Skip to content

Commit

Permalink
Make tests for config jobs more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sol committed Jun 5, 2024
1 parent e407eae commit af843e2
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions tests/test_hook_implementations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
import shutil
from os import path
from pathlib import Path

import pytest
import rstcheck_core.checker
import subscript.hook_implementations.jobs
import subscript
from subscript.hook_implementations import jobs
from ert.shared.plugins.plugin_manager import ErtPluginManager

# pylint: disable=redefined-outer-name
Expand All @@ -13,28 +15,11 @@
@pytest.fixture
def expected_jobs(path_to_subscript):
"""dictionary of installed jobs with location to config"""
expected_job_names = [
"CHECK_SWATINIT",
"CASEGEN_UPCARS",
"CSV2OFMVOL",
"CSV_STACK",
"ECLCOMPRESS",
"ECLDIFF2ROFF",
"ECLGRID2ROFF",
"ECLINIT2ROFF",
"ECLRST2ROFF",
"INTERP_RELPERM",
"MERGE_RFT_ERTOBS",
"MERGE_UNRST_FILES",
"OFMVOL2CSV",
"PARAMS2CSV",
"RI_WELLMOD",
"PRTVOL2CSV",
"SUNSCH",
"WELLTEST_DPDS",
]
config_jobs_folder = Path(path_to_subscript) / "config_jobs"
expected_job_names = list(config_jobs_folder.glob("*"))

return {
name: path.join(path_to_subscript, "config_jobs", name)
str(name.name): path.join(path_to_subscript, "config_jobs", name)
for name in expected_job_names
}

Expand All @@ -46,21 +31,30 @@ def expected_jobs(path_to_subscript):
def test_hook_implementations(expected_jobs):
"""Test that we have the correct set of jobs installed,
nothing more, nothing less"""
plugin_m = ErtPluginManager(plugins=[subscript.hook_implementations.jobs])
print(expected_jobs)
plugin_m = ErtPluginManager(plugins=[jobs])

installable_jobs = plugin_m.get_installable_jobs()
for wf_name, wf_location in expected_jobs.items():
assert wf_name in installable_jobs
assert installable_jobs[wf_name].endswith(wf_location)
assert path.isfile(installable_jobs[wf_name])

assert set(installable_jobs.keys()) == set(expected_jobs.keys())
expected_forward_jobs = {
key: value for key, value in expected_jobs.items() if jobs.is_forward_model(key)
}
for job_name, job_location in expected_forward_jobs.items():
assert job_name in installable_jobs
assert installable_jobs[job_name].endswith(job_location)
assert path.isfile(installable_jobs[job_name])

assert set(installable_jobs.keys()) == set(expected_forward_jobs.keys())

expected_workflow_jobs = {}
expected_workflow_jobs = {
key: value
for key, value in expected_jobs.items()
if not jobs.is_forward_model(key)
}
installable_workflow_jobs = plugin_m.get_installable_workflow_jobs()
for wf_name, wf_location in expected_workflow_jobs.items():
assert wf_name in installable_workflow_jobs
assert installable_workflow_jobs[wf_name].endswith(wf_location)
for job_name, job_location in expected_workflow_jobs.items():
assert job_name in installable_workflow_jobs
assert installable_workflow_jobs[job_name].endswith(job_location)

assert set(installable_workflow_jobs.keys()) == set(expected_workflow_jobs.keys())

Expand All @@ -78,9 +72,12 @@ def test_job_config_syntax(expected_jobs):
def test_executables(expected_jobs):
"""Test executables listed in job configurations exist in $PATH"""
for _, job_config in expected_jobs.items():
executable = (
Path(job_config).read_text(encoding="utf8").splitlines()[0].split()[1]
)

executable_line = re.compile(r"^EXECUTABLE\s+([a-zA-Z_]+)")
executable = executable_line.search(
Path(job_config).read_text(encoding="utf8")
).group(1)
print(job_config, ":", executable)
assert shutil.which(executable)


Expand Down

0 comments on commit af843e2

Please sign in to comment.