Coverage for tests/test_graphBuilder.py : 53%

Hot-keys 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
27from lsst.pipe.base import GraphBuilder
28from lsst.pipe.base.tests import simpleQGraph
29import lsst.utils.tests
30from lsst.utils.tests import temporaryDirectory
32_LOG = logging.getLogger(__name__)
35class VerifyInstrumentRestrictionTestCase(unittest.TestCase):
37 def testAddInstrument(self):
38 """Verify the pipeline instrument is added to the query."""
39 self.assertEqual(
40 GraphBuilder._verifyInstrumentRestriction("HSC", "tract = 42"),
41 "instrument = 'HSC' AND (tract = 42)")
43 def testQueryContainsInstrument(self):
44 """Verify the instrument is found and no further action is taken."""
45 self.assertEqual(
46 GraphBuilder._verifyInstrumentRestriction("HSC", "'HSC' = instrument AND tract = 42"),
47 "'HSC' = instrument AND tract = 42")
49 def testQueryContainsInstrumentAltOrder(self):
50 """Verify instrument is found in a different order, with no further
51 action."""
52 self.assertEqual(
53 GraphBuilder._verifyInstrumentRestriction("HSC", "tract=42 AND instrument='HSC'"),
54 "tract=42 AND instrument='HSC'")
56 def testQueryContainsSimilarKey(self):
57 """Verify a key that contains "instrument" is not confused for the
58 actual "instrument" key."""
59 self.assertEqual(
60 GraphBuilder._verifyInstrumentRestriction("HSC", "notinstrument=42 AND instrument='HSC'"),
61 "notinstrument=42 AND instrument='HSC'")
63 def testNoPipelineInstrument(self):
64 """Verify that when no pipeline instrument is passed that the query is
65 returned unchanged."""
66 self.assertEqual(
67 GraphBuilder._verifyInstrumentRestriction(None, "foo=bar"),
68 "foo=bar")
70 def testNoPipelineInstrumentTwoQueryInstruments(self):
71 """Verify that when no pipeline instrument is passed that the query can
72 contain two instruments."""
73 self.assertEqual(
74 GraphBuilder._verifyInstrumentRestriction(None, "instrument = 'HSC' OR instrument = 'LSSTCam'"),
75 "instrument = 'HSC' OR instrument = 'LSSTCam'")
77 def testTwoQueryInstruments(self):
78 """Verify that when a pipeline instrument is passed and the query
79 contains two instruments that a RuntimeError is raised."""
80 with self.assertRaises(RuntimeError):
81 GraphBuilder._verifyInstrumentRestriction("HSC", "instrument = 'HSC' OR instrument = 'LSSTCam'")
83 def testNoQuery(self):
84 """Test adding the instrument query to an empty query."""
85 self.assertEqual(GraphBuilder._verifyInstrumentRestriction("HSC", ""), "instrument = 'HSC'")
87 def testNoQueryNoInstruments(self):
88 """Test the verify function when there is no instrument and no
89 query."""
90 self.assertEqual(GraphBuilder._verifyInstrumentRestriction("", ""), "")
93class GraphBuilderTestCase(unittest.TestCase):
95 def testDefault(self):
96 """Simple test to verify makeSimpleQGraph can be used to make a Quantum
97 Graph."""
98 with temporaryDirectory() as root:
99 # makeSimpleQGraph calls GraphBuilder.
100 butler, qgraph = simpleQGraph.makeSimpleQGraph(root=root)
101 # by default makeSimpleQGraph makes a graph with 5 nodes
102 self.assertEqual(len(qgraph), 5)
104 def testAddInstrumentMismatch(self):
105 """Verify that a RuntimeError is raised if the instrument in the user
106 query does not match the instrument in the pipeline."""
107 with temporaryDirectory() as root:
108 pipeline = simpleQGraph.makeSimplePipeline(
109 nQuanta=5,
110 instrument="lsst.pipe.base.tests.simpleQGraph.SimpleInstrument")
111 with self.assertRaises(RuntimeError):
112 simpleQGraph.makeSimpleQGraph(root=root,
113 pipeline=pipeline,
114 userQuery="instrument = 'foo'")
117if __name__ == "__main__": 117 ↛ 118line 117 didn't jump to line 118, because the condition on line 117 was never true
118 lsst.utils.tests.init()
119 unittest.main()