17ac0fb1b24510066843e08f701e43915da44c0c
[openblackhole/openblackhole-enigma2.git] / tests / test_timer.py
1 import enigma
2 import sys
3 import time
4
5 import tests
6
7 #enigma.reset()
8 def test_timer(repeat = 0, timer_start = 3600, timer_length = 1000, sim_length = 86400 * 7):
9
10         print "loading RecordTimer"
11         import RecordTimer
12         print "ok"
13         
14         at = time.time()
15         
16         t = RecordTimer.RecordTimer()
17         t.MaxWaitTime = 86400 * 1000
18
19         # generate a timer to test
20         import xml.dom.minidom
21
22         timer = RecordTimer.createTimer(xml.dom.minidom.parseString(
23         """
24                 <timer 
25                         begin="%d" 
26                         end="%d"
27                         serviceref="1:0:1:6DD2:44D:1:C00000:0:0:0:" 
28                         repeated="%d" 
29                         name="Test Event Name" 
30                         description="Test Event Description" 
31                         afterevent="nothing" 
32                         eit="56422" 
33                         disabled="0" 
34                         justplay="0">
35         </timer>""" % (at + timer_start, at + timer_start + timer_length, repeat)
36         ).childNodes[0])
37
38         t.record(timer)
39
40         # run virtual environment
41         enigma.run(sim_length)
42         
43         print "done."
44         
45         timers = t.processed_timers  + t.timer_list
46         
47         print "start: %s" % (time.ctime(at + 10))
48         
49         assert len(timers) == 1
50         
51         for t in timers:
52                 print "begin=%d, end=%d, repeated=%d, state=%d" % (t.begin - at, t.end - at, t.repeated, t.state)
53                 print "begin: %s" % (time.ctime(t.begin))
54                 print "end: %s" % (time.ctime(t.end))
55
56         # if repeat, check if the calculated repeated time of day matches the initial time of day
57         if repeat:
58                 t_initial = time.localtime(at + timer_start)
59                 t_repeated = time.localtime(timers[0].begin)
60                 print t_initial
61                 print t_repeated
62                 
63         if t_initial[3:6] != t_repeated[3:6]:
64                 raise tests.TestError("repeated timer time of day does not match")
65
66 import FakeNotifications
67 #sys.modules["Tools.Notifications"] = FakeNotifications
68 #sys.modules["Tools.NumericalTextInput.NumericalTextInput"] = FakeNotifications
69
70 # required stuff for timer (we try to keep this minimal)
71 enigma.init_nav()
72 enigma.init_record_config()
73 enigma.init_parental_control()
74
75
76 from events import log
77
78 import calendar
79
80
81 import os
82 # we are operating in CET/CEST
83 os.environ['TZ'] = 'CET'
84 time.tzset()
85
86 #log(test_timer, test_name = "test_timer_repeating", base_time = calendar.timegm((2007, 3, 1, 12, 0, 0)), repeat=0x7f, sim_length = 86400 * 7)
87 log(test_timer, test_name = "test_timer_repeating_dst_start", base_time = calendar.timegm((2007, 03, 20, 0, 0, 0)), repeat=0x7f, sim_length = 86400 * 7)