Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

import os 

import sqlite3 

import unittest 

import lsst.utils.tests 

 

from lsst.sims.downtimeModel import ScheduledDowntime 

 

 

class ScheduledDowntimeTest(unittest.TestCase): 

 

def setUp(self): 

self.sdt = ScheduledDowntime() 

 

def check_downtime(self, downtime, night, duration, activity): 

self.assertEqual(downtime[0], night) 

self.assertEqual(downtime[1], duration) 

self.assertEqual(downtime[2], activity) 

 

def test_basic_information_after_creation(self): 

self.assertIsNone(self.sdt.downtime_file) 

self.assertEqual(len(self.sdt), 0) 

 

def test_information_after_initialization(self): 

self.sdt.initialize() 

self.assertEqual(os.path.basename(self.sdt.downtime_file), "scheduled_downtime.db") 

self.assertEqual(len(self.sdt), 31) 

self.check_downtime(self.sdt.downtimes[0], 158, 7, "general maintenance") 

self.check_downtime(self.sdt.downtimes[-1], 7242, 7, "general maintenance") 

 

def test_alternate_db(self): 

downtime_dbfile = "alternate_scheduled_downtime.db" 

 

downtime_table = [] 

downtime_table.append("night INTEGER PRIMARY KEY") 

downtime_table.append("duration INTEGER") 

downtime_table.append("activity TEXT") 

 

with sqlite3.connect(downtime_dbfile) as conn: 

cur = conn.cursor() 

cur.execute("DROP TABLE IF EXISTS Downtime") 

cur.execute("CREATE TABLE Downtime({})".format(",".join(downtime_table))) 

cur.execute("INSERT INTO Downtime VALUES(?, ?, ?)", (100, 7, "something to do")) 

cur.close() 

 

self.sdt.initialize(downtime_dbfile) 

self.assertEqual(len(self.sdt), 1) 

self.check_downtime(self.sdt.downtimes[0], 100, 7, "something to do") 

 

os.remove(downtime_dbfile) 

 

def test_call(self): 

self.sdt.initialize() 

self.check_downtime(self.sdt(), 158, 7, "general maintenance") 

self.assertEqual(len(self.sdt), 30) 

 

 

class TestMemory(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()