Coverage for tests / test_cliCmdUpdateGraphRun.py: 46%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-22 08:58 +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 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/>. 

27 

28"""Unit tests for ctrl_mpexec CLI update-graph-run subcommand.""" 

29 

30import os 

31import unittest 

32 

33from lsst.ctrl.mpexec.cli.pipetask import cli as pipetask_cli 

34from lsst.daf.butler.cli.utils import LogCliRunner, clickResultMsg 

35from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir 

36from lsst.pipe.base.quantum_graph import PredictedQuantumGraph 

37from lsst.pipe.base.tests.mocks import InMemoryRepo 

38 

39TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

40 

41 

42class UpdateGraphRunTest(unittest.TestCase): 

43 """Test executing "pipetask update-graph-run" commands.""" 

44 

45 instrument = "lsst.pipe.base.tests.simpleQGraph.SimpleInstrument" 

46 

47 def setUp(self) -> None: 

48 self.runner = LogCliRunner() 

49 self.root = makeTestTempDir(TESTDIR) 

50 

51 def tearDown(self) -> None: 

52 removeTestTempDir(self.root) 

53 

54 def test_update(self): 

55 """Test for updating output run in a graph.""" 

56 helper = InMemoryRepo() 

57 self.enterContext(helper) 

58 helper.add_task() 

59 helper.add_task() 

60 qgc = helper.make_quantum_graph_builder().finish(attach_datastore_records=False) 

61 old_path = os.path.join(self.root, "graph.qg") 

62 qgc.write(old_path) 

63 new_path = os.path.join(self.root, "graph-updated.qg") 

64 result = self.runner.invoke( 

65 pipetask_cli, 

66 ["update-graph-run", old_path, "new-run", new_path], 

67 input="no", 

68 ) 

69 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

70 with PredictedQuantumGraph.open(new_path) as reader: 

71 # Don't need to check the details; those are covered by pipe_base 

72 # tests. 

73 self.assertEqual(reader.components.header.output_run, "new-run") 

74 

75 

76if __name__ == "__main__": 

77 unittest.main()