From be09a3f816c5c16fea3d50b1701891bc35646689 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Thu, 23 Nov 2023 14:44:59 +0000 Subject: [PATCH] Test explicit enrichment failure for routine not found --- loki/bulk/scheduler.py | 3 ++- tests/test_scheduler.py | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/loki/bulk/scheduler.py b/loki/bulk/scheduler.py index 33bf3a3ef..c189cd70b 100644 --- a/loki/bulk/scheduler.py +++ b/loki/bulk/scheduler.py @@ -418,7 +418,8 @@ def find_routine(self, routine): warning(f'Scheduler could not find routine {routine}') if self.config.default['strict']: raise RuntimeError(f'Scheduler could not find routine {routine}') - elif len(candidates) != 1: + return None + if len(candidates) != 1: warning(f'Scheduler found multiple candidates for routine {routine}: {candidates}') if self.config.default['strict']: raise RuntimeError(f'Scheduler found multiple candidates for routine {routine}: {candidates}') diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index f78e7391c..4c14fa7b2 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -630,6 +630,59 @@ def test_scheduler_graph_multiple_separate(here, config, frontend): cg_path.with_suffix('.pdf').unlink() +@pytest.mark.parametrize('strict', [True, False]) +def test_scheduler_graph_multiple_separate_enrich_fail(here, config, frontend, strict): + """ + Tests that explicit enrichment in "strict" mode will fail because it can't + find ext_driver + + projA: driverB -> kernelB -> compute_l1 -> compute_l2 + | + + + projB: ext_driver -> ext_kernelfail + """ + projA = here/'sources/projA' + + configA = config.copy() + configA['default']['strict'] = strict + configA['routine'] = [ + { + 'name': 'kernelB', + 'role': 'kernel', + 'ignore': ['ext_driver'], + 'enrich': ['ext_driver'], + }, + ] + + if strict: + with pytest.raises(FileNotFoundError): + Scheduler( + paths=[projA], includes=projA/'include', config=configA, + seed_routines=['driverB'], frontend=frontend + ) + else: + schedulerA = Scheduler( + paths=[projA], includes=projA/'include', config=configA, + seed_routines=['driverB'], frontend=frontend + ) + + expected_itemsA = [ + 'driverB_mod#driverB', 'kernelB_mod#kernelB', + 'compute_l1_mod#compute_l1', 'compute_l2_mod#compute_l2', + ] + expected_dependenciesA = [ + ('driverB_mod#driverB', 'kernelB_mod#kernelB'), + ('kernelB_mod#kernelB', 'compute_l1_mod#compute_l1'), + ('compute_l1_mod#compute_l1', 'compute_l2_mod#compute_l2'), + ] + + assert all(n in schedulerA.items for n in expected_itemsA) + assert all(e in schedulerA.dependencies for e in expected_dependenciesA) + assert 'ext_driver' not in schedulerA.items + assert 'ext_kernel' not in schedulerA.items + + def test_scheduler_module_dependency(here, config, frontend): """ Ensure dependency chasing is done correctly, even with surboutines