Hide keyboard shortcuts

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/>. 

21 

22import unittest 

23import astropy.time 

24 

25from lsst.daf.butler import Quantum, DimensionUniverse, StorageClass, DatasetType, DatasetRef 

26from lsst.daf.butler.core.utils import NamedKeyDict 

27 

28"""Tests for Quantum. 

29""" 

30 

31 

32class QuantumTestCase(unittest.TestCase): 

33 """Test for Quantum. 

34 """ 

35 

36 def testConstructor(self): 

37 """Test of constructor. 

38 """ 

39 # Quantum specific arguments 

40 run = None # TODO add Run 

41 taskName = "some.task.object" # can't use a real PipelineTask due to inverted package dependency 

42 # Base class arguments 

43 startTime = astropy.time.Time("2018-01-01", format="iso", scale="utc") 

44 endTime = astropy.time.Time("2018-01-02", format="iso", scale="utc") 

45 host = "localhost" 

46 quantum = Quantum(taskName=taskName, run=run, startTime=startTime, endTime=endTime, host=host) 

47 self.assertEqual(quantum.taskName, taskName) 

48 self.assertEqual(quantum.run, run) 

49 self.assertEqual(quantum.predictedInputs, NamedKeyDict()) 

50 self.assertEqual(quantum.actualInputs, NamedKeyDict()) 

51 self.assertIsNone(quantum.dataId) 

52 self.assertIsNone(quantum.id) 

53 self.assertEqual(quantum.startTime, startTime) 

54 self.assertEqual(quantum.endTime, endTime) 

55 self.assertEqual(quantum.host, host) 

56 

57 def testAddInputsOutputs(self): 

58 """Test of addPredictedInput() method. 

59 """ 

60 quantum = Quantum(taskName="some.task.object", run=None) 

61 

62 # start with empty 

63 self.assertEqual(quantum.predictedInputs, dict()) 

64 universe = DimensionUniverse() 

65 instrument = "DummyCam" 

66 datasetTypeName = "test_ds" 

67 storageClass = StorageClass("testref_StructuredData") 

68 datasetType = DatasetType(datasetTypeName, universe.extract(("instrument", "visit")), storageClass) 

69 

70 # add one ref 

71 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=42)) 

72 quantum.addPredictedInput(ref) 

73 self.assertIn(datasetTypeName, quantum.predictedInputs) 

74 self.assertEqual(len(quantum.predictedInputs[datasetTypeName]), 1) 

75 # add second ref 

76 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=43)) 

77 quantum.addPredictedInput(ref) 

78 self.assertEqual(len(quantum.predictedInputs[datasetTypeName]), 2) 

79 

80 # mark last ref as actually used 

81 self.assertEqual(quantum.actualInputs, dict()) 

82 quantum._markInputUsed(ref) 

83 self.assertIn(datasetTypeName, quantum.actualInputs) 

84 self.assertEqual(len(quantum.actualInputs[datasetTypeName]), 1) 

85 

86 # add couple of outputs too 

87 self.assertEqual(quantum.outputs, dict()) 

88 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=42)) 

89 quantum.addOutput(ref) 

90 self.assertIn(datasetTypeName, quantum.outputs) 

91 self.assertEqual(len(quantum.outputs[datasetTypeName]), 1) 

92 

93 ref = DatasetRef(datasetType, dict(instrument=instrument, visit=43)) 

94 quantum.addOutput(ref) 

95 self.assertEqual(len(quantum.outputs[datasetTypeName]), 2) 

96 

97 

98if __name__ == "__main__": 98 ↛ 99line 98 didn't jump to line 99, because the condition on line 98 was never true

99 unittest.main()