Coverage for tests/test_groups.py: 25%
55 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-22 03:09 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-22 03:09 -0800
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 os.path
13import unittest
15from astro_metadata_translator import ObservationGroup
16from astro_metadata_translator.serialize import group_to_fits, info_to_fits
17from astro_metadata_translator.tests import read_test_file
19TESTDIR = os.path.abspath(os.path.dirname(__file__))
22class ObservationGroupTestCase(unittest.TestCase):
23 datadir = os.path.join(TESTDIR, "data")
25 def setUp(self):
26 self.decam_files = (
27 "fitsheader-decam.yaml",
28 "fitsheader-decam-0160496.yaml",
29 "fitsheader-decam-calexp-0412037_10.yaml",
30 )
31 self.hsc_files = ("fitsheader-hsc-HSCA04090107.yaml", "fitsheader-hsc.yaml")
33 def _files_to_headers(self, files):
34 return [read_test_file(os.path.join(self.datadir, f)) for f in files]
36 def test_groups(self):
37 headers = self._files_to_headers(self.decam_files)
39 obs_group = ObservationGroup(headers)
40 self.assertEqual(len(obs_group), 3)
41 self.assertEqual(
42 str(obs_group),
43 "[(DECam, 2013-09-01T06:02:55.754), (DECam, 2012-12-11T22:06:32.859),"
44 " (DECam, 2015-02-20T00:47:21.127)]",
45 )
47 sorted_group = ObservationGroup(sorted(obs_group))
48 self.assertIsInstance(sorted_group, ObservationGroup)
49 self.assertEqual(len(sorted_group), 3)
50 self.assertEqual(sorted_group[0], obs_group[1])
52 self.assertNotEqual(obs_group, sorted_group)
53 obs_group.sort()
54 self.assertEqual(obs_group, sorted_group)
55 obs_group.reverse()
56 self.assertEqual(obs_group[0], sorted_group[-1])
58 newest = obs_group.newest()
59 oldest = obs_group.oldest()
60 self.assertEqual(newest, sorted_group[-1])
61 self.assertEqual(oldest, sorted_group[0])
63 self.assertLess(oldest, newest)
64 self.assertGreater(newest, oldest)
66 self.assertNotEqual(oldest, obs_group)
67 self.assertNotEqual(obs_group, oldest)
69 # Add some headers and check that sorting still works
70 obs_group.extend(self._files_to_headers(self.hsc_files))
71 self.assertEqual(len(obs_group), 5)
72 self.assertEqual(obs_group.newest(), obs_group[3])
74 instruments = obs_group.property_values("instrument")
75 self.assertEqual(instruments, {"HSC", "DECam"})
77 # Check that simplified form round trips
78 self.assertEqual(ObservationGroup.from_simple(obs_group.to_simple()), obs_group)
80 def test_fits_group(self):
81 headers = self._files_to_headers(self.decam_files)
83 obs_group = ObservationGroup(headers)
84 cards, comments = group_to_fits(obs_group)
86 expected = {
87 "INSTRUME": "DECam",
88 "TIMESYS": "TAI",
89 "DATE-OBS": "2012-12-11T22:07:07.859",
90 "MJD-OBS": 56272.92161874134,
91 "DATE-END": "2015-02-20T00:50:11.000",
92 "MJD-END": 57073.034849537034,
93 "DATE-AVG": "2014-01-15T23:28:39.430",
94 "MJD-AVG": 56672.97823413919,
95 }
96 self.assertEqual(cards, expected)
98 def test_fits_info(self):
99 header = self._files_to_headers(self.decam_files)[0]
100 obs_group = ObservationGroup([header])
101 cards, comments = info_to_fits(obs_group[0])
103 expected = {
104 "INSTRUME": "DECam",
105 "TIMESYS": "TAI",
106 "MJD-AVG": 56536.25417681625,
107 "MJD-END": 56536.25591435185,
108 "MJD-OBS": 56536.25243928065,
109 "DATE-OBS": "2013-09-01T06:03:30.754",
110 "DATE-AVG": "2013-09-01T06:06:00.877",
111 "DATE-END": "2013-09-01T06:08:31.000",
112 }
113 self.assertEqual(cards, expected)
116if __name__ == "__main__": 116 ↛ 117line 116 didn't jump to line 117, because the condition on line 116 was never true
117 unittest.main()