Coverage for tests/test_cliCmdQgraph.py: 45%

27 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-07 02:50 -0700

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 qgraph subcommand.""" 

29 

30import os 

31import unittest 

32 

33from lsst.ctrl.mpexec import Report 

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

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

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

37from lsst.pipe.base.tests.simpleQGraph import makeSimpleQGraph 

38 

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

40 

41 

42class QgraphTest(unittest.TestCase): 

43 """Test executing "pipetask qgraph" command.""" 

44 

45 def setUp(self) -> None: 

46 self.runner = LogCliRunner() 

47 self.root = makeTestTempDir(TESTDIR) 

48 

49 def tearDown(self) -> None: 

50 removeTestTempDir(self.root) 

51 

52 def test_qgraph_summary(self): 

53 """Test for making a summary of a QuantumGraph.""" 

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

55 butler, qgraph = makeSimpleQGraph( 

56 run="run", 

57 root=self.root, 

58 metadata=metadata, 

59 ) 

60 

61 graph_uri = os.path.join(self.root, "graph.qgraph") 

62 qgraph.saveUri(graph_uri) 

63 

64 test_filename = os.path.join(self.root, "summary.json") 

65 

66 result = self.runner.invoke( 

67 pipetask_cli, 

68 ["qgraph", "--butler-config", self.root, "--qgraph", graph_uri, "--summary", test_filename], 

69 input="no", 

70 ) 

71 # Check that we can read from the command line 

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

73 

74 # Check that we can open and read the file produced by make_reports 

75 with open(test_filename) as f: 

76 summary = Report.model_validate_json(f.read()) 

77 self.assertEqual(summary.qgraphSummary.outputRun, "run") 

78 self.assertEqual(len(summary.qgraphSummary.qgraphTaskSummaries), 5) 

79 

80 

81if __name__ == "__main__": 

82 unittest.main()