Coverage for tests/test_cliUtils.py: 39%

21 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-30 02:36 -0800

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 def test_makePipelineActions(self): 

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

33 action type.""" 

34 self.assertEqual( 

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

36 ) 

37 self.assertEqual( 

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

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

40 ) 

41 self.assertEqual( 

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

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

44 ) 

45 self.assertEqual( 

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

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

48 ) 

49 self.assertEqual( 

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

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

52 ) 

53 self.assertEqual( 

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

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

56 ) 

57 self.assertEqual( 

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

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

60 ) 

61 self.assertEqual( 

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

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

64 ) 

65 self.assertEqual( 

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

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

68 ) 

69 

70 def test_nonActions(self): 

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

72 that arg should be ignored.""" 

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

74 self.assertEqual( 

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

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

77 ) 

78 

79 def test_multipleActions(self): 

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

81 self.assertEqual( 

82 makePipelineActions( 

83 [ 

84 "--foo", 

85 "bar", 

86 "-C", 

87 "task:filename", 

88 "-x", 

89 "-c", 

90 "task:addend=100", 

91 "--instrument", 

92 "instr", 

93 ] 

94 ), 

95 [ 

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

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

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

99 ], 

100 ) 

101 

102 

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

104 unittest.main()