Coverage for tests/test_basics.py: 30%

31 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-20 10:39 +0000

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 """Test basic metadata translation functionality.""" 

23 

24 def test_basic(self): 

25 version = astro_metadata_translator.__version__ 

26 self.assertIsNotNone(version) 

27 

28 def test_obsinfo(self): 

29 """Test construction of ObservationInfo without header.""" 

30 obsinfo = makeObservationInfo(boresight_airmass=1.5, tracking_radec=None) 

31 self.assertIsInstance(obsinfo, ObservationInfo) 

32 self.assertIsNone(obsinfo.tracking_radec) 

33 self.assertAlmostEqual(obsinfo.boresight_airmass, 1.5) 

34 self.assertIsNone(obsinfo.observation_id) 

35 self.assertEqual(obsinfo.cards_used, set()) 

36 self.assertEqual(obsinfo.stripped_header(), {}) 

37 

38 with self.assertRaises(TypeError): 

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

40 

41 with self.assertRaises(KeyError): 

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

43 

44 def test_simple(self): 

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

46 reference = dict( 

47 boresight_airmass=1.5, 

48 focus_z=1.0 * u.mm, 

49 temperature=15 * u.deg_C, 

50 observation_type="bias", 

51 exposure_time=5 * u.ks, 

52 detector_num=32, 

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

54 ) 

55 

56 obsinfo = makeObservationInfo(**reference) 

57 simple = obsinfo.to_simple() 

58 newinfo = ObservationInfo.from_simple(simple) 

59 self.assertEqual(obsinfo, newinfo) 

60 

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

62 self.assertEqual(via_json, obsinfo) 

63 

64 

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

66 unittest.main()