diff --git a/libecl/src/ecl_region.c b/libecl/src/ecl_region.c index 2c3b06edc0..ca1a2faeb7 100644 --- a/libecl/src/ecl_region.c +++ b/libecl/src/ecl_region.c @@ -306,7 +306,7 @@ void ecl_region_deselect_cell( ecl_region_type * region , int i , int j , int k) static void ecl_region_select_equal__( ecl_region_type * region , const ecl_kw_type * ecl_kw, int value , bool select) { bool global_kw; ecl_region_assert_kw( region , ecl_kw , &global_kw); - if (ecl_type_is_int(ecl_kw_get_data_type( ecl_kw ))) + if (!ecl_type_is_int(ecl_kw_get_data_type( ecl_kw ))) util_abort("%s: sorry - select by equality is only supported for integer keywords \n",__func__); { const int * kw_data = ecl_kw_get_int_ptr( ecl_kw ); diff --git a/python/python/ert/ecl/ecl_region.py b/python/python/ert/ecl/ecl_region.py index d340172a7f..c329f3bcff 100644 --- a/python/python/ert/ecl/ecl_region.py +++ b/python/python/ert/ecl/ecl_region.py @@ -417,6 +417,8 @@ def select_equal( self , ecl_kw , value , intersect = False): region.select_equal( pvtnum_kw , 4 ) """ + if not ecl_kw.data_type.is_int(): + raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( )) self._select_equal( ecl_kw , value ) @@ -426,6 +428,8 @@ def deselect_equal( self , ecl_kw , value ): See select_equal() for further documentation. """ + if not ecl_kw.data_type.is_int(): + raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( )) self._deselect_equal( ecl_kw , value ) @select_method diff --git a/python/tests/core/ecl/CMakeLists.txt b/python/tests/core/ecl/CMakeLists.txt index 2747cc0a96..e2cdb6551d 100644 --- a/python/tests/core/ecl/CMakeLists.txt +++ b/python/tests/core/ecl/CMakeLists.txt @@ -25,6 +25,7 @@ set(TEST_SOURCES test_kw_function.py test_layer.py test_npv.py + test_region.py test_region_statoil.py test_restart.py test_rft.py @@ -62,6 +63,7 @@ addPythonTest(ecl.ecl_file ecl.test_ecl_file.EclFileTest) addPythonTest(ecl.ecl_grav ecl.test_grav.EclGravTest) addPythonTest(ecl.ecl_geertsma ecl.test_geertsma.GeertsmaTest) addPythonTest(ecl.ecl_type ecl.test_ecl_type.EclDataTypeTest) +addPythonTest(ecl.ecl_region ecl.test_region.RegionTest) if (STATOIL_TESTDATA_ROOT) diff --git a/python/tests/core/ecl/test_region.py b/python/tests/core/ecl/test_region.py new file mode 100644 index 0000000000..921ef1457a --- /dev/null +++ b/python/tests/core/ecl/test_region.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# Copyright (C) 2017 Statoil ASA, Norway. +# +# The file 'test_region.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ERT is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. +# +# See the GNU General Public License at +# for more details. +from ert.ecl import EclGrid, EclKW, EclRegion, EclDataType +from ert.ecl.faults import Layer +from ert.test import ExtendedTestCase + + +class RegionTest(ExtendedTestCase): + + def test_equal(self): + grid = EclGrid.createRectangular( (10,10,1) , (1,1,1)) + kw_int = EclKW( "INT" , grid.getGlobalSize( ) , EclDataType.ECL_INT ) + kw_float = EclKW( "FLOAT" , grid.getGlobalSize( ) , EclDataType.ECL_FLOAT ) + + kw_int[0:49] = 1 + region = EclRegion(grid, False) + region.select_equal( kw_int , 1 ) + glist = region.getGlobalList() + for g in glist: + self.assertEqual( kw_int[g] , 1 ) + + with self.assertRaises(ValueError): + region.select_equal( kw_float , 1 )