Coverage for tests/test_cliCmdUpdateGraphRun.py: 35%
43 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-28 10:40 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-28 10:40 +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 update-graph-run subcommand."""
24import os
25import unittest
27from lsst.ctrl.mpexec.cli.pipetask import cli as pipetask_cli
28from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg
29from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir
30from lsst.pipe.base import QuantumGraph
31from lsst.pipe.base.tests.simpleQGraph import makeSimpleQGraph
32from lsst.pipe.base.tests.util import check_output_run
34TESTDIR = os.path.abspath(os.path.dirname(__file__))
37class UpdateGraphRunTest(unittest.TestCase):
38 """Test executing "pipetask update-graph-run" commands."""
40 instrument = "lsst.pipe.base.tests.simpleQGraph.SimpleInstrument"
42 def setUp(self) -> None:
43 self.runner = LogCliRunner()
44 self.root = makeTestTempDir(TESTDIR)
46 def tearDown(self) -> None:
47 removeTestTempDir(self.root)
49 def test_update(self):
50 """Test for updating output run in a graph."""
52 nQuanta = 3
53 metadata = {"output_run": "run"}
54 _, qgraph = makeSimpleQGraph(
55 nQuanta,
56 run="run",
57 root=self.root,
58 instrument=self.instrument,
59 metadata=metadata,
60 )
61 self.assertEqual(check_output_run(qgraph, "run"), [])
63 old_path = os.path.join(self.root, "graph.qgraph")
64 qgraph.saveUri(old_path)
66 new_path = os.path.join(self.root, "graph-updated.qgraph")
67 result = self.runner.invoke(
68 pipetask_cli,
69 ["update-graph-run", old_path, "new-run", new_path],
70 input="no",
71 )
72 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
74 updated_graph = QuantumGraph.loadUri(new_path)
75 self.assertEqual(check_output_run(updated_graph, "new-run"), [])
76 assert updated_graph.metadata is not None
77 self.assertEqual(updated_graph.metadata["output_run"], "new-run")
78 self.assertEqual(updated_graph.graphID, qgraph.graphID)
80 # Check that we can turn off metadata updates.
81 result = self.runner.invoke(
82 pipetask_cli,
83 ["update-graph-run", "--metadata-run-key=''", old_path, "new-run2", new_path],
84 input="no",
85 )
86 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
88 updated_graph = QuantumGraph.loadUri(new_path)
89 self.assertEqual(check_output_run(updated_graph, "new-run2"), [])
90 assert updated_graph.metadata is not None
91 self.assertEqual(updated_graph.metadata["output_run"], "run")
93 # Now check that we can make new graph ID.
94 result = self.runner.invoke(
95 pipetask_cli,
96 ["update-graph-run", "--update-graph-id", old_path, "new-run3", new_path],
97 input="no",
98 )
99 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
101 updated_graph = QuantumGraph.loadUri(new_path)
102 self.assertEqual(check_output_run(updated_graph, "new-run3"), [])
103 self.assertNotEqual(updated_graph.graphID, qgraph.graphID)
106if __name__ == "__main__":
107 unittest.main()