Coverage for tests/test_cliUtils.py: 37%
19 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-03 02:52 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-03 02:52 -0700
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 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 <http://www.gnu.org/licenses/>.
28"""Unit tests for the daf_butler shared CLI options.
29"""
31import unittest
33from lsst.ctrl.mpexec.cli.utils import _PipelineAction, makePipelineActions
36class PipelineActionTestCase(unittest.TestCase):
37 """Test command-line utility functions."""
39 def test_makePipelineActions(self):
40 """Test converting each CLI option flag to its associated pipeline
41 action type.
42 """
43 self.assertEqual(
44 makePipelineActions(["-t", "foo"]), [_PipelineAction(action="new_task", label=None, value="foo")]
45 )
46 self.assertEqual(
47 makePipelineActions(["--task", "foo"]),
48 [_PipelineAction(action="new_task", label=None, value="foo")],
49 )
50 self.assertEqual(
51 makePipelineActions(["--delete", "foo"]),
52 [_PipelineAction(action="delete_task", label="foo", value="")],
53 )
54 self.assertEqual(
55 makePipelineActions(["-c", "task:addend=100"]),
56 [_PipelineAction(action="config", label="task", value="addend=100")],
57 )
58 self.assertEqual(
59 makePipelineActions(["--config", "task:addend=100"]),
60 [_PipelineAction(action="config", label="task", value="addend=100")],
61 )
62 self.assertEqual(
63 makePipelineActions(["-C", "task:filename"]),
64 [_PipelineAction(action="configfile", label="task", value="filename")],
65 )
66 self.assertEqual(
67 makePipelineActions(["--config-file", "task:filename"]),
68 [_PipelineAction(action="configfile", label="task", value="filename")],
69 )
70 self.assertEqual(
71 makePipelineActions(["--instrument", "foo"]),
72 [_PipelineAction(action="add_instrument", label=None, value="foo")],
73 )
74 self.assertEqual(
75 makePipelineActions(["--instrument", "foo"]),
76 [_PipelineAction(action="add_instrument", label=None, value="foo")],
77 )
79 def test_nonActions(self):
80 """Test that args with a flag that does not represent an action works;
81 that arg should be ignored.
82 """
83 self.assertEqual(makePipelineActions(["-n"]), [])
84 self.assertEqual(
85 makePipelineActions(["-n", "-t", "foo"]),
86 [_PipelineAction(action="new_task", label=None, value="foo")],
87 )
89 def test_multipleActions(self):
90 """Test args with multiple actions, with non-actions mixed in."""
91 self.assertEqual(
92 makePipelineActions(
93 [
94 "--foo",
95 "bar",
96 "-C",
97 "task:filename",
98 "-x",
99 "-c",
100 "task:addend=100",
101 "--instrument",
102 "instr",
103 ]
104 ),
105 [
106 _PipelineAction(action="configfile", label="task", value="filename"),
107 _PipelineAction(action="config", label="task", value="addend=100"),
108 _PipelineAction(action="add_instrument", label=None, value="instr"),
109 ],
110 )
113if __name__ == "__main__":
114 unittest.main()