Coverage for tests/test_timeMap.py: 18%

50 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-14 01:55 -0800

1import unittest 

2 

3import numpy as np 

4from numpy.testing import assert_allclose 

5 

6import astshim as ast 

7from astshim.test import MappingTestCase 

8 

9SecPerDay = 3600 * 24 

10 

11 

12class TestTimeMap(MappingTestCase): 

13 

14 def test_TimeMapDefault(self): 

15 """Test a TimeMap with no conversions added 

16 """ 

17 timemap = ast.TimeMap() 

18 self.assertEqual(timemap.className, "TimeMap") 

19 self.assertEqual(timemap.nIn, 1) 

20 self.assertEqual(timemap.nOut, 1) 

21 

22 self.checkCopy(timemap) 

23 self.checkBasicSimplify(timemap) 

24 

25 indata = np.array([0.0, 1.0], dtype=float) 

26 outdata = timemap.applyForward(indata) 

27 assert_allclose(outdata, indata) 

28 

29 self.checkRoundTrip(timemap, indata) 

30 self.checkMappingPersistence(timemap, indata) 

31 

32 def test_TimeMapAddUTTOUTC(self): 

33 timemap = ast.TimeMap() 

34 dut1 = 0.35 

35 timemap.add("UTTOUTC", [dut1]) 

36 indata = np.array([512345.0, 512346.0], dtype=float) 

37 outdata = timemap.applyForward(indata) 

38 pred_outdata = (indata.T - dut1 / SecPerDay).T 

39 assert_allclose(outdata, pred_outdata, atol=1e-15, rtol=0) 

40 

41 self.checkRoundTrip(timemap, indata) 

42 self.checkMappingPersistence(timemap, indata) 

43 

44 def test_TimeMapAddInvalid(self): 

45 timemap = ast.TimeMap() 

46 

47 with self.assertRaises(Exception): 

48 timemap.add("BEPTOMJD", [560]) # too few arguments 

49 with self.assertRaises(Exception): 

50 timemap.add("BEPTOMJD", [560, 720, 33]) # too many arguments 

51 timemap.add("BEPTOMJD", [560, 720]) # just right 

52 

53 with self.assertRaises(Exception): 

54 timemap.add("UTCTOTAI", [560]) # just right 

55 with self.assertRaises(Exception): 

56 timemap.add("UTCTOTAI", [560, 720, 23]) # too many arguments 

57 timemap.add("UTCTOTAI", [560, 720]) # too many arguments 

58 

59 with self.assertRaises(Exception): 

60 timemap.add("TTTOTDB", [560, 720, 33, 53]) # too few arguments 

61 with self.assertRaises(Exception): 

62 # too many arguments 

63 timemap.add("TTTOTDB", [560, 720, 33, 53, 23, 10, 20]) 

64 timemap.add("TTTOTDB", [560, 720, 33, 53, 10]) # just right 

65 

66 with self.assertRaises(Exception): 

67 timemap.timeadd("UNRECOGNIZED", [1]) 

68 

69 

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

71 unittest.main()