Coverage for tests/test_graphBuilder.py: 48%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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# (https://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 <https://www.gnu.org/licenses/>.
22"""Tests of things related to the GraphBuilder class."""
24import logging
25import unittest
27import lsst.utils.tests
28from lsst.daf.butler.registry import UserExpressionError
29from lsst.pipe.base.graphBuilder import DatasetQueryConstraintVariant
30from lsst.pipe.base.tests import simpleQGraph
31from lsst.utils.tests import temporaryDirectory
33_LOG = logging.getLogger(__name__)
36class GraphBuilderTestCase(unittest.TestCase):
37 def testDefault(self):
38 """Simple test to verify makeSimpleQGraph can be used to make a Quantum
39 Graph."""
40 with temporaryDirectory() as root:
41 # makeSimpleQGraph calls GraphBuilder.
42 butler, qgraph = simpleQGraph.makeSimpleQGraph(root=root)
43 # by default makeSimpleQGraph makes a graph with 5 nodes
44 self.assertEqual(len(qgraph), 5)
45 constraint = DatasetQueryConstraintVariant.OFF
46 _, qgraph2 = simpleQGraph.makeSimpleQGraph(
47 butler=butler, datasetQueryConstraint=constraint, callPopulateButler=False
48 )
49 self.assertEqual(len(qgraph2), 5)
50 self.assertEqual(qgraph, qgraph2)
51 constraint = DatasetQueryConstraintVariant.fromExpression("add_dataset0")
52 _, qgraph3 = simpleQGraph.makeSimpleQGraph(
53 butler=butler, datasetQueryConstraint=constraint, callPopulateButler=False
54 )
55 self.assertEqual(qgraph2, qgraph3)
57 def testAddInstrumentMismatch(self):
58 """Verify that a RuntimeError is raised if the instrument in the user
59 query does not match the instrument in the pipeline."""
60 with temporaryDirectory() as root:
61 pipeline = simpleQGraph.makeSimplePipeline(
62 nQuanta=5, instrument="lsst.pipe.base.tests.simpleQGraph.SimpleInstrument"
63 )
64 with self.assertRaises(UserExpressionError):
65 simpleQGraph.makeSimpleQGraph(root=root, pipeline=pipeline, userQuery="instrument = 'foo'")
68if __name__ == "__main__": 68 ↛ 69line 68 didn't jump to line 69, because the condition on line 68 was never true
69 lsst.utils.tests.init()
70 unittest.main()