Coverage for python/lsst/pipe/base/tests/util.py: 11%
25 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-06-06 10:05 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-06-06 10:05 +0000
1# This file is part of pipe_base.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Collection of common methods for use in unit tests."""
24from __future__ import annotations
26from lsst.daf.butler import DatasetRef
28from ..graph import QuantumGraph
31def check_output_run(graph: QuantumGraph, run: str) -> list[DatasetRef]:
32 """Check that all output and intermediate datasets belong to a
33 specified run.
35 Parameters
36 ----------
37 graph : `Quantumgraph`
38 Quantum graph.
39 run : `str`
40 Output run name.
42 Returns
43 refs : `list` [ `DatasetRef` ]
44 List of output/intermediate dataset references that do NOT belong to
45 the specified run.
46 """
48 # Collect all inputs/outputs, so that we can build intermediate refs.
49 output_refs = []
50 input_refs = []
51 for node in graph:
52 for refs in node.quantum.outputs.values():
53 output_refs += refs
54 for refs in node.quantum.inputs.values():
55 input_refs += refs
56 for task_def in graph.iterTaskGraph():
57 init_refs = graph.initOutputRefs(task_def)
58 if init_refs:
59 output_refs += init_refs
60 init_refs = graph.initInputRefs(task_def)
61 if init_refs:
62 input_refs += init_refs
63 output_refs += graph.globalInitOutputRefs()
64 refs = [ref for ref in output_refs if ref.run != run]
66 output_ids = {ref.id for ref in output_refs}
67 intermediates = [ref for ref in input_refs if ref.id in output_ids]
68 refs += [ref for ref in intermediates if ref.run != run]
70 return refs