Coverage for tests/test_groups.py : 27%

Hot-keys 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)
41 sorted_group = ObservationGroup(sorted(obs_group))
42 self.assertIsInstance(sorted_group, ObservationGroup)
43 self.assertEqual(len(sorted_group), 3)
44 self.assertEqual(sorted_group[0], obs_group[1])
46 self.assertNotEqual(obs_group, sorted_group)
47 obs_group.sort()
48 self.assertEqual(obs_group, sorted_group)
49 obs_group.reverse()
50 self.assertEqual(obs_group[0], sorted_group[-1])
52 newest = obs_group.newest()
53 oldest = obs_group.oldest()
54 self.assertEqual(newest, sorted_group[-1])
55 self.assertEqual(oldest, sorted_group[0])
57 self.assertLess(oldest, newest)
58 self.assertGreater(newest, oldest)
60 self.assertNotEqual(oldest, obs_group)
62 # Add some headers and check that sorting still works
63 obs_group.extend(self._files_to_headers(self.hsc_files))
64 self.assertEqual(len(obs_group), 5)
65 self.assertEqual(obs_group.newest(), obs_group[3])
67 instruments = obs_group.property_values("instrument")
68 self.assertEqual(instruments, {"HSC", "DECam"})
70 def test_fits_group(self):
71 headers = self._files_to_headers(self.decam_files)
73 obs_group = ObservationGroup(headers)
74 cards, comments = group_to_fits(obs_group)
76 expected = {'INSTRUME': 'DECam',
77 'TIMESYS': 'TAI',
78 'DATE-OBS': '2012-12-11T22:07:07.859',
79 'MJD-OBS': 56272.92161874134,
80 'DATE-END': '2015-02-20T00:50:11.000',
81 'MJD-END': 57073.034849537034,
82 'DATE-AVG': '2014-01-15T23:28:39.430',
83 'MJD-AVG': 56672.97823413919}
84 self.assertEqual(cards, expected)
86 def test_fits_info(self):
87 header = self._files_to_headers(self.decam_files)[0]
88 obs_group = ObservationGroup([header])
89 cards, comments = info_to_fits(obs_group[0])
91 expected = {'INSTRUME': 'DECam',
92 'TIMESYS': 'TAI',
93 'MJD-AVG': 56536.25417681625,
94 'MJD-END': 56536.25591435185,
95 'MJD-OBS': 56536.25243928065,
96 'DATE-OBS': '2013-09-01T06:03:30.754',
97 'DATE-AVG': '2013-09-01T06:06:00.877',
98 'DATE-END': '2013-09-01T06:08:31.000'}
99 self.assertEqual(cards, expected)
102if __name__ == "__main__": 102 ↛ 103line 102 didn't jump to line 103, because the condition on line 102 was never true
103 unittest.main()