Skip to content

Commit d09e285

Browse files
committed
test: test outputs
1 parent 6e07caf commit d09e285

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

test/test_execution_hooks_core.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
DataCatalogInterface,
1616
ExecutionHooksBasePlugin,
1717
ExecutionHooksHint,
18+
OutputType,
19+
SandboxInterface,
1820
SchedulingHint,
1921
TransformationExecutionHooksHint,
2022
)
@@ -95,6 +97,15 @@ def store_output(
9597
catalog.store_output("test_output", "/tmp/test") # Should not raise an error
9698

9799

100+
class TestSandboxInterface:
101+
"""Test the SandboxInterface base class."""
102+
103+
def test_output_query(self):
104+
sandbox = SandboxInterface()
105+
output_path = sandbox.get_output_query("1337")
106+
assert output_path == Path("sandboxstore/output_sandbox_1337.tar.gz")
107+
108+
98109
class TestExecutionHookExtended:
99110
"""Test the ExecutionHooksBasePlugin foundation class methods."""
100111

@@ -138,10 +149,55 @@ class TestModel(ExecutionHooksBasePlugin):
138149
assert model.get_input_query("test") is None
139150
assert model.get_output_query("test") is None
140151

141-
# Test store_output raises RuntimeError when no output path is defined
152+
# Test datacatalog store_output raises RuntimeError when no output path is defined
142153
with pytest.raises(RuntimeError, match="No output path defined"):
143154
model.data_catalog.store_output("test", "/tmp/file.txt")
144155

156+
def test_output_interfaces_selection(self, mocker):
157+
"""Test that the Hook uses the correct interface methods."""
158+
159+
class TestCatalog(DataCatalogInterface):
160+
def get_output_query(self, output_name, **kwargs):
161+
if output_name == "test_output":
162+
return Path("filecatalog/test1/output")
163+
return super().get_output_query(output_name, **kwargs)
164+
165+
def get_input_query(self, input_name, **kwargs):
166+
return None
167+
168+
class TestModel(ExecutionHooksBasePlugin):
169+
_data_catalog = TestCatalog()
170+
_sandbox_interface = SandboxInterface()
171+
172+
model = TestModel(lfns_output_overrides={"test_lfn": "lfn:filecatalog/test"})
173+
174+
mocker.patch.object(model._data_catalog, "store_output", return_value=None)
175+
mocker.patch.object(model._sandbox_interface, "store_output", return_value=None)
176+
177+
# Test output type
178+
# DataCatalog if output in lfns_output_overrides
179+
output_type = model.get_output_type("test_lfn", "file.test")
180+
assert "test_lfn" in model.lfns_output_overrides
181+
assert output_type == OutputType.Data_Catalog
182+
183+
# DataCatalog if datacatalog output query is defined
184+
output_path = model.data_catalog.get_output_query("test_output")
185+
output_type = model.get_output_type("test_output", "file.test")
186+
assert output_path is not None
187+
assert output_type == OutputType.Data_Catalog
188+
189+
# Sandbox if not in lfns_output_overrides and datacatalog output query is None
190+
output_path = model.data_catalog.get_output_query("test")
191+
output_type = model.get_output_type("test", "file.test")
192+
assert output_path is None
193+
assert output_type == OutputType.Sandbox
194+
195+
# Test if store_output delegates to the correct interface.
196+
model.store_output("test_output", "file.test")
197+
model._data_catalog.store_output.assert_called_once()
198+
model.store_output("test", "file.test")
199+
model._sandbox_interface.store_output.assert_called_once()
200+
145201
def test_model_serialization(self):
146202
"""Test that model serialization works correctly."""
147203

test/test_workflows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _cleanup():
6767
"test/workflows/test_meta/test_meta.cwl",
6868
[
6969
"test/workflows/test_meta/override_dirac_hints.yaml",
70+
"test/workflows/test_meta/override_output_path.yaml",
7071
],
7172
),
7273
# --- Crypto example ---
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$namespaces:
2+
dirac: "./schemas/dirac-metadata.json#"
3+
cwltool:overrides:
4+
test_meta.cwl#:
5+
baseCommand: ["touch", "test_file"]
6+
outputs:
7+
test:
8+
type: File?
9+
outputBinding:
10+
glob: "test_file"
11+
hints:
12+
dirac:execution-hooks:
13+
configuration:
14+
lfns_output_overrides:
15+
test: "lfn:filecatalog/test/results"

0 commit comments

Comments
 (0)