Skip to content

Commit

Permalink
Make test code more robust
Browse files Browse the repository at this point in the history
If you have already run the snake-case and there
is some storage lying around, it should not trip the test.

Also make robust towards slight changes in poly.ert
  • Loading branch information
berland committed Nov 24, 2023
1 parent 2441590 commit 6aa2aaf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def fixture_copy_case(tmp_path_factory, source_root, monkeypatch):
def _copy_case(path):
tmp_path = tmp_path_factory.mktemp(path.replace("/", "-"))
shutil.copytree(
os.path.join(source_root, "test-data", path), tmp_path / "test_data"
os.path.join(source_root, "test-data", path),
tmp_path / "test_data",
ignore=shutil.ignore_patterns("storage"),
)
monkeypatch.chdir(tmp_path / "test_data")

Expand Down
11 changes: 5 additions & 6 deletions tests/unit_tests/cli/test_integration_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,14 @@ def test_cli_does_not_run_without_observations(tmpdir, source_root, mode, target
os.path.join(str(tmpdir), "poly_example"),
)

def remove_line(file_name, line_num):
with open(file_name, "r", encoding="utf-8") as f:
lines = f.readlines()
with open(file_name, "w", encoding="utf-8") as f:
f.writelines(lines[: line_num - 1] + lines[line_num:])
def remove_linestartswith(file_name: str, startswith: str):
lines = Path(file_name).read_text(encoding="utf-8").split("\n")
lines = [line for line in lines if not line.startswith(startswith)]
Path(file_name).write_text("\n".join(lines), encoding="utf-8")

with tmpdir.as_cwd():
# Remove observations from config file
remove_line("poly_example/poly.ert", 8)
remove_linestartswith("poly_example/poly.ert", "OBS_CONFIG")

parser = ArgumentParser(prog="test_main")
parsed = ert_parser(
Expand Down

0 comments on commit 6aa2aaf

Please sign in to comment.