Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
159 lines (123 loc) · 4.17 KB
/
Copy pathtest.py
File metadata and controls
159 lines (123 loc) · 4.17 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Calendar, Graphical calendar applet with novel interface
#
# test.py
#
# Copyright (c) 2010, Brandon Lewis <brandon_lewis@berkeley.edu>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import cal
import weekview
import gobject
import gtk
import traceback
import sys
import datetime
import os
import recurrence
class TestApp(cal.App):
path = "test.data"
class Tester:
def __init__(self, test_case):
self.app = TestApp()
gobject.timeout_add(1000, self.run_test_case, test_case(self.app))
self.app.run()
os.unlink("test.data")
def run_test_case(self, iterator):
print "Tick"
try:
scheduler = iterator.next()
except StopIteration:
print "Test Case Finished Successfully"
self.app.quit()
return False
except Exception, e:
print "An error occured"
self.app.quit()
traceback.print_exc()
return False
scheduler.schedule(self, iterator)
return False
class Sleep(object):
def __init__(self, timeout=1000):
self.timeout = timeout
def schedule(self, tester, iterator):
gobject.timeout_add(self.timeout, tester.run_test_case, iterator)
class WaitForSignal(object):
def __init__(self, obj, signame):
self.obj = obj
self.signame = signame
self.iterator = None
self.sigid = None
def schedule(self, tester, iterator):
self.sigid = self.obj.connect(self.signame, self._handler)
self.iterator = iterator
self.tester = tester
def _handler(self, *args):
self.tester.run_test_case(self.iterator)
self.obj.disconnect(self.sigid)
def basic_test(app):
yield Sleep(100)
def test_select_area(app):
yield Sleep(100)
cmd = weekview.SelectArea(app.weekview.timed, [100, 100])
cmd.update((100, 100 + app.weekview.timed.hour_height),
(0, app.weekview.timed.hour_height),
True)
yield Sleep()
assert type(app.info.selection_recurrence) == recurrence.Period
r = app.info.selection_recurrence
yield Sleep()
cmd.undo()
assert app.info.selection_recurrence == None
yield Sleep()
cmd.do()
assert app.info.selection_recurrence == r
yield Sleep()
def test_new_event(app):
yield Sleep(100)
s = datetime.datetime.today()
e = s + datetime.timedelta(hours=1)
app.info.selection_recurrence = r = recurrence.Period(
recurrence.Weekly(0), datetime.time(12, 00), datetime.time(13, 00))
cmd = cal.NewEvent(app)
cmd.do()
assert app.info.selection_recurrence == None
cmd.undo()
assert app.info.selection_recurrence == r
cmd.do()
assert app.info.selection_recurrence == None
def test_select_and_delete_event(app):
cmd = weekview.SelectArea(app.weekview.timed, (100, 100))
cmd.update((100, 100 + app.weekview.timed.hour_height),
(0, app.weekview.timed.hour_height))
r = app.info.selection_recurrence
cmd = cal.NewEvent(app)
cmd.do()
yield Sleep()
event = cmd.event
cmd = weekview.SelectPoint(app.weekview.timed, 110, 110)
cmd.do()
yield Sleep()
assert app.info.selected == (event, 0)
cmd = cal.DelEvent(app)
cmd.do()
assert app.weekview.timed.selected == None
cmd.undo()
for test in [basic_test,
test_select_area,
test_new_event,
test_select_and_delete_event]:
Tester(test)