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 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 tempfile 

24import unittest 

25 

26from lsst.ctrl.mpexec.cli import script 

27from lsst.ctrl.mpexec.cli.pipetask import cli as pipetaskCli 

28from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner 

29from lsst.pipe.base import Pipeline 

30import lsst.utils.tests 

31 

32 

33class BuildTestCase(unittest.TestCase): 

34 """Test a few of the inputs to the build script function to test basic 

35 funcitonality.""" 

36 

37 def testMakeEmptyPipeline(self): 

38 """Test building a pipeline with default arguments. 

39 """ 

40 pipeline = script.build() 

41 self.assertIsInstance(pipeline, Pipeline) 

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

43 

44 def testSavePipeline(self): 

45 """Test pipeline serialization.""" 

46 with tempfile.TemporaryDirectory() as tempdir: 

47 # make empty pipeline and store it in a file 

48 filename = os.path.join(tempdir, "pipeline") 

49 pipeline = script.build(save_pipeline=filename) 

50 self.assertIsInstance(pipeline, Pipeline) 

51 

52 # read pipeline from a file 

53 pipeline = script.build(pipeline=filename) 

54 self.assertIsInstance(pipeline, Pipeline) 

55 self.assertIsInstance(pipeline, Pipeline) 

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

57 

58 def testShowPipeline(self): 

59 """Test showing the pipeline.""" 

60 class ShowInfo: 

61 def __init__(self, show, expectedOutput): 

62 self.show = show 

63 self.expectedOutput = expectedOutput 

64 

65 def __repr__(self): 

66 return f"ShowInfo({self.show}, {self.expectedOutput}" 

67 

68 testdata = [ 

69 ShowInfo("pipeline", """description: anonymous 

70tasks: 

71 task: 

72 class: testUtil.AddTask 

73 config: 

74 - addend: '100'"""), 

75 ShowInfo("config", """### Configuration for task `task' 

76# Flag to enable/disable metadata saving for a task, enabled by default. 

77config.saveMetadata=True 

78 

79# amount to add 

80config.addend=100 

81 

82# name for connection input 

83config.connections.input='add_input' 

84 

85# name for connection output 

86config.connections.output='add_output' 

87 

88# name for connection initout 

89config.connections.initout='add_init_output'"""), 

90 

91 # history will contain machine-specific paths, TBD how to verify 

92 ShowInfo("history=task::addend", None), 

93 ShowInfo("tasks", "### Subtasks for task `AddTask'") 

94 ] 

95 

96 for showInfo in testdata: 

97 runner = LogCliRunner() 

98 result = runner.invoke(pipetaskCli, ["build", 

99 "--task", "testUtil.AddTask:task", 

100 "--config", "task:addend=100", 

101 "--show", showInfo.show]) 

102 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

103 if showInfo.expectedOutput is not None: 

104 self.assertIn(showInfo.expectedOutput, result.output, msg=f"for {showInfo}") 

105 

106 

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

108 lsst.utils.tests.init() 

109 unittest.main()