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

28from lsst.ctrl.mpexec.cli.utils import _PipelineAction 

29 

30 

31class PipelineActionTestCase(unittest.TestCase): 

32 

33 def test_makePipelineActions(self): 

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

35 action type.""" 

36 self.assertEqual(makePipelineActions(["-t", "foo"]), 

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

38 self.assertEqual(makePipelineActions(["--task", "foo"]), 

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

40 self.assertEqual(makePipelineActions(["--delete", "foo"]), 

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

42 self.assertEqual(makePipelineActions(["-c", "task:addend=100"]), 

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

44 self.assertEqual(makePipelineActions(["--config", "task:addend=100"]), 

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

46 self.assertEqual(makePipelineActions(["-C", "task:filename"]), 

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

48 self.assertEqual(makePipelineActions(["--config-file", "task:filename"]), 

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

50 self.assertEqual(makePipelineActions(["--instrument", "foo"]), 

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

52 self.assertEqual(makePipelineActions(["--instrument", "foo"]), 

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

54 

55 def test_nonActions(self): 

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

57 that arg should be ignored.""" 

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

59 self.assertEqual(makePipelineActions(["-n", "-t", "foo"]), 

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

61 

62 def test_multipleActions(self): 

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

64 self.assertEqual(makePipelineActions(["--foo", "bar", 

65 "-C", "task:filename", 

66 "-x", 

67 "-c", "task:addend=100", 

68 "--instrument", "instr"]), 

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

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

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

72 

73 

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

75 unittest.main()