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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

# This file is part of daf_butler. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

import unittest 

from datetime import datetime 

 

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

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

 

"""Tests for Quantum. 

""" 

 

 

class QuantumTestCase(unittest.TestCase): 

"""Test for Quantum. 

""" 

 

def testConstructor(self): 

"""Test of constructor. 

""" 

# Quantum specific arguments 

run = None # TODO add Run 

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

# Base class arguments 

startTime = datetime(2018, 1, 1) 

endTime = datetime(2018, 1, 2) 

host = "localhost" 

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

self.assertEqual(quantum.taskName, taskName) 

self.assertEqual(quantum.run, run) 

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

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

self.assertIsNone(quantum.dataId) 

self.assertIsNone(quantum.id) 

self.assertEqual(quantum.startTime, startTime) 

self.assertEqual(quantum.endTime, endTime) 

self.assertEqual(quantum.host, host) 

 

def testAddInputsOutputs(self): 

"""Test of addPredictedInput() method. 

""" 

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

 

# start with empty 

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

universe = DimensionUniverse() 

instrument = "DummyCam" 

datasetTypeName = "test_ds" 

storageClass = StorageClass("testref_StructuredData") 

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

 

# add one ref 

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

quantum.addPredictedInput(ref) 

self.assertIn(datasetTypeName, quantum.predictedInputs) 

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

# add second ref 

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

quantum.addPredictedInput(ref) 

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

 

# mark last ref as actually used 

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

quantum._markInputUsed(ref) 

self.assertIn(datasetTypeName, quantum.actualInputs) 

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

 

# add couple of outputs too 

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

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

quantum.addOutput(ref) 

self.assertIn(datasetTypeName, quantum.outputs) 

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

 

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

quantum.addOutput(ref) 

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

 

 

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

unittest.main()