Coverage for tests/test_cliCmdUpdateGraphRun.py: 35%

43 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-01 09:30 +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/>. 

21 

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

23 

24import os 

25import unittest 

26 

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 

33 

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

35 

36 

37class UpdateGraphRunTest(unittest.TestCase): 

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

39 

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

41 

42 def setUp(self) -> None: 

43 self.runner = LogCliRunner() 

44 self.root = makeTestTempDir(TESTDIR) 

45 

46 def tearDown(self) -> None: 

47 removeTestTempDir(self.root) 

48 

49 def test_update(self): 

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

51 nQuanta = 3 

52 metadata = {"output_run": "run"} 

53 _, qgraph = makeSimpleQGraph( 

54 nQuanta, 

55 run="run", 

56 root=self.root, 

57 instrument=self.instrument, 

58 metadata=metadata, 

59 ) 

60 self.assertEqual(check_output_run(qgraph, "run"), []) 

61 

62 old_path = os.path.join(self.root, "graph.qgraph") 

63 qgraph.saveUri(old_path) 

64 

65 new_path = os.path.join(self.root, "graph-updated.qgraph") 

66 result = self.runner.invoke( 

67 pipetask_cli, 

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

69 input="no", 

70 ) 

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

72 

73 updated_graph = QuantumGraph.loadUri(new_path) 

74 self.assertEqual(check_output_run(updated_graph, "new-run"), []) 

75 assert updated_graph.metadata is not None 

76 self.assertEqual(updated_graph.metadata["output_run"], "new-run") 

77 self.assertEqual(updated_graph.graphID, qgraph.graphID) 

78 

79 # Check that we can turn off metadata updates. 

80 result = self.runner.invoke( 

81 pipetask_cli, 

82 ["update-graph-run", "--metadata-run-key=''", old_path, "new-run2", new_path], 

83 input="no", 

84 ) 

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

86 

87 updated_graph = QuantumGraph.loadUri(new_path) 

88 self.assertEqual(check_output_run(updated_graph, "new-run2"), []) 

89 assert updated_graph.metadata is not None 

90 self.assertEqual(updated_graph.metadata["output_run"], "run") 

91 

92 # Now check that we can make new graph ID. 

93 result = self.runner.invoke( 

94 pipetask_cli, 

95 ["update-graph-run", "--update-graph-id", old_path, "new-run3", new_path], 

96 input="no", 

97 ) 

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

99 

100 updated_graph = QuantumGraph.loadUri(new_path) 

101 self.assertEqual(check_output_run(updated_graph, "new-run3"), []) 

102 self.assertNotEqual(updated_graph.graphID, qgraph.graphID) 

103 

104 

105if __name__ == "__main__": 

106 unittest.main()