Skip to content

Commit

Permalink
Create base configuration fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 25, 2024
1 parent c2d2caf commit 2b79ae3
Showing 1 changed file with 24 additions and 102 deletions.
126 changes: 24 additions & 102 deletions tests/forward_models/overburden_timeshift/test_ots_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,10 @@

TEST_NORNE_DIR = Path(__file__).parent / ".." / ".." / "test_data" / "norne"

# pylint: disable=duplicate-code


@pytest.fixture()
def ecl_files(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
for extension in ["INIT", "EGRID", "UNRST"]:
shutil.copy(TEST_NORNE_DIR / f"NORNE_ATW2013.{extension}", tmp_path)


@pytest.mark.parametrize("vintages_export_file", ["ts.txt", None])
@pytest.mark.parametrize("horizon", ["horizon.irap", None])
@pytest.mark.parametrize("velocity_model", ["norne_vol.segy", None])
@pytest.mark.usefixtures("ecl_files")
def test_valid_config(velocity_model, horizon, vintages_export_file):
conf = {
@pytest.fixture(name="conf")
def conf_fixture():
yield {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
Expand All @@ -40,6 +28,20 @@ def test_valid_config(velocity_model, horizon, vintages_export_file):
"dpv": [["1997-11-06", "1997-12-17"]],
},
}


@pytest.fixture()
def ecl_files(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
for extension in ["INIT", "EGRID", "UNRST"]:
shutil.copy(TEST_NORNE_DIR / f"NORNE_ATW2013.{extension}", tmp_path)


@pytest.mark.parametrize("vintages_export_file", ["ts.txt", None])
@pytest.mark.parametrize("horizon", ["horizon.irap", None])
@pytest.mark.parametrize("velocity_model", ["norne_vol.segy", None])
@pytest.mark.usefixtures("ecl_files")
def test_valid_config(conf, velocity_model, horizon, vintages_export_file):
if velocity_model:
conf.update({"velocity_model": velocity_model})
if horizon:
Expand All @@ -58,25 +60,7 @@ def test_valid_config(velocity_model, horizon, vintages_export_file):
],
)
@pytest.mark.usefixtures("ecl_files")
def test_eclbase_config(extension, error_msg):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
"youngs": 0.5,
"poisson": 0.3,
"rfactor": 20,
"mapaxes": False,
"convention": 1,
"output_dir": "ts",
"horizon": "horizon.irap",
"vintages_export_file": "ts.txt",
"velocity_model": "norne_vol.segy",
"vintages": {
"ts_simple": [["1997-11-06", "1998-02-01"], ["1997-12-17", "1998-02-01"]],
"dpv": [["1997-11-06", "1997-12-17"]],
},
}
def test_eclbase_config(extension, error_msg, conf):
# Renaming a needed ecl file to simulate it not existing
Path(f"NORNE_ATW2013.{extension}").rename("NOT_ECLBASE")
with pytest.raises(ValidationError, match=error_msg):
Expand All @@ -102,90 +86,28 @@ def test_eclbase_config(extension, error_msg):
],
)
@pytest.mark.usefixtures("ecl_files")
def test_valid_file_format(file_format):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
"youngs": 0.5,
"poisson": 0.3,
"rfactor": 20,
"mapaxes": False,
"convention": 1,
"output_dir": "ts",
"vintages": {
"ts_simple": [["1997-11-06", "1998-02-01"], ["1997-12-17", "1998-02-01"]],
"dpv": [["1997-11-06", "1997-12-17"]],
},
}
def test_valid_file_format(file_format, conf):
conf.update({"file_format": file_format})
OTSConfig(**conf)


@pytest.mark.usefixtures("ecl_files")
def test_invalid_file_format():
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
"youngs": 0.5,
"poisson": 0.3,
"rfactor": 20,
"mapaxes": False,
"convention": 1,
"output_dir": "ts",
"vintages": {
"ts_simple": [["1997-11-06", "1998-02-01"], ["1997-12-17", "1998-02-01"]],
"dpv": [["1997-11-06", "1997-12-17"]],
},
}
def test_invalid_file_format(conf):
conf.update({"file_format": "not a file format"})
with pytest.raises(ValidationError, match="file_format\n Input should be"):
OTSConfig(**conf)


@pytest.mark.usefixtures("ecl_files")
def test_missing_date(tmpdir):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
"youngs": 0.5,
"poisson": 0.3,
"rfactor": 20,
"mapaxes": False,
"convention": 1,
"output_dir": "ts",
"horizon": "horizon.irap",
"vintages_export_file": "ts.txt",
"velocity_model": "norne_vol.segy",
"vintages": {
"ts_simple": [["1997-11-06", "2024-01-03"]],
},
}
def test_missing_date(conf):
conf["vintages"]["ts_simple"] = [["1997-11-06", "2024-01-03"]]
with pytest.raises(ValidationError, match="Vintages with dates not found"):
OTSConfig(**conf)


@pytest.mark.usefixtures("ecl_files")
def test_extra_date():
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
"seabed": 300,
"youngs": 0.5,
"poisson": 0.3,
"rfactor": 20,
"mapaxes": False,
"convention": 1,
"output_dir": "ts",
"horizon": "horizon.irap",
"vintages_export_file": "ts.txt",
"velocity_model": "norne_vol.segy",
"vintages": {
"ts_simple": [["1997-11-06", "1998-02-01", "1997-12-17"]],
},
}
def test_extra_date(conf):
conf["vintages"]["ts_simple"] = [["1997-11-06", "1998-02-01", "1997-12-17"]]
with pytest.raises(ValidationError, match="List should have at most 2 items"):
OTSConfig(**conf)

Expand Down

0 comments on commit 2b79ae3

Please sign in to comment.