Coverage for tests/test_load_json.py: 29%
44 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
1#
2# LSST Data Management System
3# Copyright 2012-2016 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
24import os
25import unittest
27import lsst.utils
29from lsst.utils.tests import ExecutablesTestCase
30from lsst.validate.drp.validate import (
31 get_filter_name_from_job, load_json_output, plot_metrics, print_metrics)
34class ParseJsonJob(ExecutablesTestCase):
35 """Testing loading of JSON cache files."""
37 def setUp(self):
38 testDataDir = os.path.dirname(__file__)
39 self.jsonFile = os.path.join(testDataDir, 'CfhtQuick_output_r.json')
40 self.jsonFile_filter = 'r'
41 self.longMessage = True
42 self.executable_dir = os.path.join(lsst.utils.getPackageDir("VALIDATE_DRP"),
43 "bin")
45 def testLoadFromValidate(self):
46 self.assertExecutable("validateDrp.py",
47 root_dir=self.executable_dir,
48 args=[self.jsonFile, "--noplot"],
49 msg="CFHT Quick Test failed")
51 def testLoadJsonJob(self):
52 """Can we load a Job from a JSON file?"""
54 # without throwing an error
55 job = load_json_output(self.jsonFile)
56 # Spot-check a few attributes
57 self.assertEqual(len(job.measurements), 42)
59 def testParseJobFilterName(self):
60 """Do we correctly read the filterName from a Job object?"""
61 job = load_json_output(self.jsonFile)
62 filterName = get_filter_name_from_job(job)
63 self.assertEqual(filterName, self.jsonFile_filter)
65 def testPrintMetricsFromJsonJob(self):
66 """Does printing the metrics run without error using itself?
68 This is in essence half the big test.
69 If we load a file do we get printed metrics?
70 Next TODO is to actually check for the values printed.
71 """
72 job = load_json_output(self.jsonFile)
73 filterName = get_filter_name_from_job(job)
74 print_metrics(job, filterName)
76 def testPlotMetricsFromJsonJob(self):
77 """Does plotting the metrics run and produce the correct filenames?
79 This could be loosely seen as a test of the outputPrefix handling
80 and thus DM-11410, it's a rather incomplete one because the chain
81 of wrapping functions is different.
82 """
83 job = load_json_output(self.jsonFile)
84 filterName = get_filter_name_from_job(job)
86 noOutputPrefixFiles = ['check_astrometry.png',
87 'check_photometry.png',
88 'PA1.png',
89 'validate_drp.AM1_D_5_arcmin_17.0_21.5_mag.png',
90 'validate_drp.TE1_D_1_arcmin.png',
91 'validate_drp.TE2_D_5_arcmin.png']
92 # test with no output prefix.
93 plot_metrics(job, filterName)
94 for filename in noOutputPrefixFiles:
95 assert os.path.exists(filename), "File not created: %s"%filename
96 os.remove(filename)
98 # test that outputPrefix is prepended correctly.
99 outputPrefix = 'foobarbaz'
100 outputPrefixFiles = ['%s_%s' % (outputPrefix, f) for f in noOutputPrefixFiles]
101 plot_metrics(job, filterName, outputPrefix=outputPrefix)
102 for filename in outputPrefixFiles:
103 assert os.path.exists(filename), "File not created: %s"%filename
104 os.remove(filename)
107def setup_module(module):
108 lsst.utils.tests.init()
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112, because the condition on line 111 was never true
112 lsst.utils.tests.init()
113 unittest.main()