Coverage for tests/test_basics.py: 33%
31 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-08-01 01:03 -0700
« prev ^ index » next coverage.py v6.4.2, created at 2022-08-01 01:03 -0700
1# This file is part of astro_metadata_translator.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the LICENSE file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12import unittest
14import astropy.time
15import astropy.units as u
17import astro_metadata_translator
18from astro_metadata_translator import ObservationInfo, makeObservationInfo
21class BasicTestCase(unittest.TestCase):
22 def test_basic(self):
23 version = astro_metadata_translator.__version__
24 self.assertIsNotNone(version)
26 def test_obsinfo(self):
27 """Test construction of ObservationInfo without header."""
28 obsinfo = makeObservationInfo(boresight_airmass=1.5, tracking_radec=None)
29 self.assertIsInstance(obsinfo, ObservationInfo)
30 self.assertIsNone(obsinfo.tracking_radec)
31 self.assertAlmostEqual(obsinfo.boresight_airmass, 1.5)
32 self.assertIsNone(obsinfo.observation_id)
33 self.assertEqual(obsinfo.cards_used, set())
34 self.assertEqual(obsinfo.stripped_header(), {})
36 with self.assertRaises(TypeError):
37 ObservationInfo.makeObservationInfo(boresight_airmass=1.5, observation_id=5)
39 with self.assertRaises(KeyError):
40 obsinfo = ObservationInfo.makeObservationInfo(unrecognized=1.5, keys="unknown")
42 def test_simple(self):
43 """Test that we can simplify an ObservationInfo."""
45 reference = dict(
46 boresight_airmass=1.5,
47 focus_z=1.0 * u.mm,
48 temperature=15 * u.deg_C,
49 observation_type="bias",
50 exposure_time=5 * u.ks,
51 detector_num=32,
52 datetime_begin=astropy.time.Time("2021-02-15T12:00:00", format="isot", scale="utc"),
53 )
55 obsinfo = makeObservationInfo(**reference)
56 simple = obsinfo.to_simple()
57 newinfo = ObservationInfo.from_simple(simple)
58 self.assertEqual(obsinfo, newinfo)
60 via_json = ObservationInfo.from_json(newinfo.to_json())
61 self.assertEqual(via_json, obsinfo)
64if __name__ == "__main__": 64 ↛ 65line 64 didn't jump to line 65, because the condition on line 64 was never true
65 unittest.main()