Coverage for tests/test_cliCmdDefineVisits.py : 48%

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/>.
22"""Unit tests for daf_butler CLI define-visits command.
23"""
25import click
26import click.testing
27import unittest
29from lsst.daf.butler.cli import butler
30from lsst.daf.butler.cli.utils import Mocker, mockEnvVar
33def makeExpectedKwargs(**kwargs):
34 expected = dict(config_file=None,
35 collections=[])
36 expected.update(kwargs)
37 return expected
40class DefineVisitsTest(unittest.TestCase):
42 def run_test(self, inputs, expectedKwargs):
43 """Test command line interaction with the defineVisits command function.
45 Parameters
46 ----------
47 inputs : [`str`]
48 A list of the arguments to the butler command, starting with
49 `define-visits`
50 expectedKwargs : `dict` [`str`, `str`]
51 The expected arguments to the define-visits command function, keys are
52 the argument name and values are the argument value.
53 """
54 runner = click.testing.CliRunner(env=mockEnvVar)
55 result = runner.invoke(butler.cli, inputs)
56 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
57 Mocker.mock.assert_called_with(**expectedKwargs)
59 def test_repoBasic(self):
60 """Test the most basic required arguments."""
61 expected = makeExpectedKwargs(repo="here", instrument="a.b.c")
62 self.run_test(["define-visits", "here",
63 "--instrument", "a.b.c"], expected)
65 def test_all(self):
66 """Test all the arguments."""
67 expected = dict(repo="here", instrument="a.b.c", config_file="/path/to/config",
68 # The list of collections must be in exactly the same order as it is passed in the
69 # list of arguments to run_test.
70 collections=["foo/bar", "baz", "boz"])
71 self.run_test(["define-visits", "here",
72 "--instrument", "a.b.c",
73 "--collections", "foo/bar,baz",
74 "--config-file", "/path/to/config",
75 "--collections", "boz"], expected)
77 def test_missing(self):
78 """test a missing argument"""
79 with self.assertRaises(TypeError):
80 self.run_test(["define-visits", "from"])
83if __name__ == "__main__": 83 ↛ 84line 83 didn't jump to line 84, because the condition on line 83 was never true
84 unittest.main()