Coverage for tests/test_cliUtils.py: 37%

19 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-14 19:56 +0000

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 

22"""Unit tests for the daf_butler shared CLI options. 

23""" 

24 

25import unittest 

26 

27from lsst.ctrl.mpexec.cli.utils import _PipelineAction, makePipelineActions 

28 

29 

30class PipelineActionTestCase(unittest.TestCase): 

31 """Test command-line utility functions.""" 

32 

33 def test_makePipelineActions(self): 

34 """Test converting each CLI option flag to its associated pipeline 

35 action type. 

36 """ 

37 self.assertEqual( 

38 makePipelineActions(["-t", "foo"]), [_PipelineAction(action="new_task", label=None, value="foo")] 

39 ) 

40 self.assertEqual( 

41 makePipelineActions(["--task", "foo"]), 

42 [_PipelineAction(action="new_task", label=None, value="foo")], 

43 ) 

44 self.assertEqual( 

45 makePipelineActions(["--delete", "foo"]), 

46 [_PipelineAction(action="delete_task", label="foo", value="")], 

47 ) 

48 self.assertEqual( 

49 makePipelineActions(["-c", "task:addend=100"]), 

50 [_PipelineAction(action="config", label="task", value="addend=100")], 

51 ) 

52 self.assertEqual( 

53 makePipelineActions(["--config", "task:addend=100"]), 

54 [_PipelineAction(action="config", label="task", value="addend=100")], 

55 ) 

56 self.assertEqual( 

57 makePipelineActions(["-C", "task:filename"]), 

58 [_PipelineAction(action="configfile", label="task", value="filename")], 

59 ) 

60 self.assertEqual( 

61 makePipelineActions(["--config-file", "task:filename"]), 

62 [_PipelineAction(action="configfile", label="task", value="filename")], 

63 ) 

64 self.assertEqual( 

65 makePipelineActions(["--instrument", "foo"]), 

66 [_PipelineAction(action="add_instrument", label=None, value="foo")], 

67 ) 

68 self.assertEqual( 

69 makePipelineActions(["--instrument", "foo"]), 

70 [_PipelineAction(action="add_instrument", label=None, value="foo")], 

71 ) 

72 

73 def test_nonActions(self): 

74 """Test that args with a flag that does not represent an action works; 

75 that arg should be ignored. 

76 """ 

77 self.assertEqual(makePipelineActions(["-n"]), []) 

78 self.assertEqual( 

79 makePipelineActions(["-n", "-t", "foo"]), 

80 [_PipelineAction(action="new_task", label=None, value="foo")], 

81 ) 

82 

83 def test_multipleActions(self): 

84 """Test args with multiple actions, with non-actions mixed in.""" 

85 self.assertEqual( 

86 makePipelineActions( 

87 [ 

88 "--foo", 

89 "bar", 

90 "-C", 

91 "task:filename", 

92 "-x", 

93 "-c", 

94 "task:addend=100", 

95 "--instrument", 

96 "instr", 

97 ] 

98 ), 

99 [ 

100 _PipelineAction(action="configfile", label="task", value="filename"), 

101 _PipelineAction(action="config", label="task", value="addend=100"), 

102 _PipelineAction(action="add_instrument", label=None, value="instr"), 

103 ], 

104 ) 

105 

106 

107if __name__ == "__main__": 

108 unittest.main()