Coverage for tests/test_cliCmdRemoveRuns.py: 35%
Shortcuts 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
Shortcuts 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 remove-runs subcommand.
23"""
26import os
27import unittest
29from lsst.daf.butler import DatasetType
30from lsst.daf.butler.cli import butler
31from lsst.daf.butler.cli.cmd._remove_runs import (
32 abortedMsg,
33 didRemoveDatasetsMsg,
34 didRemoveRunsMsg,
35 noRunCollectionsMsg,
36 removedRunsMsg,
37 willRemoveDatasetsMsg,
38 willRemoveRunsMsg,
39)
40from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg
41from lsst.daf.butler.tests.utils import MetricTestRepo
43TESTDIR = os.path.abspath(os.path.dirname(__file__))
46class RemoveCollectionTest(unittest.TestCase):
47 """Test the butler remove-runs command."""
49 def setUp(self):
50 self.runner = LogCliRunner()
52 def test_removeRuns(self):
53 with self.runner.isolated_filesystem():
54 root = "repo"
55 repo = MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
56 # Add a dataset type that will have no datasets to make sure it
57 # isn't printed.
58 repo.butler.registry.registerDatasetType(
59 DatasetType("no_datasets", repo.butler.registry.dimensions.empty, "StructuredDataDict")
60 )
62 # Execute cmd but say no, check for expected outputs.
63 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="no")
64 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
65 self.assertIn(willRemoveRunsMsg, result.output)
66 self.assertIn(willRemoveDatasetsMsg, result.output)
67 self.assertIn(abortedMsg, result.output)
68 self.assertNotIn("no_datasets", result.output)
70 # ...say yes
71 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="yes")
72 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
73 self.assertIn(willRemoveRunsMsg, result.output)
74 self.assertIn(willRemoveDatasetsMsg, result.output)
75 self.assertIn(removedRunsMsg, result.output)
77 # now they've been deleted, try again and check for "none found"
78 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"])
79 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
80 self.assertIn(noRunCollectionsMsg, result.output)
82 # remake the repo and check --no-confirm option
83 root = "repo1"
84 MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
86 # Execute cmd but say no, check for expected outputs.
87 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*", "--no-confirm"])
88 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
89 self.assertIn(didRemoveRunsMsg, result.output)
90 self.assertIn(didRemoveDatasetsMsg, result.output)
92 # Execute cmd looking for a non-existant collection
93 result = self.runner.invoke(butler.cli, ["remove-runs", root, "foo"])
94 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
95 self.assertIn(noRunCollectionsMsg, result.output)
98if __name__ == "__main__": 98 ↛ 99line 98 didn't jump to line 99, because the condition on line 98 was never true
99 unittest.main()