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