Coverage for tests/test_report_from_json.py: 26%

32 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-05 19:03 -0800

1# LSST Data Management System 

2# Copyright 2017 AURA/LSST. 

3# 

4# This product includes software developed by the 

5# LSST Project (http://www.lsst.org/). 

6# 

7# This program is free software: you can redistribute it and/or modify 

8# it under the terms of the GNU General Public License as published by 

9# the Free Software Foundation, either version 3 of the License, or 

10# (at your option) any later version. 

11# 

12# This program is distributed in the hope that it will be useful, 

13# but WITHOUT ANY WARRANTY; without even the implied warranty of 

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU General Public License for more details. 

16# 

17# You should have received a copy of the LSST License Statement and 

18# the GNU General Public License along with this program. If not, 

19# see <https://www.lsstcorp.org/LegalNotices/>. 

20 

21 

22import os 

23import tempfile 

24import unittest 

25 

26import lsst.utils 

27from lsst.validate.drp import report_performance 

28 

29 

30class ReportPerformanceFromJob(unittest.TestCase): 

31 """Testing release performance summary.""" 

32 

33 def setUp(self): 

34 test_data_dir = os.path.dirname(__file__) 

35 self.release_specs_package = 'verify_metrics' 

36 self.srd_levels = ['design', 'minimum'] 

37 self.release_levels = ['FY17', 'FY18'] 

38 self.report_files = [os.path.join(test_data_dir, f) for f in 

39 ['CfhtQuick_output_r_report_{}_{}.rst'.format(s, r) 

40 for s, r in zip(self.srd_levels, self.release_levels)]] 

41 self.json_file = os.path.join(test_data_dir, 'CfhtQuick_output_r.json') 

42 self.json_file_filter = 'r' 

43 

44 def test_generate_report_from_json(self): 

45 """Can we read in JSON results and make a report. 

46 

47 Reference datasets are from a v13.0 validation_data_hsc run. 

48 

49 Check for the default (srd_level, release_level) = ('design', 'FY17') and ('minimum', 'FY18') 

50 """ 

51 # Manually use temporary directories here, 

52 # because I can't figure out how to get py.test tmpdir fixture 

53 # to work in the unittest.TestCase context. 

54 tmp_dir = tempfile.mkdtemp() 

55 

56 srd_release_report = zip(self.srd_levels, self.release_levels, self.report_files) 

57 for srd_level, release_level, ref_file in srd_release_report: 

58 out_file_name = os.path.join( 

59 tmp_dir, 

60 "report_performance_test_{}_{}.rst".format(srd_level, release_level)) 

61 report_performance.run( 

62 [self.json_file], 

63 out_file_name, 

64 srd_level=srd_level, 

65 release_specs_package='verify_metrics', 

66 release_level=release_level) 

67 

68 assert(os.path.exists(out_file_name)) 

69 with open(out_file_name) as fh: 

70 of_lines = fh.readlines() 

71 with open(ref_file) as fh: 

72 rf_lines = fh.readlines() 

73 self.maxDiff = None 

74 self.assertEqual(''.join(of_lines), ''.join(rf_lines), 

75 msg=f"Files are {out_file_name} and {ref_file}") 

76 # Cleanup our temp file 

77 os.remove(out_file_name) 

78 

79 # Cleanup our temp directory 

80 os.removedirs(tmp_dir) 

81 

82 

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

84 lsst.utils.tests.init() 

85 unittest.main()