1 # -*- coding: utf-8 -*-
3 from nose.tools import assert_equal, assert_true, assert_false
6 from datetime import time
7 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
10 from gotovienna.realtime import *
14 stationbased = open(os.path.join(DATAPATH, 'stationbased.html'), 'r').read()
15 line_station = open(os.path.join(DATAPATH, 'line_station.html'), 'r').read()
16 errorpage = open(os.path.join(DATAPATH, 'errorpage.html'), 'r').read()
17 nodepartures = open(os.path.join(DATAPATH, 'nodepartures.html'), 'r').read()
18 lines = open(os.path.join(DATAPATH, 'lines.html'), 'r').read()
19 stations1 = open(os.path.join(DATAPATH, 'stations1.html'), 'r').read()
20 stations2 = open(os.path.join(DATAPATH, 'stations2.html'), 'r').read()
22 parsed_lines = parser.parse_lines(lines)
25 assert_equal(dict, type(parsed_lines))
26 assert_true(parsed_lines)
28 def test_line_amount():
29 assert_equal(104, len(parsed_lines.keys()))
32 assert_equal('http://www.wienerlinien.at/itip/linienwahl/linie.php?lng=de&lng=de&linie=1', parsed_lines['1'])
34 def test_line_links():
35 assert_true(filter(lambda x: x.startswith('http://'), parsed_lines.values()))
38 st1 = parser.parse_stations(stations1)
39 assert_true(st1.has_key(u'Gersthof, Herbeckstraße'))
40 assert_true(st1.has_key(u'Schottentor U'))
41 assert_equal(14, len(st1[u'Gersthof, Herbeckstraße']))
42 assert_equal(12, len(st1[u'Schottentor U']))
45 st2 = parser.parse_stations(stations2)
46 assert_true(st2.has_key(u'Stefan-Fadinger-Platz'))
47 assert_true(st2.has_key(u'Prater Hauptallee'))
48 assert_equal(31, len(st2[u'Stefan-Fadinger-Platz']))
49 assert_equal(30, len(st2[u'Prater Hauptallee']))
51 def test_departures_by_station():
52 dep = parser.parse_departures_by_station(stationbased)
53 # find all 34 departures
54 assert_equal(34, len(dep))
55 l = list(set(map(lambda x: x['line'], dep)))
56 # there are 8 different lines
57 assert_equal(8, len(l))
59 def test_departures_by_station_lowfloor():
60 dep = parser.parse_departures_by_station(stationbased)
61 assert_true(dep[0]['lowfloor'])
62 assert_false(dep[14]['lowfloor'])
64 def test_departures_by_station_datetime():
65 dep = parser.parse_departures_by_station(stationbased)
66 assert_equal(int, type(dep[13]['time']))
67 assert_equal(time, type(dep[14]['time']))
69 def test_departures():
70 dep = parser.parse_departures(line_station)
72 def test_error_page():
73 dep = parser.parse_departures(errorpage)
74 assert_equal(0, len(dep))
76 def test_no_departures():
77 dep = parser.parse_departures(nodepartures)
78 assert_equal(0, len(dep))