Coverage for tests/test_basics.py: 37%

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

31 statements  

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. 

11 

12import unittest 

13 

14import astropy.time 

15import astropy.units as u 

16 

17import astro_metadata_translator 

18from astro_metadata_translator import ObservationInfo, makeObservationInfo 

19 

20 

21class BasicTestCase(unittest.TestCase): 

22 def test_basic(self): 

23 version = astro_metadata_translator.__version__ 

24 self.assertIsNotNone(version) 

25 

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(), {}) 

35 

36 with self.assertRaises(TypeError): 

37 ObservationInfo.makeObservationInfo(boresight_airmass=1.5, observation_id=5) 

38 

39 with self.assertRaises(KeyError): 

40 obsinfo = ObservationInfo.makeObservationInfo(unrecognized=1.5, keys="unknown") 

41 

42 def test_simple(self): 

43 """Test that we can simplify an ObservationInfo.""" 

44 

45 reference = dict( 

46 boresight_airmass=1.5, 

47 temperature=15 * u.deg_C, 

48 observation_type="bias", 

49 exposure_time=5 * u.ks, 

50 detector_num=32, 

51 datetime_begin=astropy.time.Time("2021-02-15T12:00:00", format="isot", scale="utc"), 

52 ) 

53 

54 obsinfo = makeObservationInfo(**reference) 

55 simple = obsinfo.to_simple() 

56 newinfo = ObservationInfo.from_simple(simple) 

57 self.assertEqual(obsinfo, newinfo) 

58 

59 via_json = ObservationInfo.from_json(newinfo.to_json()) 

60 self.assertEqual(via_json, obsinfo) 

61 

62 

63if __name__ == "__main__": 63 ↛ 64line 63 didn't jump to line 64, because the condition on line 63 was never true

64 unittest.main()