rewrote routing unittests
[pywienerlinien] / gotovienna / tests / routing.py
1 # -*- coding: utf-8 -*-
2
3 from nose.tools import assert_equal, assert_true, assert_false
4 from datetime import datetime
5
6 from gotovienna.routing import *
7 DATAPATH = 'data'
8
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()
12
13 def test_extract_city():
14     assert_equal('Wien', extract_city('Börse, Wien'))
15     assert_equal('Wien', extract_city('Börse'))
16
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'))
20
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'))
24
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'))
28
29 def test_overview1():
30     """ Normal distance
31     """
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'])
39
40 def test_overview2():
41     """ Mixed routing short distance (EUR 0.9) and normal distance
42     """
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'])
55
56 def test_overview3():
57     """ Short distance, routing by foot
58     """
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'])