Coverage for tests/test_cliCmdTestIngest.py : 46%

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 config-dump 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(directory=None,
35 file=None,
36 transfer="auto",
37 ingest_task="lsst.obs.base.RawIngestTask",
38 config={},
39 config_file=None)
40 expected.update(kwargs)
41 return expected
44class Suite(unittest.TestCase):
46 def run_test(self, inputs, expectedKwargs):
47 """Test command line interaction with ingest_raws command function.
49 Parameters
50 ----------
51 inputs : [`str`]
52 A list of the arguments to the butler command, starting with
53 `ingest-raws`
54 expectedKwargs : `dict` [`str`, `str`]
55 The expected arguments to the ingestRaws command function, keys are
56 the argument name and values are the argument value.
57 """
58 runner = click.testing.CliRunner(env=mockEnvVar)
59 result = runner.invoke(butler.cli, inputs)
60 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")
61 Mocker.mock.assert_called_with(**expectedKwargs)
63 def test_repoAndOutput(self):
64 """Test the most basic required arguments, repo and output run"""
65 expected = makeExpectedKwargs(repo="here", output_run="out")
66 self.run_test(["ingest-raws", "here",
67 "--output-run", "out"], expected)
69 def test_configMulti(self):
70 """Test config overrides"""
71 expected = makeExpectedKwargs(repo="here", output_run="out", config=dict(foo="1", bar="2", baz="3"))
72 self.run_test(["ingest-raws", "here",
73 "--output-run", "out",
74 "-c", "foo=1",
75 "--config", "bar=2,baz=3"], expected)
77 def test_configFile(self):
78 """Test config file override"""
79 expected = makeExpectedKwargs(repo="here", output_run="out", config_file="path/to/file.txt")
80 self.run_test(["ingest-raws", "here",
81 "--output-run", "out",
82 "--config-file", "path/to/file.txt"], expected)
84 def test_transfer(self):
85 """Test the transfer argument"""
86 expected = makeExpectedKwargs(repo="here", output_run="out", transfer="foo")
87 self.run_test(["ingest-raws", "here",
88 "--output-run", "out",
89 "--transfer", "foo"], expected)
91 def test_ingestTask(self):
92 """Test the ingest task argument"""
93 expected = makeExpectedKwargs(repo="here", output_run="out", ingest_task="foo.bar.baz")
94 self.run_test(["ingest-raws", "here",
95 "--output-run", "out",
96 "--ingest-task", "foo.bar.baz"], expected)
99if __name__ == "__main__": 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true
100 unittest.main()