Coverage for tests/test_cmd_line_embedder.py: 25%

55 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-18 09:55 +0000

1# This file is part of ctrl_bps_panda. 

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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27 

28"""Unit tests for cmd_line_embedder.py 

29""" 

30import unittest 

31 

32from lsst.ctrl.bps import GenericWorkflowFile 

33from lsst.ctrl.bps.panda.cmd_line_embedder import CommandLineEmbedder 

34from lsst.ctrl.bps.panda.constants import PANDA_MAX_LEN_INPUT_FILE 

35 

36 

37class TestCmdLineEmbedder(unittest.TestCase): 

38 """Test CmdLineEmbedder class""" 

39 

40 def setUp(self): 

41 self.cmd_line_0 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b {key1} -c {key2} -d {key3} {key4}" 

42 self.cmd_line_1 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:file3> -c <FILE:file4> -d {key3} {key4}" 

43 self.cmd_line_2 = ( 

44 "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:sfile1> -c <FILE:file3> -d <FILE:sfile2> <FILE:file4>" 

45 ) 

46 self.sfile1 = GenericWorkflowFile("sfile1", "/path/to/sfile1.yaml", False, True, True) 

47 self.sfile2 = GenericWorkflowFile("sfile2", "/path/to/sfile2.yaml", False, True, True) 

48 self.file3 = GenericWorkflowFile("file3", "/path/to/file3.yaml", True, False, False) 

49 self.file4 = GenericWorkflowFile("file4", "/path/to/file4.yaml", True, False, False) 

50 

51 self.ans_cmd_line_0 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b {key1} -c {key2} -d {key3} {key4}" 

52 self.ans_cmd_line_1 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:file3> -c <FILE:file4> -d {key3} {key4}" 

53 self.ans_cmd_line_2 = ( 

54 "<ENV:CTRL_MPEXEC_DIR>/mycmd -b /path/to/sfile1.yaml -c <FILE:file3> " 

55 "-d /path/to/sfile2.yaml <FILE:file4>" 

56 ) 

57 

58 def testReplaceStaticFilesNoFiles(self): 

59 orig_cmd_line = self.cmd_line_0 

60 orig_cmd_line_copy = orig_cmd_line 

61 

62 cmd_line_embedder = CommandLineEmbedder({}) 

63 new_cmd_line = cmd_line_embedder.replace_static_files(orig_cmd_line, []) 

64 

65 # Ensure no side effect 

66 self.assertEqual(orig_cmd_line, orig_cmd_line_copy) 

67 self.assertEqual(new_cmd_line, orig_cmd_line_copy) 

68 

69 def testReplaceStaticFilesMissingFiles(self): 

70 orig_cmd_line = self.cmd_line_1 

71 orig_cmd_line_copy = orig_cmd_line 

72 

73 cmd_line_embedder = CommandLineEmbedder({}) 

74 with self.assertRaises(RuntimeError): 

75 _ = cmd_line_embedder.replace_static_files(orig_cmd_line, [self.sfile1, self.file3]) 

76 

77 self.assertEqual(orig_cmd_line, orig_cmd_line_copy) 

78 

79 def testReplaceStaticFilesNone(self): 

80 orig_cmd_line = self.cmd_line_1 

81 orig_cmd_line_copy = orig_cmd_line 

82 

83 cmd_line_embedder = CommandLineEmbedder({}) 

84 new_cmd_line = cmd_line_embedder.replace_static_files( 

85 orig_cmd_line, [self.sfile1, self.sfile2, self.file3, self.file4] 

86 ) 

87 

88 self.assertEqual(orig_cmd_line, orig_cmd_line_copy) 

89 self.assertEqual(new_cmd_line, self.ans_cmd_line_1) 

90 

91 def testReplaceStaticFilesSome(self): 

92 orig_cmd_line = self.cmd_line_2 

93 orig_cmd_line_copy = orig_cmd_line 

94 

95 cmd_line_embedder = CommandLineEmbedder({}) 

96 new_cmd_line = cmd_line_embedder.replace_static_files( 

97 orig_cmd_line, [self.sfile1, self.sfile2, self.file3, self.file4] 

98 ) 

99 

100 self.assertEqual(orig_cmd_line, orig_cmd_line_copy) 

101 self.assertEqual(new_cmd_line, self.ans_cmd_line_2) 

102 

103 def testTooLongPseudoFilename(self): 

104 cmd_line_embedder = CommandLineEmbedder({}) 

105 with self.assertRaises(RuntimeError): 

106 _, _ = cmd_line_embedder.substitute_command_line("", {}, "j" * PANDA_MAX_LEN_INPUT_FILE, []) 

107 

108 def testOKPseudoFilename(self): 

109 cmd_line_embedder = CommandLineEmbedder({}) 

110 _, name = cmd_line_embedder.substitute_command_line("", {}, "j" * 15, []) 

111 self.assertIn("j" * 15, name) 

112 

113 

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

115 unittest.main()