Coverage for tests/test_output.py: 35%
30 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-24 09:24 +0000
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-24 09:24 +0000
1# This file is part of verify.
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/>.
22import json
23import unittest
24import os
26import astropy.units as u
27from astropy.tests.helper import quantity_allclose
29import lsst.verify
32def load_json(filename):
33 with open(filename) as logfile:
34 json_doc = json.load(logfile)
35 return json_doc
38class OutputQuantitiesTestCase(unittest.TestCase):
40 def tearDown(self):
41 if hasattr(self, 'output_filename'):
42 if os.path.exists(self.output_filename):
43 os.remove(self.output_filename)
45 def test_output_quantities(self):
46 data = {'thing1': 10 * u.mmag,
47 'thing2': 5.2 * u.dimensionless_unscaled}
49 self.output_filename = lsst.verify.output_quantities(
50 'testing', data)
51 self.assertEqual(self.output_filename, 'testing.verify.json')
53 json_doc = load_json(self.output_filename)
54 self.assertEqual(len(json_doc['measurements']), 2)
55 self.assertEqual(len(json_doc['metrics']), 0)
56 self.assertEqual(len(json_doc['specs']), 0)
57 self.assertEqual(len(json_doc['blobs']), 0)
59 job = lsst.verify.Job.deserialize(**json_doc)
61 self.assertEqual(len(job.measurements), 2)
62 quantity_allclose(
63 job.measurements['testing.thing1'].quantity,
64 data['thing1'])
65 quantity_allclose(
66 job.measurements['testing.thing2'].quantity,
67 data['thing2'])
70if __name__ == "__main__": 70 ↛ 71line 70 didn't jump to line 71, because the condition on line 70 was never true
71 unittest.main()