Coverage for tests/testScheduledDowntimeData.py : 33%

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
1import os
2import sqlite3
3import unittest
4from astropy.time import Time, TimeDelta
5from lsst.utils import getPackageDir
6import lsst.utils.tests
7from lsst.utils.tests import getTempFilePath
9from lsst.sims.downtimeModel import ScheduledDowntimeData
12class ScheduledDowntimeDataTest(unittest.TestCase):
14 def setUp(self):
15 self.th = Time('2020-01-01', format='isot', scale='tai')
16 self.startofnight = -0.34
17 self.downtime_db = os.path.join(getPackageDir('sims_downtimeModel'), 'data', 'scheduled_downtime.db')
19 def test_basic_information_after_creation(self):
20 downtimeData = ScheduledDowntimeData(self.th, start_of_night_offset=self.startofnight)
21 self.assertEqual(downtimeData.scheduled_downtime_db, self.downtime_db)
22 self.assertEqual(self.th + TimeDelta(self.startofnight, format='jd'), downtimeData.night0)
23 downtimeData = ScheduledDowntimeData(self.th, start_of_night_offset=0)
24 self.assertEqual(downtimeData.night0, self.th)
26 def test_information_after_initialization(self):
27 downtimeData = ScheduledDowntimeData(self.th, start_of_night_offset=self.startofnight)
28 downtimeData.read_data()
29 self.assertEqual(len(downtimeData.downtime), 31)
30 # Check some of the downtime values.
31 dnight = downtimeData.downtime['end'] - downtimeData.downtime['start']
32 self.assertEqual(dnight[0].jd, 7)
33 self.assertEqual(downtimeData.downtime['activity'][0], 'general maintenance')
34 self.assertEqual(dnight[4].jd, 14)
35 self.assertEqual(downtimeData.downtime['activity'][4], 'recoat mirror')
37 def test_alternate_db(self):
38 with getTempFilePath('.alt_downtime.db') as tmpdb:
39 downtime_table = []
40 downtime_table.append("night INTEGER PRIMARY KEY")
41 downtime_table.append("duration INTEGER")
42 downtime_table.append("activity TEXT")
44 with sqlite3.connect(tmpdb) as conn:
45 cur = conn.cursor()
46 cur.execute("DROP TABLE IF EXISTS Downtime")
47 cur.execute("CREATE TABLE Downtime({})".format(",".join(downtime_table)))
48 cur.execute("INSERT INTO Downtime VALUES(?, ?, ?)", (100, 7, "something to do"))
49 cur.close()
51 downtimeData = ScheduledDowntimeData(self.th,
52 scheduled_downtime_db=tmpdb,
53 start_of_night_offset = self.startofnight)
54 downtimeData.read_data()
55 self.assertEqual(len(downtimeData.downtime), 1)
56 self.assertEqual(downtimeData.downtime['activity'][0], 'something to do')
58 def test_call(self):
59 downtimeData = ScheduledDowntimeData(self.th, start_of_night_offset=self.startofnight)
60 downtimeData.read_data()
61 downtimes = downtimeData()
62 self.assertEqual(downtimes['activity'][4], 'recoat mirror')
65class TestMemory(lsst.utils.tests.MemoryTestCase):
66 pass
68def setup_module(module):
69 lsst.utils.tests.init()
71if __name__ == "__main__": 71 ↛ 72line 71 didn't jump to line 72, because the condition on line 71 was never true
72 lsst.utils.tests.init()
73 unittest.main()