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