diff --git a/tests/test_middleware_interface.py b/tests/test_middleware_interface.py index 424f59e9..928fc504 100644 --- a/tests/test_middleware_interface.py +++ b/tests/test_middleware_interface.py @@ -46,6 +46,8 @@ import lsst.daf.butler.tests as butler_tests from lsst.obs.base.formatters.fitsExposure import FitsImageFormatter from lsst.obs.base.ingest import RawFileDatasetInfo, RawFileData +import lsst.pipe.base +from lsst.pipe.base.tests.simpleQGraph import makeSimpleQGraph import lsst.resources import lsst.sphgeom @@ -570,7 +572,7 @@ def _check_run_pipeline_fallback(self, callable, pipe_files, graphs, final_label def test_run_pipeline_fallback_1failof2(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml')] - graph_list = [[], ["node1", "node2"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(2)] expected = "SingleFrame.yaml" self._prepare_run_pipeline() @@ -580,7 +582,7 @@ def test_run_pipeline_fallback_1failof2(self): def test_run_pipeline_fallback_1failof2_inverse(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml')] - graph_list = [["node1", "node2"], []] + graph_list = [self._make_test_graph(2), self._make_test_graph(0)] expected = "ApPipe.yaml" self._prepare_run_pipeline() @@ -590,7 +592,7 @@ def test_run_pipeline_fallback_1failof2_inverse(self): def test_run_pipeline_fallback_2failof2(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml')] - graph_list = [[], []] + graph_list = [self._make_test_graph(0), self._make_test_graph(0)] expected = "" self._prepare_run_pipeline() @@ -602,7 +604,7 @@ def test_run_pipeline_fallback_0failof3(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml'), os.path.join(self.data_dir, 'ISR.yaml')] - graph_list = [["node1", "node2"], ["node3", "node4"], ["node5"]] + graph_list = [self._make_test_graph(2), self._make_test_graph(2), self._make_test_graph(0)] expected = "ApPipe.yaml" self._prepare_run_pipeline() @@ -613,7 +615,7 @@ def test_run_pipeline_fallback_1failof3(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml'), os.path.join(self.data_dir, 'ISR.yaml')] - graph_list = [[], ["node3", "node4"], ["node5"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(1)] expected = "SingleFrame.yaml" self._prepare_run_pipeline() @@ -624,7 +626,7 @@ def test_run_pipeline_fallback_2failof3(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml'), os.path.join(self.data_dir, 'ISR.yaml')] - graph_list = [[], [], ["node5"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(0), self._make_test_graph(1)] expected = "ISR.yaml" self._prepare_run_pipeline() @@ -635,7 +637,7 @@ def test_run_pipeline_fallback_2failof3_inverse(self): pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'), os.path.join(self.data_dir, 'SingleFrame.yaml'), os.path.join(self.data_dir, 'ISR.yaml')] - graph_list = [[], ["node3", "node4"], []] + graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(0)] expected = "SingleFrame.yaml" self._prepare_run_pipeline() @@ -745,7 +747,7 @@ def test_run_preprocessing_full(self): def test_run_preprocessing_fallback_1failof2(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml')] - graph_list = [[], ["node1", "node2"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(2)] expected = "MinPrep.yaml" self._prepare_run_preprocessing() @@ -754,7 +756,7 @@ def test_run_preprocessing_fallback_1failof2(self): def test_run_preprocessing_fallback_1failof2_inverse(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml')] - graph_list = [["node1", "node2"], []] + graph_list = [self._make_test_graph(2), self._make_test_graph(0)] expected = "Preprocess.yaml" self._prepare_run_preprocessing() @@ -763,7 +765,7 @@ def test_run_preprocessing_fallback_1failof2_inverse(self): def test_run_preprocessing_fallback_2failof2(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml')] - graph_list = [[], []] + graph_list = [self._make_test_graph(0), self._make_test_graph(0)] expected = "" self._prepare_run_preprocessing() @@ -775,7 +777,7 @@ def test_run_preprocessing_fallback_0failof3(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml'), os.path.join(self.data_dir, 'NoPrep.yaml')] - graph_list = [["node1", "node2"], ["node3", "node4"], ["node5"]] + graph_list = [self._make_test_graph(2), self._make_test_graph(2), self._make_test_graph(1)] expected = "Preprocess.yaml" self._prepare_run_preprocessing() @@ -785,7 +787,7 @@ def test_run_preprocessing_fallback_1failof3(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml'), os.path.join(self.data_dir, 'NoPrep.yaml')] - graph_list = [[], ["node3", "node4"], ["node5"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(1)] expected = "MinPrep.yaml" self._prepare_run_preprocessing() @@ -795,7 +797,7 @@ def test_run_preprocessing_fallback_2failof3(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml'), os.path.join(self.data_dir, 'NoPrep.yaml')] - graph_list = [[], [], ["node5"]] + graph_list = [self._make_test_graph(0), self._make_test_graph(0), self._make_test_graph(1)] expected = "NoPrep.yaml" self._prepare_run_preprocessing() @@ -805,7 +807,7 @@ def test_run_preprocessing_fallback_2failof3_inverse(self): pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'), os.path.join(self.data_dir, 'MinPrep.yaml'), os.path.join(self.data_dir, 'NoPrep.yaml')] - graph_list = [[], ["node3", "node4"], []] + graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(0)] expected = "MinPrep.yaml" self._prepare_run_preprocessing() @@ -912,6 +914,29 @@ def _make_expanded_ref(registry, dtype, data_id, run): return lsst.daf.butler.DatasetRef(registry.getDatasetType(dtype), data_id, run=run) \ .expanded(registry.expandDataId(data_id)) + @staticmethod + def _make_test_graph(n_quanta): + """Make a `QuantumGraph` for tests. + + Parameters + ---------- + n_quanta : `int` + Number of quanta in a graph. + + Returns + ------- + qgraph : `~lsst.pipe.base.QuantumGraph` + Quantum graph instance. + """ + with tempfile.TemporaryDirectory() as tmpdir: + if n_quanta == 0: + butler = Butler(Butler.makeRepo(tmpdir)) + return lsst.pipe.base.QuantumGraph({}, universe=butler.dimensions) + elif n_quanta < 0: + raise RuntimeError("Invalid input") + else: + return makeSimpleQGraph(n_quanta, root=tmpdir)[1] + def test_get_sasquatch_dispatcher(self): self.assertIsNone(_get_sasquatch_dispatcher()) with unittest.mock.patch.dict(os.environ,