From af843e2b126dbe7987f93387e3d4b09a30752bf0 Mon Sep 17 00:00:00 2001 From: Daniel Berge Sollien Date: Wed, 5 Jun 2024 09:23:27 +0200 Subject: [PATCH] Make tests for config jobs more flexible --- tests/test_hook_implementations.py | 67 ++++++++++++++---------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/tests/test_hook_implementations.py b/tests/test_hook_implementations.py index 26971bf1a..8079684b9 100644 --- a/tests/test_hook_implementations.py +++ b/tests/test_hook_implementations.py @@ -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 @@ -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 } @@ -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()) @@ -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)