diff --git a/.travis.yml b/.travis.yml index e4eb62513a..78fa0c189b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ dist: trusty env: global: - ERT_SHOW_BACKTRACE=1 + - LD_LIBRARY_PATH="$(pwd)/install/lib64" matrix: - PYTHON_VERSION=2.7 TEST_SUITE="-LE SLOW" # Run all tests not labeled as slow - PYTHON_VERSION=2.7 TEST_SUITE="-L SLOW_1" # Run all tests labeled as SLOW in group 1 diff --git a/python/ecl/__init__.py b/python/ecl/__init__.py index 880dde2119..9988076250 100644 --- a/python/ecl/__init__.py +++ b/python/ecl/__init__.py @@ -80,10 +80,10 @@ # module should contain the variable lib_path pointing to the # directory with shared object files. try: - import __ecl_lib_info - ecl_lib_path = __ecl_lib_info.lib_path - ert_so_version = __ecl_lib_info.so_version - __version__ = __ecl_lib_info.__version__ + from .__ecl_lib_info import EclLibInfo + ecl_lib_path = EclLibInfo.lib_path + ert_so_version = EclLibInfo.so_version + __version__ = EclLibInfo.__version__ except ImportError: pass except AttributeError: diff --git a/python/ecl/ecl_lib_info_build.py.in b/python/ecl/ecl_lib_info_build.py.in index eaf570f7ca..7f80c68807 100644 --- a/python/ecl/ecl_lib_info_build.py.in +++ b/python/ecl/ecl_lib_info_build.py.in @@ -1,3 +1,9 @@ -lib_path = "${LIBRARY_OUTPUT_PATH}" -so_version = "${ECL_BINARY_POSTFIX}" -__version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" + + +class EclLibInfo(object): + lib_path = "${LIBRARY_OUTPUT_PATH}" + so_version = "${ECL_BINARY_POSTFIX}" + __version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" + + def __init__(self): + pass diff --git a/python/ecl/ecl_lib_info_install.py.in b/python/ecl/ecl_lib_info_install.py.in index 85643091ec..12c6c69375 100644 --- a/python/ecl/ecl_lib_info_install.py.in +++ b/python/ecl/ecl_lib_info_install.py.in @@ -1,3 +1,9 @@ -lib_path = "../../../../${CMAKE_INSTALL_LIBDIR}" -so_version = "${ECL_BINARY_POSTFIX}" -__version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" + + +class EclLibInfo(object): + lib_path = "../../../../${CMAKE_INSTALL_LIBDIR}" + so_version = "${ECL_BINARY_POSTFIX}" + __version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" + + def __init__(self): + pass diff --git a/python/ecl/grid/ecl_grid.py b/python/ecl/grid/ecl_grid.py index 358b60dd2e..1a923140ac 100644 --- a/python/ecl/grid/ecl_grid.py +++ b/python/ecl/grid/ecl_grid.py @@ -31,7 +31,7 @@ import os.path import math import itertools -from cwrap import CFILE, BaseCClass +from cwrap import CFILE, BaseCClass, load, open as copen from ecl import EclPrototype from ecl.util.util import monkey_the_camel @@ -140,7 +140,7 @@ def load_from_grdecl(cls, filename): """ if os.path.isfile(filename): - with open(filename) as f: + with copen(filename) as f: specgrid = EclKW.read_grdecl(f, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False) zcorn = EclKW.read_grdecl(f, "ZCORN") coord = EclKW.read_grdecl(f, "COORD") diff --git a/python/ecl/grid/ecl_region.py b/python/ecl/grid/ecl_region.py index e7e2631eaf..295f0e59f9 100644 --- a/python/ecl/grid/ecl_region.py +++ b/python/ecl/grid/ecl_region.py @@ -29,6 +29,7 @@ from cwrap import BaseCClass +import ecl from ecl.util.util import monkey_the_camel from ecl.util.util import IntVector @@ -927,7 +928,11 @@ def idiv_kw( self , target_kw , other , force_active = False): else: raise TypeError("Type mismatch") else: - self.scale_kw( target_kw , 1/other , force_active ) + if target_kw.data_type.is_int(): + scale = 1 // other + else: + scale = 1.0 / other + self.scale_kw( target_kw , scale , force_active ) def copy_kw( self , target_kw , src_kw , force_active = False): diff --git a/python/ecl/well/well_connection.py b/python/ecl/well/well_connection.py index f9fe3ae5e2..522d19ee0c 100644 --- a/python/ecl/well/well_connection.py +++ b/python/ecl/well/well_connection.py @@ -65,6 +65,9 @@ def connectionFactor(self): def __eq__(self, other): return self._equal(other) + def __hash__(self): + return id(self) + def __ne__(self, other): return not self == other diff --git a/python/tests/ecl_tests/test_ecl_file_statoil.py b/python/tests/ecl_tests/test_ecl_file_statoil.py index 0a51ac4327..8377b639f0 100755 --- a/python/tests/ecl_tests/test_ecl_file_statoil.py +++ b/python/tests/ecl_tests/test_ecl_file_statoil.py @@ -222,7 +222,7 @@ def test_ix_case(self): ] padd = lambda str_len : (lambda s : s + (" " * (max(0, str_len-len(s))))) - self.assertEqual(map(padd(8), keywords_from_file), keywords_loaded) + self.assertEqual( list(map(padd(8), keywords_from_file)), keywords_loaded) # Names self.assertTrue( "NAMES" in f ) @@ -272,4 +272,4 @@ def test_ix_case(self): ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+' ] - self.assertEqual(map(padd(10), names_from_file), names_loaded) + self.assertEqual( list(map(padd(10), names_from_file)), names_loaded) diff --git a/python/tests/ecl_tests/test_ecl_sum.py b/python/tests/ecl_tests/test_ecl_sum.py index a8e6bd50b7..2177dbce95 100644 --- a/python/tests/ecl_tests/test_ecl_sum.py +++ b/python/tests/ecl_tests/test_ecl_sum.py @@ -19,6 +19,8 @@ import os.path from cwrap import CFILE +from cwrap import Prototype, load, open as copen + from ecl.eclfile import EclFile, FortIO, openFortIO, openEclFile, EclKW from ecl.summary import EclSum, EclSumKeyWordVector from ecl.util.test import TestAreaContext @@ -61,7 +63,7 @@ def test_dump_csv_line(self): dtime = datetime.datetime(2002, 1, 1, 0, 0, 0) with TestAreaContext("EclSum/csv_dump"): test_file_name = self.createTestPath("dump.csv") - outputH = open(test_file_name, "w") + outputH = copen(test_file_name, "w") self.ecl_sum.dumpCSVLine(dtime, ecl_sum_vector, outputH) assert os.path.isfile(test_file_name) diff --git a/python/tests/ecl_tests/test_ecl_sum_vector.py b/python/tests/ecl_tests/test_ecl_sum_vector.py index d44ea5dab4..454fa9143a 100644 --- a/python/tests/ecl_tests/test_ecl_sum_vector.py +++ b/python/tests/ecl_tests/test_ecl_sum_vector.py @@ -47,7 +47,8 @@ def test_basic(self): pfx = 'EclSum(name' self.assertEqual(pfx, repr(self.ecl_sum)[:len(pfx)]) it = iter(self.ecl_sum) - t = self.ecl_sum[it.next()] # EclSumVector + #t = self.ecl_sum[it.next()] # EclSumVector + t = self.ecl_sum[next(it)] # EclSumVector self.assertEqual(63, len(t)) self.assertEqual('BARSA', t.unit) pfx = 'EclSumVector(key = ' diff --git a/python/tests/ecl_tests/test_fault_blocks_statoil.py b/python/tests/ecl_tests/test_fault_blocks_statoil.py index 46ebde00de..4b72f27be6 100644 --- a/python/tests/ecl_tests/test_fault_blocks_statoil.py +++ b/python/tests/ecl_tests/test_fault_blocks_statoil.py @@ -25,12 +25,14 @@ from tests import EclTest, statoil_test from ecl.grid.faults import FaultBlock, FaultBlockLayer +from cwrap import open as copen + @statoil_test() class FaultBlockTest(EclTest): def setUp(self): self.grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Mariner/MARINER.EGRID")) - fileH = open( self.createTestPath("Statoil/ECLIPSE/Mariner/faultblock.grdecl") ) + fileH = copen( self.createTestPath("Statoil/ECLIPSE/Mariner/faultblock.grdecl") ) self.kw = EclKW.read_grdecl( fileH , "FAULTBLK" , ecl_type = EclDataType.ECL_INT ) diff --git a/python/tests/ecl_tests/test_grdecl.py b/python/tests/ecl_tests/test_grdecl.py index 6ae0e77f3b..6063c109e0 100755 --- a/python/tests/ecl_tests/test_grdecl.py +++ b/python/tests/ecl_tests/test_grdecl.py @@ -20,7 +20,7 @@ from ecl.grid import EclGrid from tests import EclTest, statoil_test - +from cwrap import open as copen @statoil_test() @@ -39,29 +39,29 @@ def tearDown(self): def test_Load( self ): - kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") + kw = EclKW.read_grdecl(copen(self.src_file, "r"), "PERMX") self.assertTrue(kw) grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE" )) - kw = Ecl3DKW.read_grdecl(grid , open(self.src_file, "r"), "PERMX") + kw = Ecl3DKW.read_grdecl(grid , copen(self.src_file, "r"), "PERMX") self.assertTrue( isinstance( kw , Ecl3DKW )) def test_reload( self ): - kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") + kw = EclKW.read_grdecl(copen(self.src_file, "r"), "PERMX") tmp_file1 = "/tmp/permx1.grdecl" tmp_file2 = "/tmp/permx2.grdecl" self.addFile(tmp_file1) self.addFile(tmp_file2) - fileH = open(tmp_file1, "w") + fileH = copen(tmp_file1, "w") kw.write_grdecl(fileH) fileH.close() - kw1 = EclKW.read_grdecl(open(tmp_file1, "r"), "PERMX") + kw1 = EclKW.read_grdecl(copen(tmp_file1, "r"), "PERMX") - fileH = open(tmp_file2, "w") + fileH = copen(tmp_file2, "w") kw1.write_grdecl(fileH) fileH.close() @@ -69,12 +69,12 @@ def test_reload( self ): def test_fseek( self ): - file = open(self.src_file, "r") + file = copen(self.src_file, "r") self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) file.close() - file = open(self.src_file, "r") + file = copen(self.src_file, "r") kw1 = EclKW.read_grdecl(file, "PERMX") self.assertFalse(EclKW.fseek_grdecl(file, "PERMX")) self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) @@ -84,7 +84,7 @@ def test_fseek( self ): def test_fseek2(self): test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl") # Test kw at the the very start - file = open(test_src, "r") + file = copen(test_src, "r") self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) # Test commented out kw: @@ -106,7 +106,7 @@ def test_fseek2(self): def test_fseek_dos(self): test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl_dos") # File formatted with \r\n line endings. # Test kw at the the very start - file = open(test_src, "r") + file = copen(test_src, "r") self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) # Test commented out kw: diff --git a/python/tests/ecl_tests/test_grid_statoil.py b/python/tests/ecl_tests/test_grid_statoil.py index 029b128937..19f6be7295 100755 --- a/python/tests/ecl_tests/test_grid_statoil.py +++ b/python/tests/ecl_tests/test_grid_statoil.py @@ -21,6 +21,9 @@ except ImportError: from unittest import skipIf +from cwrap import Prototype +from cwrap import open as copen + import time from ecl import EclDataType from ecl.eclfile import EclKW, EclFile, openEclFile @@ -119,7 +122,7 @@ def test_EGRID( self ): def create(self, filename, load_actnum=True): - fileH = open(filename, "r") + fileH = copen(filename, "r") specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False) zcorn = EclKW.read_grdecl(fileH, "ZCORN") coord = EclKW.read_grdecl(fileH, "COORD") @@ -186,10 +189,12 @@ def test_grdecl_load(self): self.assertEqual( g1.getNumActive() , actnum.elementSum() ) g1.save_EGRID("G.EGRID") + with open("grid.grdecl" , "w") as f2: + f2.write("SPECGRID\n") + f2.write(" 10 10 10 \'F\' /\n") + with openEclFile("G.EGRID") as f: - with open("grid.grdecl" , "w") as f2: - f2.write("SPECGRID\n") - f2.write(" 10 10 10 \'F\' /\n") + with copen("grid.grdecl" , "a") as f2: coord_kw = f["COORD"][0] coord_kw.write_grdecl( f2 ) @@ -231,7 +236,7 @@ def test_save(self): g2 = EclGrid("test.GRID") self.assertTrue(g1.equal(g2)) - fileH = open("test.grdecl", "w") + fileH = copen("test.grdecl", "w") g1.save_grdecl(fileH) fileH.close() g2 = self.create("test.grdecl") diff --git a/python/tests/ecl_tests/test_restart.py b/python/tests/ecl_tests/test_restart.py index c72fac714b..32fa276aec 100755 --- a/python/tests/ecl_tests/test_restart.py +++ b/python/tests/ecl_tests/test_restart.py @@ -85,7 +85,7 @@ def report_list_file_test(self, fname, rlist0): def test_report_list(self): - rlist0 = range(63) + rlist0 = list(range(63)) self.report_list_file_test(self.u_file, rlist0) rlist0 = [0] diff --git a/python/tests/ecl_tests/test_statoil_faults.py b/python/tests/ecl_tests/test_statoil_faults.py index b8da9d6408..03c5b3210a 100644 --- a/python/tests/ecl_tests/test_statoil_faults.py +++ b/python/tests/ecl_tests/test_statoil_faults.py @@ -19,6 +19,8 @@ except ImportError: from unittest import skipIf +from cwrap import open as copen + import time from ecl import EclDataType from ecl.eclfile import EclKW @@ -31,7 +33,7 @@ class StatoilFaultTest(EclTest): def loadGrid(self): grid_file = self.createTestPath("Statoil/ECLIPSE/Faults/grid.grdecl") - fileH = open(grid_file, "r") + fileH = copen(grid_file, "r") specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False) zcorn = EclKW.read_grdecl(fileH, "ZCORN") coord = EclKW.read_grdecl(fileH, "COORD") diff --git a/python/tests/ecl_tests/test_sum_statoil.py b/python/tests/ecl_tests/test_sum_statoil.py index 4ee830ee6e..beab1012fe 100755 --- a/python/tests/ecl_tests/test_sum_statoil.py +++ b/python/tests/ecl_tests/test_sum_statoil.py @@ -474,7 +474,7 @@ def test_ix_case(self): hwell_padder = lambda key : key if key.split(":")[-1] != "HWELL_PR" else key + "OD" self.assertEqual( intersect_summary.keys("WWCT*"), - map(hwell_padder, eclipse_summary.keys("WWCT*")) + list(map(hwell_padder, eclipse_summary.keys("WWCT*"))) ) def test_ix_write(self):