Use utility function for path to testdata
This commit is contained in:
@@ -3,7 +3,7 @@ import unittest
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from opm.io.schedule import Schedule
|
||||
|
||||
from utils import test_path
|
||||
|
||||
def flowing(connection):
|
||||
return connection.state == 'OPEN'
|
||||
@@ -16,8 +16,10 @@ class TestWells(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
deck = Parser().parse('tests/spe3/SPE3CASE1.DATA')
|
||||
deck = Parser().parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
print("Creating state")
|
||||
cls.state = EclipseState(deck)
|
||||
print("State OK")
|
||||
cls.sch = Schedule(deck, cls.state)
|
||||
cls.timesteps = cls.sch.timesteps
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import opm.io
|
||||
|
||||
class TestGrupnet(unittest.TestCase):
|
||||
|
||||
"""
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
norne = 'examples/data/norne/NORNE_ATW2013.DATA'
|
||||
cls.sch = opm.io.parse(norne, [('PARSE_RANDOM_SLASH', opm.io.action.ignore)]).schedule
|
||||
|
||||
def test_vfp_table(self):
|
||||
self.assertEqual(0, self.sch.group(timestep=0)['PROD'].vfp_table_nr)
|
||||
self.assertEqual(9, self.sch.group(timestep=0)['MANI-E2'].vfp_table_nr)
|
||||
self.assertEqual(9, self.sch.group(timestep=247)['MANI-E2'].vfp_table_nr)
|
||||
self.assertEqual(9999, self.sch.group(timestep=0)['MANI-K1'].vfp_table_nr)
|
||||
self.assertEqual(0, self.sch.group(timestep=0)['INJE'].vfp_table_nr)
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
|
||||
from opm.io.parser import Parser, ParseContext
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from utils import test_path
|
||||
|
||||
class TestParse(unittest.TestCase):
|
||||
|
||||
@@ -32,8 +33,8 @@ FIPNUM
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.spe3fn = 'tests/spe3/SPE3CASE1.DATA'
|
||||
self.norne_fname = os.path.abspath('examples/data/norne/NORNE_ATW2013.DATA')
|
||||
self.spe3fn = test_path('spe3/SPE3CASE1.DATA')
|
||||
self.norne_fname = test_path('../examples/data/norne/NORNE_ATW2013.DATA')
|
||||
|
||||
def test_parse(self):
|
||||
deck = Parser().parse(self.spe3fn)
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.parser import ParseContext
|
||||
from opm.io.deck import DeckKeyword
|
||||
from utils import test_path
|
||||
|
||||
unit_foot = 0.3048 #meters
|
||||
|
||||
@@ -34,8 +35,8 @@ FIPNUM
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.spe3fn = 'tests/spe3/SPE3CASE1.DATA'
|
||||
self.norne_fname = os.path.abspath('examples/data/norne/NORNE_ATW2013.DATA')
|
||||
self.spe3fn = test_path('spe3/SPE3CASE1.DATA')
|
||||
self.norne_fname = test_path('../examples/data/norne/NORNE_ATW2013.DATA')
|
||||
|
||||
def test_create(self):
|
||||
parser = Parser()
|
||||
|
||||
@@ -3,6 +3,7 @@ import opm.io
|
||||
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from utils import test_path
|
||||
|
||||
|
||||
class TestProps(unittest.TestCase):
|
||||
@@ -14,7 +15,7 @@ class TestProps(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
parser = Parser()
|
||||
deck = parser.parse('tests/spe3/SPE3CASE1.DATA')
|
||||
deck = parser.parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
self.spe3 = EclipseState(deck)
|
||||
self.props = self.spe3.props()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime as dt
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from opm.io.schedule import Schedule
|
||||
from utils import test_path
|
||||
|
||||
|
||||
class TestSchedule(unittest.TestCase):
|
||||
@@ -11,7 +12,7 @@ class TestSchedule(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
deck = Parser().parse('tests/spe3/SPE3CASE1.DATA')
|
||||
deck = Parser().parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
state = EclipseState(deck)
|
||||
cls.sch = Schedule( deck, state )
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from opm.io.parser import Parser
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from opm.io.schedule import Schedule
|
||||
from opm.io.summary import SummaryConfig
|
||||
from utils import test_path
|
||||
|
||||
|
||||
class TestState2(unittest.TestCase):
|
||||
@@ -57,10 +58,10 @@ SATNUM
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
parser = Parser()
|
||||
cls.deck_cpa = parser.parse('tests/data/CORNERPOINT_ACTNUM.DATA')
|
||||
cls.deck_cpa = parser.parse(test_path('data/CORNERPOINT_ACTNUM.DATA'))
|
||||
cls.cp_state = EclipseState(cls.deck_cpa)
|
||||
|
||||
cls.deck_spe3 = parser.parse('tests/spe3/SPE3CASE1.DATA')
|
||||
cls.deck_spe3 = parser.parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
cls.state = EclipseState(cls.deck_spe3)
|
||||
cls.schedule = Schedule(cls.deck_spe3, cls.state)
|
||||
cls.summary_config = SummaryConfig(cls.deck_spe3, cls.state, cls.schedule)
|
||||
|
||||
@@ -3,7 +3,7 @@ import datetime
|
||||
from opm.tools import *
|
||||
|
||||
from opm.io.parser import Parser
|
||||
from .utils import tmp
|
||||
from utils import test_path, tmp
|
||||
|
||||
class TestTimeVector(unittest.TestCase):
|
||||
|
||||
@@ -57,10 +57,10 @@ class TestTimeVector(unittest.TestCase):
|
||||
|
||||
|
||||
def test_load(self):
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file = "tests/data/schedule/part1.sch")
|
||||
tv.load("tests/data/schedule/part3.sch")
|
||||
tv.load("tests/data/schedule/fragment_dates.sch")
|
||||
tv.load("tests/data/schedule/part2.sch")
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file = test_path("data/schedule/part1.sch"))
|
||||
tv.load(test_path("data/schedule/part3.sch"))
|
||||
tv.load(test_path("data/schedule/fragment_dates.sch"))
|
||||
tv.load(test_path("data/schedule/part2.sch"))
|
||||
|
||||
self.assertEqual(tv.dates, [datetime.datetime(1997, 11, 6),
|
||||
datetime.datetime(1997, 11, 14),
|
||||
@@ -80,9 +80,9 @@ class TestTimeVector(unittest.TestCase):
|
||||
datetime.datetime(1998, 8, 1)])
|
||||
|
||||
def test_str(self):
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_string = open("tests/data/schedule/part1.sch").read())
|
||||
tv.load("tests/data/schedule/part3.sch")
|
||||
tv.load("tests/data/schedule/part2.sch")
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_string = open(test_path("data/schedule/part1.sch")).read())
|
||||
tv.load(test_path("data/schedule/part3.sch"))
|
||||
tv.load(test_path("data/schedule/part2.sch"))
|
||||
|
||||
s = str(tv)
|
||||
tv2 = TimeVector(datetime.date(1997, 11, 6))
|
||||
@@ -93,17 +93,17 @@ class TestTimeVector(unittest.TestCase):
|
||||
|
||||
|
||||
def test_optional(self):
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file = "tests/data/schedule/part1.sch")
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file = test_path("data/schedule/part1.sch"))
|
||||
|
||||
# Must have a starting date, either as first keyword in loaded file,
|
||||
# or alternatively as the optional date argument.
|
||||
with self.assertRaises(ValueError):
|
||||
tv.load("tests/data/schedule/fragment.sch")
|
||||
tv.load(test_path("data/schedule/fragment.sch"))
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
tv.load("tests/data/schedule/fragment_dates.sch", date = datetime.datetime(1998, 1,1))
|
||||
tv.load(test_path("data/schedule/fragment_dates.sch"), date = datetime.datetime(1998, 1,1))
|
||||
|
||||
tv.load("tests/data/schedule/fragment.sch", date = datetime.datetime(1998, 1, 10))
|
||||
tv.load(test_path("data/schedule/fragment.sch"), date = datetime.datetime(1998, 1, 10))
|
||||
ts = tv[-1]
|
||||
self.assertEqual(ts.dt, datetime.datetime(1998, 1 , 10))
|
||||
self.assertEqual(ts.keywords[0].name, "WCONINJE")
|
||||
@@ -112,14 +112,14 @@ class TestTimeVector(unittest.TestCase):
|
||||
|
||||
def test_user_test(self):
|
||||
tv=TimeVector(datetime.date(1999,12,31))
|
||||
tv.load('tests/data/schedule/TEMPLATE.SCH', date=datetime.datetime(1999,12,31))
|
||||
tv.load(test_path('data/schedule/TEMPLATE.SCH'), date=datetime.datetime(1999,12,31))
|
||||
self.assertListEqual(tv.dates, [datetime.datetime(1999,12,31),
|
||||
datetime.datetime(2000,1,1),
|
||||
datetime.datetime(2000,2,1),
|
||||
datetime.datetime(2000,3,1)])
|
||||
|
||||
def test_no_leading_DATES(self):
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file="tests/data/schedule/part1.sch")
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file=test_path("data/schedule/part1.sch"))
|
||||
s = str(tv)
|
||||
d = Parser().parse_string(s)
|
||||
kw0 = d[0]
|
||||
@@ -129,7 +129,7 @@ class TestTimeVector(unittest.TestCase):
|
||||
self.assertEqual("", str(tv2))
|
||||
|
||||
def test_drop_dates(self):
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file="tests/data/schedule/part1.sch")
|
||||
tv = TimeVector(datetime.date(1997, 11, 6), base_file=test_path("data/schedule/part1.sch"))
|
||||
with self.assertRaises(KeyError):
|
||||
tv.delete(datetime.datetime(2019,1,1))
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import opm
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.ecl_state import EclipseState
|
||||
from opm.io.schedule import Schedule
|
||||
from utils import test_path
|
||||
|
||||
def injector(well):
|
||||
return well.isinjector()
|
||||
@@ -26,7 +27,7 @@ class TestWells(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
deck = Parser().parse('tests/spe3/SPE3CASE1.DATA')
|
||||
deck = Parser().parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
state = EclipseState(deck)
|
||||
cls.sch = Schedule( deck, state )
|
||||
cls.timesteps = cls.sch.timesteps
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import contextlib
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -20,6 +21,11 @@ def tmpdir(path, teardown=True):
|
||||
return real_decorator
|
||||
|
||||
|
||||
|
||||
def test_path(path):
|
||||
return os.path.join(os.path.dirname(__file__), path)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tmp(path=None, teardown=True):
|
||||
"""Create and go into tmp directory, returns the path.
|
||||
|
||||
Reference in New Issue
Block a user