Skip to content

Commit

Permalink
Move to temp path in fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 25, 2024
1 parent dad824c commit c2d2caf
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions tests/forward_models/overburden_timeshift/test_ots_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@


@pytest.fixture()
def ecl_files(tmpdir):
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}", tmpdir)
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(tmpdir, velocity_model, horizon, vintages_export_file):
def test_valid_config(velocity_model, horizon, vintages_export_file):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
Expand All @@ -45,8 +46,7 @@ def test_valid_config(tmpdir, velocity_model, horizon, vintages_export_file):
conf.update({"horizon": horizon})
if vintages_export_file:
conf.update({"vintages_export_file": vintages_export_file})
with tmpdir.as_cwd():
OTSConfig(**conf)
OTSConfig(**conf)


@pytest.mark.parametrize(
Expand All @@ -58,7 +58,7 @@ def test_valid_config(tmpdir, velocity_model, horizon, vintages_export_file):
],
)
@pytest.mark.usefixtures("ecl_files")
def test_eclbase_config(tmpdir, extension, error_msg):
def test_eclbase_config(extension, error_msg):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
Expand All @@ -77,11 +77,10 @@ def test_eclbase_config(tmpdir, extension, error_msg):
"dpv": [["1997-11-06", "1997-12-17"]],
},
}
with tmpdir.as_cwd():
# 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):
OTSConfig(**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):
OTSConfig(**conf)


@pytest.mark.parametrize(
Expand All @@ -103,8 +102,7 @@ def test_eclbase_config(tmpdir, extension, error_msg):
],
)
@pytest.mark.usefixtures("ecl_files")
def test_valid_file_format(file_format, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_valid_file_format(file_format):
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
Expand All @@ -125,7 +123,7 @@ def test_valid_file_format(file_format, tmp_path, monkeypatch):


@pytest.mark.usefixtures("ecl_files")
def test_invalid_file_format(tmpdir):
def test_invalid_file_format():
conf = {
"eclbase": "NORNE_ATW2013",
"above": 100,
Expand All @@ -142,9 +140,7 @@ def test_invalid_file_format(tmpdir):
},
}
conf.update({"file_format": "not a file format"})
with tmpdir.as_cwd(), pytest.raises(
ValidationError, match="file_format\n Input should be"
):
with pytest.raises(ValidationError, match="file_format\n Input should be"):
OTSConfig(**conf)


Expand All @@ -167,9 +163,7 @@ def test_missing_date(tmpdir):
"ts_simple": [["1997-11-06", "2024-01-03"]],
},
}
with tmpdir.as_cwd(), pytest.raises(
ValidationError, match="Vintages with dates not found"
):
with pytest.raises(ValidationError, match="Vintages with dates not found"):
OTSConfig(**conf)


Expand Down

0 comments on commit c2d2caf

Please sign in to comment.