-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_timetable.py
executable file
·623 lines (520 loc) · 26.6 KB
/
test_timetable.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# Skapat av Christian Davén 2004
from i18n import *
setLanguage("en")
import timetable
import calendar
import xunittest
# -----------------------------------------------------------
class CourseTest(xunittest.TestCase):
def testInit(self):
c = timetable.Course("*:59/2I1140", "Artificiell intelligens", 934, 1, "20051")
self.failUnlessEqual(c.code, "*:59/2I1140")
self.failUnlessEqual(c.name, "Artificiell intelligens")
self.failUnlessEqual(c.id, 934)
self.failUnlessEqual(c.group, "1")
self.failUnlessEqual(c.getTerm(), "VT05")
c = timetable.Course("2C1224", "Projektstyrning")
self.failUnlessEqual(c.code, "2C1224")
self.failUnlessEqual(c.id, "2C1224")
self.failUnlessEqual(c.name, "Projektstyrning")
self.failUnlessEqual(c.group, "")
def testEqual(self):
c1 = timetable.Course("*:59/2I1140", "Artificiell intelligens", 934)
c2 = timetable.Course("*:59/2I1140", "Artificiell intelligens", 809)
c3 = timetable.Course("5B1116", "Matematisk statistik", group="a")
c4 = timetable.Course("5B1116", "MatStat", group="c")
self.failIfEqual(c1, c3)
self.failIfEqual(c1, c2)
self.failUnlessEqual(c3, c4)
self.failUnlessEqual(c1, c1)
def testHasCode(self):
c = timetable.Course("*:36/2I1225/2I1374/2I1190", "DSV-kurs")
self.failUnless(c.hasCode("*:36/2I1225/2I1374/2"))
c = timetable.Course("5B1506 IT", "Matte nånting")
self.failUnless(c.hasCode("5B1506 ME"))
c = timetable.Course("*:59/2I1140", "Artificiell intelligens")
self.failIf(c.hasCode("6B3023"))
def testIsDaisyOrTimeEdit(self):
c = timetable.Course("*:59/2I1140", "Artificiell intelligens", 809)
self.failIf(c.isTimeEdit())
self.failUnless(c.isDaisy())
c = timetable.Course("5B1116", "Matematisk statistik")
self.failIf(c.isDaisy())
self.failUnless(c.isTimeEdit())
def testGetTerm(self):
c = timetable.Course("*:59/2I1140", "Artificiell intelligens", term="20051")
self.failUnlessEqual(c.getTerm(), "VT05")
c = timetable.Course("*:59/2I1140", "Artificiell intelligens", term="20042")
self.failUnlessEqual(c.getTerm(), "HT04")
# -----------------------------------------------------------
class CourseListTest(xunittest.TestCase):
courselist = None
courses = []
def setUp(self):
self.courses = []
self.courses.append(timetable.Course("2B1345", "DigEl", group="3"))
self.courses.append(timetable.Course("*:59", "DSV-mysko", 931))
self.courses.append(timetable.Course("DSV:L/9E1363", "Kommunikation", 429, group="5"))
self.courses.append(timetable.Course("5B1113 IT", "Matte"))
self.courselist = timetable.CourseList()
self.courselist.courses.append(timetable.Course("2B1345", "DigEl"))
self.courselist.courses.append(timetable.Course("*:59", "DSV-mysko", 931))
self.courselist.courses.append(timetable.Course("DSV:L/9E1363", "Kommunikation", 429))
self.courselist.courses.append(timetable.Course("5B1113 IT", "Matte"))
def testClearAndEmpty(self):
self.courselist.clear()
self.failIf(self.courselist.courses)
self.failUnless(self.courselist.isEmpty())
def testDaisyCourseIDs(self):
self.failUnlessListsEqual([931,429], self.courselist.getAllDaisyCourseIDs())
def testTimeEditCourseIDs(self):
self.failUnlessListsEqual(["2B1345", "5B1113 IT"], self.courselist.getAllTimeEditCourseIDs())
def testGetAllMatchingName(self):
courses = self.courselist.getAllMatchingName("DSV")
self.failUnlessEqual(len(courses), 1)
self.failUnlessEqual(courses[0].code, "*:59")
courses = self.courselist.getAllMatchingName("qwerty")
self.failIf(len(courses))
def testGetAllMatchingCode(self):
courses = self.courselist.getAllMatchingCode("DSV")
self.failUnlessEqual(len(courses), 1)
self.failUnlessEqual(courses[0].code, "DSV:L/9E1363")
courses = self.courselist.getAllMatchingCode("qwerty")
self.failIf(len(courses))
def tstAddCourses(self):
self.courselist.clear()
for course in self.courses:
code = course.code
name = course.name
id = course.id
group = course.group
self.courselist.addCourse(code, name, id, group)
self.failUnlessEqual(self.courselist.courses, self.courses)
count = len(self.courselist.courses)
self.courselist.addCourse("5B1113 IT", "Matematik")
self.failUnlessEqual(count, len(self.courselist.courses))
self.failUnlessEqual(self.courselist.getCourseName("5B1113 IT"), "Matematik")
self.courses.append(timetable.Course("9B1111", "X"))
self.courselist.addCourse(timetable.Course("9B1111", "X"))
self.failUnlessEqual(self.courses, self.courselist.courses)
def tstRemoveCourse(self):
self.courselist.removeCourse("DSV:L/9E1363")
self.courses.remove(timetable.Course("DSV:L/9E1363", "Kommunikation", 429, 5))
self.failUnlessListsEqual(self.courselist.courses, self.courses)
self.failUnlessRaises(ValueError, self.courselist.removeCourse, "abc")
def testGetCourse(self):
course5B1113 = timetable.Course("5B1113 IT", "Matte")
course9E1363 = timetable.Course("DSV:L/9E1363", "Kommunikation", 429)
self.failUnlessEqual(self.courselist.getCourse(429), course9E1363)
self.failUnlessEqual(self.courselist.getCourse("5B1113 IT"), course5B1113)
self.failUnlessRaises(ValueError, self.courselist.getCourse, "abc")
# -----------------------------------------------------------
class TimeTableTest: #(xunittest.TestCase):
def setUp(self):
self.events = {}
self.timetable = timetable.TimeTable()
self.timetable.updated = calendar.DateTime("20040530")
self.updated = calendar.DateTime("20040530")
timetable.courselist.clear()
timetable.courselist.addCourse("2B1345", "DigEl", 616, 2)
timetable.courselist.addCourse("*:59", "DSV-mysko", 931, 0)
timetable.courselist.addCourse("DSV:L/9E1363", "Kommunikation", 429, 5)
timetable.courselist.addCourse("5B1113", "Matte", 754, 0)
self.events["DAISYKTH1000"] = timetable.Event("DAISYKTH1000", calendar.Date("20040301"),
calendar.Time("110000"), calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113")
self.events["DAISYKTH1001"] = timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345")
self.events["DAISYKTH1002"] = timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363")
self.events["DAISYKTH1003"] = timetable.Event("DAISYKTH1003", calendar.Date("20040416"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363")
self.timetable.eventlist.events["DAISYKTH1000"] = timetable.Event("DAISYKTH1000", calendar.Date("20040301"), calendar.Time("110000"),
calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113")
self.timetable.eventlist.events["DAISYKTH1001"] = timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345")
self.timetable.eventlist.events["DAISYKTH1002"] = timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363")
self.timetable.eventlist.events["DAISYKTH1003"] = timetable.Event("DAISYKTH1003", calendar.Date("20040416"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363")
def testEmpty(self):
self.failIf(self.timetable.isEmpty())
self.timetable.eventlist.clear()
self.failUnless(self.timetable.isEmpty())
def testEvent(self):
self.failUnlessEqual(self.timetable.getEvent("DAISYKTH1003"),
timetable.Event("DAISYKTH1003", calendar.Date("20040416"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363"))
self.failUnlessEqual(self.timetable.getEvent("DAISYKTH1001"),
timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345"))
self.failUnlessRaises(ValueError, self.timetable.getEvent, "abc")
def testAllGroups(self):
self.failUnlessEqual(self.timetable.getAllGroups("2B1345"), [2])
self.failIf(self.timetable.getAllGroups("5B1113"))
self.failUnlessRaises(ValueError, self.timetable.getAllGroups, "abc")
def testEventsForDate(self):
events = []
events.append(timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345"))
events.append(timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363"))
self.failUnlessListsEqual(self.timetable.getEventsForDate(calendar.Date("20040414")), events)
def testEventsForDateRange(self):
events = []
events.append(timetable.Event("DAISYKTH1000", calendar.Date("20040301"), calendar.Time("110000"),
calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113"))
events.append(timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345"))
events.append(timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363"))
self.failUnlessListsEqual(self.timetable.getEventsForDateRange(calendar.Date("20040301"),
calendar.Date("20040414")), events)
def testRemoveCourseEvents(self):
remaining = []
for event in self.events.values():
if event.course != "DSV:L/9E1363":
remaining.append(event)
self.timetable.removeCourseEvents("DSV:L/9E1363")
self.failUnlessListsEqual(self.timetable.eventlist.getAll(), remaining)
def testLoadSave(self):
events = []
events.extend(self.timetable.eventlist.getAll())
updated = self.timetable.updated
courses = []
courses.extend(timetable.courselist.courses)
self.timetable.save("_test")
timetable.courselist.clear()
self.timetable.clear()
self.timetable.updated = None
self.timetable.load("_test")
import os
os.remove("_test")
# testa save till skrivskyddad fil
self.failUnlessListsEqual(self.timetable.eventlist.getAll(), events)
self.failUnlessListsEqual(timetable.courselist.courses, courses)
self.failUnlessEqual(self.timetable.updated, updated)
# -----------------------------------------------------------
class EventTest: #(xunittest.TestCase):
def setUp(self):
timetable.courselist.clear()
timetable.courselist.addCourse("5B1506 IT", "MatStat", 123)
timetable.courselist.addCourse("DSV2:B", "DSV-mysko", 123)
timetable.courselist.addCourse("5B1506 ME", "MatStat", 123)
timetable.courselist.addCourse("2I1140", "AI", 123)
def testInitFromDict(self):
event = timetable.Event()
event.setID(333)
event.date = calendar.Date("20031109")
event.begin = calendar.Time("133000")
event.end = calendar.Time("160000")
event.location = "E51"
event.course = "2C1445"
event.type = "Föreläsning"
event.group = 1
event.seriesno = 7
eventdict = {"id": 333, "date": "20031109", "begin": "133000", "end": "160000",
"location": "E51", "course": "2C1445", "type": "Föreläsning", "group": 1, "seriesno": 7}
self.failUnlessEqual(timetable.Event(eventdict), event)
event = timetable.Event()
event.setID("DAISYKTH")
event.date = calendar.Date("20040901")
event.begin = calendar.Time("124500")
event.end = calendar.Time("130000")
event.location = "Sal B"
event.course = timetable.courselist.getCourse("2I1140")
event.type = "Introduktion"
event.group = 0
event.seriesno = 0
eventdict = {"id": "DAISYKTH", "date": "20040901", "begin": "124500", "end": "130000",
"location": "Sal B", "course": "2I1140", "type": "Introduktion", "group": 0, "seriesno": 0}
self.failUnlessEqual(timetable.Event(eventdict), event)
eventdict = {"id": "DAISYKTH", "date": "20040901", "begin": "124500", "end": "130000",
"location": "Sal B", "summary": "Introduktion Sal B - 2I1140"}
self.failUnlessEqual(timetable.Event(eventdict), event)
event = timetable.Event()
event.setID("[email protected]")
event.date = calendar.Date("20040901")
event.begin = calendar.Time("124500")
event.end = calendar.Time("130000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Seminarium"
eventdict = {"id": "[email protected]", "date": "20040901",
"begin": "124500", "end": "130000", "location": "", "summary": "DSV2:B.Sem X3X F3"}
self.failUnlessEqual(timetable.Event(eventdict), event)
def testInitAndString(self):
event = timetable.Event("DAISYKTH", location="539", summary="Övning 1 grp 1 539 - 5B1506")
self.failUnlessEqual(str(event), "MatStat Ö1 grp 1 (539)")
event = timetable.Event("DAISYKTH", location="215,313,314,Forum, Kista", summary="Salsskrivning 215,313,314,Forum, Kista - DSV2:B")
self.failUnlessEqual(str(event), "DSV-mysko Tenta (215,313,314,Forum, Kista)")
event = timetable.Event("DAISYKTH", location="538", summary="Lektion 26 538 - 5B1506 ME")
self.failUnlessEqual(str(event), "MatStat Lekt26 (538)")
event = timetable.Event("timeedit.evolvera.se", summary="M4MEK T4MEK V4BKO 5B1506.WS V26t ---")
self.failUnlessEqual(str(event), "MatStat WS (V26t)")
event = timetable.Event("timeedit.evolvera.se", summary="DSV2:B.L D4D E4E F4F 5V5Vio")
self.failUnlessEqual(str(event), "DSV-mysko Labb (5V5Vio)")
event = timetable.Event("timeedit.evolvera.se", summary="DSV2:B.Sem X3X")
self.failUnlessEqual(str(event), "DSV-mysko Sem")
event = timetable.Event("timeedit.evolvera.se", summary="D2D I2FIM I3KSI 5B1506.TEN E31 E32 E33 E34 E35 E36 V32 V33 V...")
self.failUnlessEqual(str(event), "MatStat Tenta (E31,E32,E33,E34,E35,E36,V32,V33)")
def testCopy(self):
event = timetable.Event("DAISYKTH", location="539", summary="Övning 1 grp 1 539 - 5B1506")
copy = timetable.Event()
copy.copy(event)
self.failUnlessEqual(event, copy)
# -----------------------------------------------------------
class EventListTest: #(xunittest.TestCase):
def setUp(self):
self.eventlist = timetable.EventList([{"id": 1, "location": "1"},
{"id": 2, "location": "2"}, {"id": 3, "location": "3"}])
self.events = {}
self.events[1] = timetable.Event(1, location="1")
self.events[2] = timetable.Event(2, location="2")
self.events[3] = timetable.Event(3, location="3")
def testInit(self):
self.failUnlessEqual(self.eventlist.events, self.events)
def testAdd(self):
self.events[6] = timetable.Event(6, location="6")
self.eventlist.addEvent(timetable.Event(6, location="6"))
self.failUnlessEqual(self.eventlist.events, self.events)
self.events[33] = timetable.Event(33, location="33")
self.eventlist.addEvent(timetable.Event(33, location="33"))
self.failUnlessEqual(self.eventlist.events, self.events)
def testRemove(self):
del self.events[2]
self.eventlist.removeEvent(2)
self.failUnlessEqual(self.eventlist.events, self.events)
# -----------------------------------------------------------
class TimeTableComparatorTest: #(xunittest.TestCase):
def testAdded(self):
events = []
events.append(timetable.Event("DAISYKTH1000", calendar.Date("20040301"), calendar.Time("110000"),
calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113"))
events.append(timetable.Event("DAISYKTH1001", calendar.Date("20040414"), calendar.Time("093000"),
calendar.Time("120000"), "540", "Lektion 3 grp 2 540 - 2B1345"))
events.append(timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1003", calendar.Date("20040416"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1004", calendar.Date("20040419"), calendar.Time("080000"),
calendar.Time("120000"), "Sal B", "Föreläsning 2 Sal B - DSV:L/9E1363"))
self.failUnlessEqual(self.timetable.getAdded(events), ["DAISYKTH1004"])
def testRemoved(self):
events = []
events.append(timetable.Event("DAISYKTH1000", calendar.Date("20040301"), calendar.Time("110000"),
calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113"))
events.append(timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("153000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1003", calendar.Date("20040416"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1004", calendar.Date("20040419"), calendar.Time("080000"),
calendar.Time("120000"), "Sal B", "Föreläsning 2 Sal B - DSV:L/9E1363"))
self.failUnlessEqual(self.timetable.getRemoved(events), ["DAISYKTH1001"])
def testChanged(self):
events = []
events.append(timetable.Event("DAISYKTH1000", calendar.Date("20040301"), calendar.Time("110000"),
calendar.Time("130000"), "Sal A", "Föreläsning 1 Sal A - 5B1113"))
events.append(timetable.Event("DAISYKTH1002", calendar.Date("20040414"), calendar.Time("160000"),
calendar.Time("180000"), "Aulan", "Introduktion Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1003", calendar.Date("20040415"), calendar.Time("100000"),
calendar.Time("120000"), "Aulan", "Föreläsning 1 Aulan - DSV:L/9E1363"))
events.append(timetable.Event("DAISYKTH1004", calendar.Date("20040419"), calendar.Time("080000"),
calendar.Time("120000"), "Sal B", "Föreläsning 2 Sal B - DSV:L/9E1363"))
self.failUnlessListsEqual(self.timetable.getChanged(events),
["DAISYKTH1002", "DAISYKTH1003"])
# -----------------------------------------------------------
class HTMLExporterTest: #(xunittest.TestCase):
def testExport(self):
timetable.courselist.clear()
timetable.courselist.addCourse("5B1506", "MatStat", 123)
timetable.courselist.addCourse("DSV2:B", "DSV-mysko", 123)
table = timetable.TimeTable()
exporter = timetable.HTMLExporter()
event = timetable.Event()
event.setID(1)
event.date = calendar.Date("20040901")
event.begin = calendar.Time("124500")
event.end = calendar.Time("130000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Seminarium"
table.addEvent(event)
event = timetable.Event()
event.setID(2)
event.date = calendar.Date("20040901")
event.begin = calendar.Time("130000")
event.end = calendar.Time("150000")
event.location = "Sal B"
event.course = "5B1506"
event.type = "Lektion"
table.addEvent(event)
event = timetable.Event()
event.setID(3)
event.date = calendar.Date("20040903")
event.begin = calendar.Time("090000")
event.end = calendar.Time("110000")
event.location = "Aulan"
event.course = "5B1506"
event.type = "Övning"
event.seriesno = 3
table.addEvent(event)
event = timetable.Event()
event.setID(4)
event.date = calendar.Date("20040906")
event.begin = calendar.Time("080000")
event.end = calendar.Time("100000")
event.location = "540"
event.course = "5B1506"
event.type = "Seminarium"
event.seriesno = 3
table.addEvent(event)
event = timetable.Event()
event.setID(5)
event.date = calendar.Date("20040908")
event.begin = calendar.Time("170000")
event.end = calendar.Time("210000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Föreläsning"
event.seriesno = 6
table.addEvent(event)
event = timetable.Event()
event.setID(6)
event.date = calendar.Date("20040902")
event.begin = calendar.Time("120000")
event.end = calendar.Time("140000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Seminarium"
event.active = False
table.addEvent(event)
exporter.export("_test", table, calendar.Date("20040831"), calendar.Date("20040909"))
exporteddata = file("_test").read()
self.failUnlessEqual(exporteddata, """<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN'
'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='sv'>
<head>
<title>Schema</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<meta name='generator' content='Schema' />
<link rel='stylesheet' type='text/css' href='timetable-html.css' />
</head>
<body><h1>Schema</h1>
<div class='week'><h2>Vecka 36</h2><div class='day'><h3>Mån 30/8</h3></div><div class='day'><h3>Tis 31/8</h3></div><div class='day'><h3>Ons 1/9</h3><div class='event'>12:45-13:00: DSV-mysko Sem (F3)</div><div class='event'>13:00-15:00: MatStat Lekt (Sal B)</div></div><div class='day'><h3>Tor 2/9</h3></div><div class='day'><h3>Fre 3/9</h3><div class='event'>09:00-11:00: MatStat Ö3 (Aulan)</div></div></div>
<div class='week'><h2>Vecka 37</h2><div class='day'><h3>Mån 6/9</h3><div class='event'>08:00-10:00: MatStat Sem3 (540)</div></div><div class='day'><h3>Tis 7/9</h3></div><div class='day'><h3>Ons 8/9</h3><div class='event'>17:00-21:00: DSV-mysko F6 (F3)</div></div><div class='day'><h3>Tor 9/9</h3></div><div class='day'><h3>Fre 10/9</h3></div></div>
</body></html>""")
import os
os.remove("_test")
# -----------------------------------------------------------
class VCalendarExporterTest: #(xunittest.TestCase):
def testExport(self):
timetable.courselist.clear()
timetable.courselist.addCourse("5B1506", "MatStat", 123)
timetable.courselist.addCourse("DSV2:B", "DSV-mysko", 123)
table = timetable.TimeTable()
exporter = timetable.VCalendarExporter()
event = timetable.Event()
event.setID(1)
event.date = calendar.Date("20040901")
event.begin = calendar.Time("124500")
event.end = calendar.Time("130000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Seminarium"
table.addEvent(event)
event = timetable.Event()
event.setID(2)
event.date = calendar.Date("20040901")
event.begin = calendar.Time("130000")
event.end = calendar.Time("150000")
event.location = "Sal B"
event.course = "5B1506"
event.type = "Lektion"
table.addEvent(event)
event = timetable.Event()
event.setID(3)
event.date = calendar.Date("20040903")
event.begin = calendar.Time("090000")
event.end = calendar.Time("110000")
event.location = "Aulan"
event.course = "5B1506"
event.type = "Övning"
event.seriesno = 3
table.addEvent(event)
event = timetable.Event()
event.setID(4)
event.date = calendar.Date("20040906")
event.begin = calendar.Time("080000")
event.end = calendar.Time("100000")
event.location = "540"
event.course = "5B1506"
event.type = "Seminarium"
event.seriesno = 3
table.addEvent(event)
event = timetable.Event()
event.setID(5)
event.date = calendar.Date("20040908")
event.begin = calendar.Time("170000")
event.end = calendar.Time("210000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Föreläsning"
event.seriesno = 6
table.addEvent(event)
event = timetable.Event()
event.setID(6)
event.date = calendar.Date("20040902")
event.begin = calendar.Time("120000")
event.end = calendar.Time("140000")
event.location = "F3"
event.course = "DSV2:B"
event.type = "Seminarium"
event.active = False
table.addEvent(event)
exporter.export("_test", table, calendar.Date("20040831"), calendar.Date("20040909"))
exporteddata = file("_test").read()
self.failUnlessEqual(exporteddata, """BEGIN:VCALENDAR
VERSION:1.0
PRODID:-//cda//NONSGML Schema//SV
BEGIN:VEVENT
UID:1
DTSTART:20040901T104500Z
DTEND:20040901T110000Z
SUMMARY:DSV-mysko Sem
LOCATION:F3
END:VEVENT
BEGIN:VEVENT
UID:2
DTSTART:20040901T110000Z
DTEND:20040901T130000Z
SUMMARY:MatStat Lekt
LOCATION:Sal B
END:VEVENT
BEGIN:VEVENT
UID:3
DTSTART:20040903T070000Z
DTEND:20040903T090000Z
SUMMARY:MatStat Ö3
LOCATION:Aulan
END:VEVENT
BEGIN:VEVENT
UID:4
DTSTART:20040906T060000Z
DTEND:20040906T080000Z
SUMMARY:MatStat Sem3
LOCATION:540
END:VEVENT
BEGIN:VEVENT
UID:5
DTSTART:20040908T150000Z
DTEND:20040908T190000Z
SUMMARY:DSV-mysko F6
LOCATION:F3
END:VEVENT
END:VCALENDAR""")
import os
os.remove("_test")
# -----------------------------------------------------------
xunittest.run()