Coverage for tests/test_cmd_line_embedder.py: 24%
50 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-26 03:01 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-26 03:01 -0700
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/>.
28"""Unit tests for cmd_line_embedder.py.
29"""
30import unittest
32from lsst.ctrl.bps import GenericWorkflowFile
33from lsst.ctrl.bps.panda.cmd_line_embedder import CommandLineEmbedder
36class TestCmdLineEmbedder(unittest.TestCase):
37 """Test CmdLineEmbedder class."""
39 def setUp(self):
40 self.cmd_line_0 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b {key1} -c {key2} -d {key3} {key4}"
41 self.cmd_line_1 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:file3> -c <FILE:file4> -d {key3} {key4}"
42 self.cmd_line_2 = (
43 "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:sfile1> -c <FILE:file3> -d <FILE:sfile2> <FILE:file4>"
44 )
45 self.sfile1 = GenericWorkflowFile("sfile1", "/path/to/sfile1.yaml", False, True, True)
46 self.sfile2 = GenericWorkflowFile("sfile2", "/path/to/sfile2.yaml", False, True, True)
47 self.file3 = GenericWorkflowFile("file3", "/path/to/file3.yaml", True, False, False)
48 self.file4 = GenericWorkflowFile("file4", "/path/to/file4.yaml", True, False, False)
50 self.ans_cmd_line_0 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b {key1} -c {key2} -d {key3} {key4}"
51 self.ans_cmd_line_1 = "<ENV:CTRL_MPEXEC_DIR>/mycmd -b <FILE:file3> -c <FILE:file4> -d {key3} {key4}"
52 self.ans_cmd_line_2 = (
53 "<ENV:CTRL_MPEXEC_DIR>/mycmd -b /path/to/sfile1.yaml -c <FILE:file3> "
54 "-d /path/to/sfile2.yaml <FILE:file4>"
55 )
57 def testReplaceStaticFilesNoFiles(self):
58 orig_cmd_line = self.cmd_line_0
59 orig_cmd_line_copy = orig_cmd_line
61 cmd_line_embedder = CommandLineEmbedder({})
62 new_cmd_line = cmd_line_embedder.replace_static_files(orig_cmd_line, [])
64 # Ensure no side effect
65 self.assertEqual(orig_cmd_line, orig_cmd_line_copy)
66 self.assertEqual(new_cmd_line, orig_cmd_line_copy)
68 def testReplaceStaticFilesMissingFiles(self):
69 orig_cmd_line = self.cmd_line_1
70 orig_cmd_line_copy = orig_cmd_line
72 cmd_line_embedder = CommandLineEmbedder({})
73 with self.assertRaises(RuntimeError):
74 _ = cmd_line_embedder.replace_static_files(orig_cmd_line, [self.sfile1, self.file3])
76 self.assertEqual(orig_cmd_line, orig_cmd_line_copy)
78 def testReplaceStaticFilesNone(self):
79 orig_cmd_line = self.cmd_line_1
80 orig_cmd_line_copy = orig_cmd_line
82 cmd_line_embedder = CommandLineEmbedder({})
83 new_cmd_line = cmd_line_embedder.replace_static_files(
84 orig_cmd_line, [self.sfile1, self.sfile2, self.file3, self.file4]
85 )
87 self.assertEqual(orig_cmd_line, orig_cmd_line_copy)
88 self.assertEqual(new_cmd_line, self.ans_cmd_line_1)
90 def testReplaceStaticFilesSome(self):
91 orig_cmd_line = self.cmd_line_2
92 orig_cmd_line_copy = orig_cmd_line
94 cmd_line_embedder = CommandLineEmbedder({})
95 new_cmd_line = cmd_line_embedder.replace_static_files(
96 orig_cmd_line, [self.sfile1, self.sfile2, self.file3, self.file4]
97 )
99 self.assertEqual(orig_cmd_line, orig_cmd_line_copy)
100 self.assertEqual(new_cmd_line, self.ans_cmd_line_2)
102 def testOKPseudoFilename(self):
103 cmd_line_embedder = CommandLineEmbedder({})
104 _, name = cmd_line_embedder.substitute_command_line("", {}, "j" * 4005, [])
105 self.assertIn("j" * 4005, name)
108if __name__ == "__main__": 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never true
109 unittest.main()