Coverage for tests/test_timeMap.py: 21%
50 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:29 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:29 +0000
1import unittest
3import numpy as np
4from numpy.testing import assert_allclose
6import astshim as ast
7from astshim.test import MappingTestCase
9SecPerDay = 3600 * 24
12class TestTimeMap(MappingTestCase):
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)
22 self.checkCopy(timemap)
23 self.checkBasicSimplify(timemap)
25 indata = np.array([0.0, 1.0], dtype=float)
26 outdata = timemap.applyForward(indata)
27 assert_allclose(outdata, indata)
29 self.checkRoundTrip(timemap, indata)
30 self.checkMappingPersistence(timemap, indata)
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)
41 self.checkRoundTrip(timemap, indata)
42 self.checkMappingPersistence(timemap, indata)
44 def test_TimeMapAddInvalid(self):
45 timemap = ast.TimeMap()
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
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
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
66 with self.assertRaises(Exception):
67 timemap.timeadd("UNRECOGNIZED", [1])
70if __name__ == "__main__": 70 ↛ 71line 70 didn't jump to line 71, because the condition on line 70 was never true
71 unittest.main()