Coverage for tests/test_simple_pipeline_executor.py: 38%

Shortcuts 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

51 statements  

1# This file is part of ctrl_mpexec. 

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

21 

22import os 

23import shutil 

24import tempfile 

25import unittest 

26 

27import lsst.daf.butler 

28import lsst.utils.tests 

29from lsst.ctrl.mpexec import SimplePipelineExecutor 

30from lsst.pipe.base import TaskDef 

31from lsst.pipe.base.tests.no_dimensions import NoDimensionsTestTask 

32 

33 

34class SimplePipelineExecutorTests(lsst.utils.tests.TestCase): 

35 """Test the SimplePipelineExecutor API with a trivial task.""" 

36 

37 def setUp(self): 

38 self.path = tempfile.mkdtemp() 

39 lsst.daf.butler.Butler.makeRepo(self.path) 

40 self.butler = SimplePipelineExecutor.prep_butler(self.path, [], "fake") 

41 self.butler.registry.registerDatasetType( 

42 lsst.daf.butler.DatasetType( 

43 "input", 

44 dimensions=self.butler.registry.dimensions.empty, 

45 storageClass="StructuredDataDict", 

46 ) 

47 ) 

48 self.butler.put({"zero": 0}, "input") 

49 

50 def tearDown(self): 

51 shutil.rmtree(self.path, ignore_errors=True) 

52 

53 def test_from_task_class(self): 

54 """Test executing a single quantum with an executor created by the 

55 `from_task_class` factory method, and the 

56 `SimplePipelineExecutor.as_generator` method. 

57 """ 

58 executor = SimplePipelineExecutor.from_task_class(NoDimensionsTestTask, butler=self.butler) 

59 (quantum,) = executor.as_generator(register_dataset_types=True) 

60 self.assertEqual(self.butler.get("output"), {"zero": 0, "one": 1}) 

61 

62 def test_from_pipeline(self): 

63 """Test executing a two quanta from different configurations of the 

64 same task, with an executor created by the `from_pipeline` factory 

65 method, and the `SimplePipelineExecutor.run` method. 

66 """ 

67 config_a = NoDimensionsTestTask.ConfigClass() 

68 config_a.connections.output = "intermediate" 

69 config_b = NoDimensionsTestTask.ConfigClass() 

70 config_b.connections.input = "intermediate" 

71 config_b.key = "two" 

72 config_b.value = 2 

73 task_defs = [ 

74 TaskDef(label="a", taskClass=NoDimensionsTestTask, config=config_a), 

75 TaskDef(label="b", taskClass=NoDimensionsTestTask, config=config_b), 

76 ] 

77 executor = SimplePipelineExecutor.from_pipeline(task_defs, butler=self.butler) 

78 quanta = executor.run(register_dataset_types=True) 

79 self.assertEqual(len(quanta), 2) 

80 self.assertEqual(self.butler.get("intermediate"), {"zero": 0, "one": 1}) 

81 self.assertEqual(self.butler.get("output"), {"zero": 0, "one": 1, "two": 2}) 

82 

83 def test_from_pipeline_file(self): 

84 """Test executing a two quanta from different configurations of the 

85 same task, with an executor created by the `from_pipeline_filename` 

86 factory method, and the `SimplePipelineExecutor.run` method. 

87 """ 

88 filename = os.path.join(self.path, "pipeline.yaml") 

89 with open(filename, "w") as f: 

90 f.write( 

91 """ 

92 description: test 

93 tasks: 

94 a: 

95 class: "lsst.pipe.base.tests.no_dimensions.NoDimensionsTestTask" 

96 config: 

97 connections.output: "intermediate" 

98 b: 

99 class: "lsst.pipe.base.tests.no_dimensions.NoDimensionsTestTask" 

100 config: 

101 connections.input: "intermediate" 

102 key: "two" 

103 value: 2 

104 """ 

105 ) 

106 executor = SimplePipelineExecutor.from_pipeline_filename(filename, butler=self.butler) 

107 quanta = executor.run(register_dataset_types=True) 

108 self.assertEqual(len(quanta), 2) 

109 self.assertEqual(self.butler.get("intermediate"), {"zero": 0, "one": 1}) 

110 self.assertEqual(self.butler.get("output"), {"zero": 0, "one": 1, "two": 2}) 

111 

112 

113class MemoryTester(lsst.utils.tests.MemoryTestCase): 

114 pass 

115 

116 

117def setup_module(module): 

118 lsst.utils.tests.init() 

119 

120 

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

122 lsst.utils.tests.init() 

123 unittest.main()