1 # -*- coding: utf-8 -*-
3 from nose.tools import assert_equal, assert_true, assert_false
4 from datetime import datetime
6 from gotovienna.routing import *
9 underground_routing = open(os.path.join(DATAPATH, 'underground_routing.html'), 'r').read()
10 underground_foot_routing = open(os.path.join(DATAPATH, 'underground_foot_routing.html'), 'r').read()
11 foot_routing = open(os.path.join(DATAPATH, 'foot_routing.html'), 'r').read()
13 def test_extract_city():
14 assert_equal('Wien', extract_city('Börse, Wien'))
15 assert_equal('Wien', extract_city('Börse'))
17 def test_extract_station():
18 assert_equal(u'Börse', extract_station(u'Börse, Wien'))
19 assert_equal(u'Börse', extract_station(u'Börse'))
21 def test_split_station():
22 assert_equal((u'Börse', 'Wien'), split_station(u'Börse, Wien'))
23 assert_equal((u'Börse', 'Wien'), split_station(u'Börse'))
25 def test_guess_location_type():
26 assert_equal('address', guess_location_type(u'Rathausstraße 6'))
27 assert_equal('stop', guess_location_type(u'Börse'))
32 router = rParser(underground_routing)
33 assert_equal(4, len(router.overview))
34 assert_equal(1, router.overview[0]['change'])
35 assert_equal(1.8, router.overview[0]['price'])
36 assert_equal([datetime(2011, 12, 16, 15, 44),
37 datetime(2011, 12, 16, 16, 0)],
38 router.overview[0]['timespan'])
41 """ Mixed routing short distance (EUR 0.9) and normal distance
43 router = rParser(underground_foot_routing)
44 assert_equal(8, len(router.overview))
45 assert_equal(1, router.overview[0]['change'])
46 assert_equal(0, router.overview[1]['change'])
47 assert_equal(1.8, router.overview[0]['price'])
48 assert_equal(0.9, router.overview[1]['price'])
49 assert_equal([datetime(2011, 12, 16, 15, 44),
50 datetime(2011, 12, 16, 15, 54)],
51 router.overview[0]['timespan'])
52 assert_equal([datetime(2011, 12, 16, 15, 44),
53 datetime(2011, 12, 16, 15, 59)],
54 router.overview[1]['timespan'])
57 """ Short distance, routing by foot
59 router = rParser(foot_routing)
60 assert_equal(1, len(router.overview))
61 assert_equal(0, router.overview[0]['change'])
62 assert_equal(.0, router.overview[0]['price'])
63 assert_equal([], router.overview[0]['timespan'])