Coverage for tests/test_cliCmdAssociate.py: 68%
18 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-25 10:50 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-25 10:50 +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 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 daf_butler CLI prune-datasets subcommand.
29"""
31import unittest
32from unittest.mock import patch
34from lsst.daf.butler.cli.butler import cli as butlerCli
35from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg
38class AssociateTestCase(unittest.TestCase):
39 """Tests the ``associate`` ``butler`` subcommand.
41 ``script.associate`` contains no logic, so instead of mocking the
42 internals, just mock the call to that function to test for expected inputs
43 and input types.
44 """
46 def setUp(self):
47 self.runner = LogCliRunner()
49 @patch("lsst.daf.butler.script.associate")
50 def test_defaults(self, mockAssociate):
51 """Test the expected default values & types for optional options."""
52 result = self.runner.invoke(butlerCli, ["associate", "myRepo", "myCollection"])
53 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
54 mockAssociate.assert_called_once_with(
55 repo="myRepo",
56 collection="myCollection",
57 dataset_type=(),
58 collections=(),
59 where="",
60 find_first=False,
61 )
63 @patch("lsst.daf.butler.script.associate")
64 def test_values(self, mockAssociate):
65 """Test expected values & types when passing in options."""
66 result = self.runner.invoke(
67 butlerCli,
68 [
69 "associate",
70 "myRepo",
71 "myCollection",
72 "--dataset-type",
73 "myDatasetType",
74 "--collections",
75 "myCollection,otherCollection",
76 "--where",
77 "'a=b'",
78 "--find-first",
79 ],
80 )
81 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
82 mockAssociate.assert_called_once_with(
83 repo="myRepo",
84 collection="myCollection",
85 dataset_type=("myDatasetType",),
86 collections=("myCollection", "otherCollection"),
87 where="'a=b'",
88 find_first=True,
89 )
92if __name__ == "__main__":
93 unittest.main()