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.cli import butler
30from lsst.daf.butler.cli.cmd._remove_runs import (
31 noRunCollectionsMsg,
32 willRemoveRunsMsg,
33 willRemoveDatasetsMsg,
34 didRemoveRunsMsg,
35 didRemoveDatasetsMsg,
36 removedRunsMsg,
37 abortedMsg,
38)
39from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
40from 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.
48 """
50 def setUp(self):
51 self.runner = LogCliRunner()
53 def test_removeRuns(self):
54 with self.runner.isolated_filesystem():
55 root = "repo"
56 MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
58 # Execute cmd but say no, check for expected outputs.
59 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="no")
60 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
61 self.assertIn(willRemoveRunsMsg, result.output)
62 self.assertIn(willRemoveDatasetsMsg, result.output)
63 self.assertIn(abortedMsg, result.output)
65 # ...say yes
66 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="yes")
67 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
68 self.assertIn(willRemoveRunsMsg, result.output)
69 self.assertIn(willRemoveDatasetsMsg, result.output)
70 self.assertIn(removedRunsMsg, result.output)
72 # now they've been deleted, try again and check for "none found"
73 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"])
74 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
75 self.assertIn(noRunCollectionsMsg, result.output)
77 # remake the repo and check --no-confirm option
78 root = "repo1"
79 MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
81 # Execute cmd but say no, check for expected outputs.
82 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*", "--no-confirm"])
83 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
84 self.assertIn(didRemoveRunsMsg, result.output)
85 self.assertIn(didRemoveDatasetsMsg, result.output)
87 # Execute cmd looking for a non-existant collection
88 result = self.runner.invoke(butler.cli, ["remove-runs", root, "foo"])
89 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
90 self.assertIn(noRunCollectionsMsg, result.output)
93if __name__ == "__main__": 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true
94 unittest.main()