Coverage for tests/test_report_from_json.py: 30%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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/>.
22import os
23import tempfile
24import unittest
26import lsst.utils
27from lsst.validate.drp import report_performance
30class ReportPerformanceFromJob(unittest.TestCase):
31 """Testing release performance summary."""
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'
44 def test_generate_report_from_json(self):
45 """Can we read in JSON results and make a report.
47 Reference datasets are from a v13.0 validation_data_hsc run.
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()
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)
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)
79 # Cleanup our temp directory
80 os.removedirs(tmp_dir)
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()