Coverage for tests/test_pipeline.py: 28%

60 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-09 03:06 -0800

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# (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 

22"""Simple unit test for Pipeline. 

23""" 

24 

25import pickle 

26import textwrap 

27import unittest 

28 

29import lsst.utils.tests 

30from lsst.pipe.base import Pipeline, PipelineDatasetTypes, TaskDef 

31from lsst.pipe.base.tests.simpleQGraph import AddTask, makeSimplePipeline 

32 

33 

34class PipelineTestCase(unittest.TestCase): 

35 """A test case for TaskDef and Pipeline.""" 

36 

37 def testTaskDef(self): 

38 """Tests for TaskDef structure""" 

39 task1 = TaskDef(taskClass=AddTask, config=AddTask.ConfigClass()) 

40 self.assertIn("Add", task1.taskName) 

41 self.assertIsInstance(task1.config, AddTask.ConfigClass) 

42 self.assertIsNotNone(task1.taskClass) 

43 self.assertEqual(task1.label, "add_task") 

44 task1a = pickle.loads(pickle.dumps(task1)) 

45 self.assertEqual(task1, task1a) 

46 

47 def testEmpty(self): 

48 """Creating empty pipeline""" 

49 pipeline = Pipeline("test") 

50 self.assertEqual(len(pipeline), 0) 

51 

52 def testInitial(self): 

53 """Testing constructor with initial data""" 

54 pipeline = makeSimplePipeline(2) 

55 self.assertEqual(len(pipeline), 2) 

56 expandedPipeline = list(pipeline.toExpandedPipeline()) 

57 self.assertEqual(expandedPipeline[0].taskName, "lsst.pipe.base.tests.simpleQGraph.AddTask") 

58 self.assertEqual(expandedPipeline[1].taskName, "lsst.pipe.base.tests.simpleQGraph.AddTask") 

59 self.assertEqual(expandedPipeline[0].taskClass, AddTask) 

60 self.assertEqual(expandedPipeline[1].taskClass, AddTask) 

61 self.assertEqual(expandedPipeline[0].label, "task0") 

62 self.assertEqual(expandedPipeline[1].label, "task1") 

63 

64 def testParameters(self): 

65 """Test that parameters can be set and used to format""" 

66 pipeline_str = textwrap.dedent( 

67 """ 

68 description: Test Pipeline 

69 parameters: 

70 testValue: 5 

71 tasks: 

72 add: 

73 class: test_pipeline.AddTask 

74 config: 

75 addend: parameters.testValue 

76 """ 

77 ) 

78 # verify that parameters are used in expanding a pipeline 

79 pipeline = Pipeline.fromString(pipeline_str) 

80 expandedPipeline = list(pipeline.toExpandedPipeline()) 

81 self.assertEqual(expandedPipeline[0].config.addend, 5) 

82 

83 # verify that a parameter can be overridden on the "command line" 

84 pipeline.addConfigOverride("parameters", "testValue", 14) 

85 expandedPipeline = list(pipeline.toExpandedPipeline()) 

86 self.assertEqual(expandedPipeline[0].config.addend, 14) 

87 

88 # verify that a non existing parameter cant be overridden 

89 with self.assertRaises(ValueError): 

90 pipeline.addConfigOverride("parameters", "missingValue", 17) 

91 

92 # verify that parameters does not support files or python overrides 

93 with self.assertRaises(ValueError): 

94 pipeline.addConfigFile("parameters", "fakeFile") 

95 with self.assertRaises(ValueError): 

96 pipeline.addConfigPython("parameters", "fakePythonString") 

97 

98 def testSerialization(self): 

99 pipeline = makeSimplePipeline(2) 

100 dump = str(pipeline) 

101 load = Pipeline.fromString(dump) 

102 self.assertEqual(pipeline, load) 

103 

104 def test_initOutputNames(self): 

105 """Test for PipelineDatasetTypes.initOutputNames method.""" 

106 pipeline = makeSimplePipeline(3) 

107 dsType = set(PipelineDatasetTypes.initOutputNames(pipeline)) 

108 expected = { 

109 "packages", 

110 "add_init_output1", 

111 "add_init_output2", 

112 "add_init_output3", 

113 "task0_config", 

114 "task1_config", 

115 "task2_config", 

116 } 

117 self.assertEqual(dsType, expected) 

118 

119 

120class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

121 pass 

122 

123 

124def setup_module(module): 

125 lsst.utils.tests.init() 

126 

127 

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

129 lsst.utils.tests.init() 

130 unittest.main()