Coverage for tests/test_cliCmdAssociate.py: 59%
20 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 15:15 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 15:15 +0000
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 prune-datasets subcommand.
23"""
25import unittest
26from unittest.mock import patch
28from lsst.daf.butler.cli.butler import cli as butlerCli
29from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg
32class AssociateTestCase(unittest.TestCase):
33 """Tests the ``associate`` ``butler`` subcommand.
35 ``script.associate`` contains no logic, so instead of mocking the
36 internals, just mock the call to that function to test for expected inputs
37 and input types.
38 """
40 def setUp(self):
41 self.runner = LogCliRunner()
43 @patch("lsst.daf.butler.script.associate")
44 def test_defaults(self, mockAssociate):
45 """Test the expected default values & types for optional options."""
46 result = self.runner.invoke(butlerCli, ["associate", "myRepo", "myCollection"])
47 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
48 mockAssociate.assert_called_once_with(
49 repo="myRepo",
50 collection="myCollection",
51 dataset_type=tuple(),
52 collections=tuple(),
53 where=None,
54 find_first=False,
55 )
57 @patch("lsst.daf.butler.script.associate")
58 def test_values(self, mockAssociate):
59 """Test expected values & types when passing in options."""
60 result = self.runner.invoke(
61 butlerCli,
62 [
63 "associate",
64 "myRepo",
65 "myCollection",
66 "--dataset-type",
67 "myDatasetType",
68 "--collections",
69 "myCollection,otherCollection",
70 "--where",
71 "'a=b'",
72 "--find-first",
73 ],
74 )
75 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
76 mockAssociate.assert_called_once_with(
77 repo="myRepo",
78 collection="myCollection",
79 dataset_type=("myDatasetType",),
80 collections=("myCollection", "otherCollection"),
81 where="'a=b'",
82 find_first=True,
83 )
86if __name__ == "__main__": 86 ↛ 87line 86 didn't jump to line 87, because the condition on line 86 was never true
87 unittest.main()