-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate test that runs ert to own file
- Loading branch information
1 parent
8a77c97
commit f38c0bd
Showing
3 changed files
with
122 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# When ERT runs it makes changes to the files. This can cause issues for other tests if they expect certain files to exist etc. | ||
# Tests that run ERT should therefore create their own temporary file structure, completely separate from other tests. | ||
from pathlib import Path | ||
|
||
from subprocess import PIPE, Popen | ||
|
||
|
||
def write_ert_config_and_run(runpath): | ||
ert_config_path = "sim2sumo.ert" | ||
encoding = "utf-8" | ||
ert_full_config_path = runpath / ert_config_path | ||
print(f"Running with path {ert_full_config_path}") | ||
with open(ert_full_config_path, "w", encoding=encoding) as stream: | ||
|
||
stream.write( | ||
f"DEFINE <SUMO_ENV> dev\nNUM_REALIZATIONS 1\nMAX_SUBMIT 1\nRUNPATH {runpath}\nFORWARD_MODEL SIM2SUMO" | ||
) | ||
with Popen( | ||
["ert", "test_run", str(ert_full_config_path)], | ||
stdout=PIPE, | ||
stderr=PIPE, | ||
) as process: | ||
stdout, stderr = process.communicate() | ||
|
||
print( | ||
f"After ert run all these files where found at runpath {[item.name for item in list(Path(runpath).glob('*'))]}" | ||
) | ||
if stdout: | ||
print("stdout:", stdout.decode(encoding), sep="\n") | ||
if stderr: | ||
print("stderr:", stderr.decode(encoding), sep="\n") | ||
try: | ||
error_content = Path(runpath / "ERROR").read_text(encoding=encoding) | ||
except FileNotFoundError: | ||
error_content = "" | ||
assert ( | ||
not error_content | ||
), f"ERROR file found with content:\n{error_content}" | ||
assert Path( | ||
runpath / "OK" | ||
).is_file(), f"running {ert_full_config_path}, No OK file" | ||
|
||
|
||
def test_sim2sumo_with_ert( | ||
ert_run_scratch_files, ert_run_case_uuid, sumo, monkeypatch | ||
): | ||
monkeypatch.chdir(ert_run_scratch_files[0]) | ||
real0 = ert_run_scratch_files[0] | ||
# After this the files in the current directory are changed and parameters.txt no longer exists | ||
write_ert_config_and_run(real0) | ||
expected_exports = 88 | ||
path = f"/objects('{ert_run_case_uuid}')/search" | ||
results = sumo.post( | ||
path, | ||
json={ | ||
"query": { | ||
"bool": { | ||
"must_not": [ | ||
{ | ||
"terms": { | ||
"class.keyword": [ | ||
"case", | ||
"iteration", | ||
"realization", | ||
] | ||
} | ||
} | ||
], | ||
} | ||
}, | ||
"size": 0, | ||
"track_total_hits": True, | ||
}, | ||
).json() | ||
|
||
returned = results["hits"]["total"]["value"] | ||
assert ( | ||
returned == expected_exports | ||
), f"Supposed to upload {expected_exports}, but actual were {returned}" |