Coverage for tests/test_reports.py: 13%

74 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-11 10:59 +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# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import unittest 

23 

24from lsst.ctrl.mpexec import ExecutionStatus, QuantumReport, Report 

25 

26 

27class ReportsTestCase(unittest.TestCase): 

28 """A test case for reports module""" 

29 

30 def test_quantumReport(self): 

31 """Test for QuantumReport class""" 

32 

33 dataId = {"instrument": "LSST"} 

34 taskLabel = "task" 

35 

36 qr = QuantumReport(dataId=dataId, taskLabel=taskLabel) 

37 self.assertEqual(qr.status, ExecutionStatus.SUCCESS) 

38 self.assertEqual(qr.dataId, dataId) 

39 self.assertEqual(qr.taskLabel, taskLabel) 

40 self.assertIsNone(qr.exitCode) 

41 self.assertIsNone(qr.exceptionInfo) 

42 

43 qr = QuantumReport(status=ExecutionStatus.TIMEOUT, dataId=dataId, taskLabel=taskLabel) 

44 self.assertEqual(qr.status, ExecutionStatus.TIMEOUT) 

45 

46 qr = QuantumReport.from_exception( 

47 exception=RuntimeError("runtime error"), dataId=dataId, taskLabel=taskLabel 

48 ) 

49 self.assertEqual(qr.status, ExecutionStatus.FAILURE) 

50 self.assertEqual(qr.dataId, dataId) 

51 self.assertEqual(qr.taskLabel, taskLabel) 

52 self.assertIsNone(qr.exitCode) 

53 self.assertEqual(qr.exceptionInfo.className, "RuntimeError") 

54 self.assertEqual(qr.exceptionInfo.message, "runtime error") 

55 

56 qr = QuantumReport.from_exit_code(exitCode=0, dataId=dataId, taskLabel=taskLabel) 

57 self.assertEqual(qr.status, ExecutionStatus.SUCCESS) 

58 self.assertEqual(qr.dataId, dataId) 

59 self.assertEqual(qr.taskLabel, taskLabel) 

60 self.assertEqual(qr.exitCode, 0) 

61 self.assertIsNone(qr.exceptionInfo) 

62 

63 qr = QuantumReport.from_exit_code(exitCode=1, dataId=dataId, taskLabel=taskLabel) 

64 self.assertEqual(qr.status, ExecutionStatus.FAILURE) 

65 self.assertEqual(qr.dataId, dataId) 

66 self.assertEqual(qr.taskLabel, taskLabel) 

67 self.assertEqual(qr.exitCode, 1) 

68 self.assertIsNone(qr.exceptionInfo) 

69 

70 def test_report(self): 

71 """Test for Report class""" 

72 

73 report = Report() 

74 self.assertEqual(report.status, ExecutionStatus.SUCCESS) 

75 self.assertIsNotNone(report.cmdLine) 

76 self.assertIsNone(report.exitCode) 

77 self.assertIsNone(report.exceptionInfo) 

78 

79 dataId = {"instrument": "LSST"} 

80 taskLabel = "task" 

81 

82 qr = QuantumReport.from_exception( 

83 exception=RuntimeError("runtime error"), dataId=dataId, taskLabel=taskLabel 

84 ) 

85 report = Report(status=ExecutionStatus.FAILURE, exitCode=-1) 

86 report.set_exception(RuntimeError("runtime error")) 

87 report.quantaReports.append(qr) 

88 self.assertEqual(report.status, ExecutionStatus.FAILURE) 

89 self.assertEqual(report.exitCode, -1) 

90 self.assertEqual(report.exceptionInfo.className, "RuntimeError") 

91 self.assertEqual(report.exceptionInfo.message, "runtime error") 

92 self.assertEqual(len(report.quantaReports), 1) 

93 

94 def test_json(self): 

95 """Test for conversion to/from json""" 

96 

97 dataId = {"instrument": "LSST"} 

98 taskLabel = "task" 

99 

100 qr = QuantumReport.from_exception( 

101 exception=RuntimeError("runtime error"), dataId=dataId, taskLabel=taskLabel 

102 ) 

103 report = Report(status=ExecutionStatus.FAILURE, exitCode=-1) 

104 report.set_exception(RuntimeError("runtime error")) 

105 report.quantaReports.append(qr) 

106 json = report.json(exclude_none=True, indent=2) 

107 self.assertIsInstance(json, str) 

108 

109 report = Report.parse_raw(json) 

110 self.assertEqual(report.status, ExecutionStatus.FAILURE) 

111 self.assertEqual(report.exitCode, -1) 

112 self.assertEqual(report.exceptionInfo.className, "RuntimeError") 

113 self.assertEqual(report.exceptionInfo.message, "runtime error") 

114 self.assertEqual(len(report.quantaReports), 1) 

115 qr = report.quantaReports[0] 

116 self.assertEqual(qr.status, ExecutionStatus.FAILURE) 

117 self.assertEqual(qr.dataId, dataId) 

118 self.assertEqual(qr.taskLabel, taskLabel) 

119 self.assertIsNone(qr.exitCode) 

120 self.assertEqual(qr.exceptionInfo.className, "RuntimeError") 

121 self.assertEqual(qr.exceptionInfo.message, "runtime error") 

122 

123 

124if __name__ == "__main__": 124 ↛ 125line 124 didn't jump to line 125, because the condition on line 124 was never true

125 unittest.main()