|
15 | 15 | DataCatalogInterface, |
16 | 16 | ExecutionHooksBasePlugin, |
17 | 17 | ExecutionHooksHint, |
| 18 | + OutputType, |
| 19 | + SandboxInterface, |
18 | 20 | SchedulingHint, |
19 | 21 | TransformationExecutionHooksHint, |
20 | 22 | ) |
@@ -95,6 +97,15 @@ def store_output( |
95 | 97 | catalog.store_output("test_output", "/tmp/test") # Should not raise an error |
96 | 98 |
|
97 | 99 |
|
| 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 | + |
98 | 109 | class TestExecutionHookExtended: |
99 | 110 | """Test the ExecutionHooksBasePlugin foundation class methods.""" |
100 | 111 |
|
@@ -138,10 +149,55 @@ class TestModel(ExecutionHooksBasePlugin): |
138 | 149 | assert model.get_input_query("test") is None |
139 | 150 | assert model.get_output_query("test") is None |
140 | 151 |
|
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 |
142 | 153 | with pytest.raises(RuntimeError, match="No output path defined"): |
143 | 154 | model.data_catalog.store_output("test", "/tmp/file.txt") |
144 | 155 |
|
| 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 | + |
145 | 201 | def test_model_serialization(self): |
146 | 202 | """Test that model serialization works correctly.""" |
147 | 203 |
|
|
0 commit comments