Skip to content

Commit

Permalink
Merge pull request #334 from stefoss23/p2_p3_changes
Browse files Browse the repository at this point in the history
P2 p3 changes
  • Loading branch information
joakim-hove authored Feb 22, 2018
2 parents a98730e + ee42286 commit a8f7f72
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 37 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions python/ecl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions python/ecl/ecl_lib_info_build.py.in
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions python/ecl/ecl_lib_info_install.py.in
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions python/ecl/grid/ecl_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion python/ecl/grid/ecl_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from cwrap import BaseCClass

import ecl
from ecl.util.util import monkey_the_camel
from ecl.util.util import IntVector

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions python/ecl/well/well_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions python/tests/ecl_tests/test_ecl_file_statoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion python/tests/ecl_tests/test_ecl_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion python/tests/ecl_tests/test_ecl_sum_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '
Expand Down
4 changes: 3 additions & 1 deletion python/tests/ecl_tests/test_fault_blocks_statoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )


Expand Down
22 changes: 11 additions & 11 deletions python/tests/ecl_tests/test_grdecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ecl.grid import EclGrid
from tests import EclTest, statoil_test


from cwrap import open as copen


@statoil_test()
Expand All @@ -39,42 +39,42 @@ 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()

self.assertFilesAreEqual(tmp_file1, tmp_file2)


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))
Expand All @@ -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:
Expand All @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions python/tests/ecl_tests/test_grid_statoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion python/tests/ecl_tests/test_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion python/tests/ecl_tests/test_statoil_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion python/tests/ecl_tests/test_sum_statoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a8f7f72

Please sign in to comment.