Coverage for tests/test_quantum.py : 16%

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 daf_butler.
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/>.
22import unittest
23import astropy.time
25from lsst.daf.butler import Quantum, DimensionUniverse, NamedKeyDict, StorageClass, DatasetType, DatasetRef
27"""Tests for Quantum.
28"""
31class QuantumTestCase(unittest.TestCase):
32 """Test for Quantum.
33 """
35 def testConstructor(self):
36 """Test of constructor.
37 """
38 # Quantum specific arguments
39 run = None # TODO add Run
40 taskName = "some.task.object" # can't use a real PipelineTask due to inverted package dependency
41 # Base class arguments
42 startTime = astropy.time.Time("2018-01-01", format="iso", scale="utc")
43 endTime = astropy.time.Time("2018-01-02", format="iso", scale="utc")
44 host = "localhost"
45 quantum = Quantum(taskName=taskName, run=run, startTime=startTime, endTime=endTime, host=host)
46 self.assertEqual(quantum.taskName, taskName)
47 self.assertEqual(quantum.run, run)
48 self.assertEqual(quantum.predictedInputs, NamedKeyDict())
49 self.assertEqual(quantum.actualInputs, NamedKeyDict())
50 self.assertIsNone(quantum.dataId)
51 self.assertIsNone(quantum.id)
52 self.assertEqual(quantum.startTime, startTime)
53 self.assertEqual(quantum.endTime, endTime)
54 self.assertEqual(quantum.host, host)
56 def testAddInputsOutputs(self):
57 """Test of addPredictedInput() method.
58 """
59 quantum = Quantum(taskName="some.task.object", run=None)
61 # start with empty
62 self.assertEqual(quantum.predictedInputs, dict())
63 universe = DimensionUniverse()
64 instrument = "DummyCam"
65 datasetTypeName = "test_ds"
66 storageClass = StorageClass("testref_StructuredData")
67 datasetType = DatasetType(datasetTypeName, universe.extract(("instrument", "visit")), storageClass)
69 # add one ref
70 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=42))
71 quantum.addPredictedInput(ref)
72 self.assertIn(datasetTypeName, quantum.predictedInputs)
73 self.assertEqual(len(quantum.predictedInputs[datasetTypeName]), 1)
74 # add second ref
75 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=43))
76 quantum.addPredictedInput(ref)
77 self.assertEqual(len(quantum.predictedInputs[datasetTypeName]), 2)
79 # mark last ref as actually used
80 self.assertEqual(quantum.actualInputs, dict())
81 quantum._markInputUsed(ref)
82 self.assertIn(datasetTypeName, quantum.actualInputs)
83 self.assertEqual(len(quantum.actualInputs[datasetTypeName]), 1)
85 # add couple of outputs too
86 self.assertEqual(quantum.outputs, dict())
87 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=42))
88 quantum.addOutput(ref)
89 self.assertIn(datasetTypeName, quantum.outputs)
90 self.assertEqual(len(quantum.outputs[datasetTypeName]), 1)
92 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=43))
93 quantum.addOutput(ref)
94 self.assertEqual(len(quantum.outputs[datasetTypeName]), 2)
97if __name__ == "__main__": 97 ↛ 98line 97 didn't jump to line 98, because the condition on line 97 was never true
98 unittest.main()