Coverage for tests/test_cliCmdPurge.py: 31%
61 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-23 10:42 +0000
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-23 10:42 +0000
1# This file is part of ctrl_mpexec.
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 ctrl_mpexec CLI purge subcommand.
23"""
26import os
27import unittest
29from lsst.ctrl.mpexec.cli.pipetask import cli as pipetask_cli
30from lsst.daf.butler.cli.butler import cli as butler_cli
31from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg
32from lsst.daf.butler.tests.utils import MetricTestRepo, makeTestTempDir, removeTestTempDir
34TESTDIR = os.path.abspath(os.path.dirname(__file__))
37class PurgeTest(unittest.TestCase):
38 """Test executing "pipetask purge" commands."""
40 def setUp(self):
41 self.runner = LogCliRunner()
43 # this creates a repo with collections:
44 # Name Type
45 # ---------- ------
46 # ingest TAGGED
47 # ingest/run RUN
48 self.root = makeTestTempDir(TESTDIR)
49 self.testRepo = MetricTestRepo(
50 self.root,
51 configFile=os.path.join(TESTDIR, "config/metricTestRepoButler.yaml"),
52 )
54 def tearDown(self):
55 removeTestTempDir(self.root)
57 def test_singleChain_yesNo(self):
58 """Test removing a chain with one child, and the yes/no
59 confirmation."""
60 # add the collection ingest/run to a CHAINED collection called "in"
61 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "in", "ingest/run"])
62 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
64 # purge the CHAINED collection called "in", but say "no", check for
65 # expected outputs.
66 result = self.runner.invoke(pipetask_cli, ["purge", "-b", self.root, "in"], input="no")
67 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
68 self.assertIn("Will remove:\n runs: ingest/run\n chains: in\n others: \n", result.output)
69 self.assertIn("Aborted.", result.output)
71 # purge the CHAINED collection called "in", and say "yes", check for
72 # expected outputs.
73 result = self.runner.invoke(pipetask_cli, ["purge", "-b", self.root, "in"], input="yes")
74 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
75 self.assertIn("Will remove:\n runs: ingest/run\n chains: in\n others: \n", result.output)
76 self.assertIn("Done.", result.output)
78 def test_granparentChain_noConfirm(self):
79 """Test removing a chain with children and grandchildren, and the
80 --no-confirm option.
81 """
83 # add the collection ingest/run to a CHAINED collection called "ing"
84 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "ing", "ingest/run"])
85 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
87 # add the CHAINED collectin "ing" a CHAINED collection called "in"
88 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "in", "ing"])
89 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
91 # purge the CHAINED collection called "in" with --no-confirm and check
92 # for expected outputs.
93 result = self.runner.invoke(
94 pipetask_cli,
95 ["purge", "-b", self.root, "in", "--recursive", "--no-confirm"],
96 )
97 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
98 self.assertIn("Removed:\n runs: ingest/run\n chains: in, ing\n others: \n", result.output)
100 def test_topParentWithParent(self):
101 """Test that purging a chain with a parent fails."""
103 # add the collection ingest/run to a CHAINED collection called "ing"
104 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "ing", "ingest/run"])
105 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
107 # add the CHAINED collectin "ing" a CHAINED collection called "in"
108 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "in", "ing"])
109 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
111 # purge the CHAINED collection called "ing" and check for expected
112 # outputs.
113 result = self.runner.invoke(
114 pipetask_cli,
115 ["purge", "-b", self.root, "ing"],
116 )
117 self.assertEqual(result.exit_code, 1, clickResultMsg(result))
118 self.assertIn(
119 'The passed-in collection "ing" must not be contained in other collections but '
120 'is contained in collection(s) "in".',
121 result.output,
122 )
124 def test_childWithMultipleParents(self):
125 """Test that a child chain with multiple parents fails."""
126 # add the collection ingest/run to a CHAINED collection called "ing"
127 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "ing", "ingest/run"])
128 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
130 # add the collectin ingest/run to a CHAINED collection called "foo"
131 result = self.runner.invoke(butler_cli, ["collection-chain", self.root, "foo", "ingest/run"])
132 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
134 # purge the CHAINED collection called "ing" and check for expected
135 # outputs.
136 result = self.runner.invoke(
137 pipetask_cli,
138 ["purge", "-b", self.root, "ing"],
139 )
140 self.assertEqual(result.exit_code, 1, clickResultMsg(result))
141 self.assertIn(
142 'Collection "ingest/run" is in multiple chained collections:',
143 result.output,
144 )
145 self.assertIn('"foo"', result.output)
146 self.assertIn('"ing"', result.output)
148 def test_notFound_notChained(self):
149 """Test for failure when the top level collection is not found,
150 and when a top level connection is not a CHAINED collection.
151 """
152 # Test purging a collection that does not exist.
153 result = self.runner.invoke(
154 pipetask_cli,
155 ["purge", "-b", self.root, "notACollection"],
156 )
157 self.assertEqual(result.exit_code, 1, clickResultMsg(result))
158 self.assertIn(
159 'The passed-in colleciton "notACollection" was not found.',
160 result.output,
161 )
163 # Test purging a colleciton that is not a CHAINED collection.
164 result = self.runner.invoke(
165 pipetask_cli,
166 ["purge", "-b", self.root, "ingest/run"],
167 )
168 self.assertEqual(result.exit_code, 1, clickResultMsg(result))
169 self.assertIn(
170 "The passed-in collection must be a CHAINED collection; " '"ingest/run" is a RUN collection.',
171 result.output,
172 )
175if __name__ == "__main__": 175 ↛ 176line 175 didn't jump to line 176, because the condition on line 175 was never true
176 unittest.main()