Fix some corner cases: mostly tulip fest around Kent & Albert
[ottawa-travel-planner.git] / tests / test_busstopmash_regexes.py
blobcf86eb629ceba22e30e5c1e22dd35712acea8485
1 # vi: set fileencoding=latin1 softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
3 # The above line tells Python to use Latin-1, which seems to be right for the
4 # accented characters coming back from the travel planner.
6 import unittest
7 import BusStopMashup
9 class TestStopRegex(unittest.TestCase):
10 def testAccentedEInName(self):
11 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=3035' target='iframe'>3035</a></b></strong><small> (RA970)</small><br>HERON STOP / ARRÊT 4A <br><a href='iframe.asp?route=4&dir=10' target='iframe'>4</a> <a href='iframe.asp?route=87&dir=11' target='iframe'>87</a> <a href='iframe.asp?route=107&dir=11' target='iframe'>107</a> <a href='iframe.asp?route=111&dir=10' target='iframe'>111</a> <a href='iframe.asp?route=118&dir=10' target='iframe'>118</a> <a href='iframe.asp?route=140&dir=11' target='iframe'>140</a> <a href='iframe.asp?route=656&dir=11' target='iframe'>656</a> </span>"""
12 match = BusStopMashup._stop_rx.search(text)
13 self.assertNotEquals(match, None)
14 self.assertEquals(match.group("stopnum"), "3035")
15 self.assertEquals(match.group("code"), "RA970")
17 def testLongStopCode(self):
18 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=3035' target='iframe'>3035</a></b></strong><small> (SCO018)</small><br>HERON SCOTIABANK 2A<br></span>"""
19 match = BusStopMashup._stop_rx.search(text)
20 self.assertNotEquals(match, None)
21 self.assertEquals(match.group("code"), "SCO018")
23 def testCodeTULIP(self):
24 text = r"""span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=xxxx' target='iframe'>xxxx</a></b></strong><small> (TULIP)</small><br>ARR¿T TULIPES / TULIP STOP / MACKENZIE/YORK<br></span>"""
25 match = BusStopMashup._stop_rx.search(text)
26 self.assertNotEquals(match, None)
27 self.assertEquals(match.group("code"), "TULIP")
29 def testCodeTULIP13(self):
30 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=xxxx' target='iframe'>xxxx</a></b></strong><small> (TULIP13)</small><br>ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A<br></span>"""
31 match = BusStopMashup._stop_rx.search(text)
32 self.assertNotEquals(match, None)
33 self.assertEquals(match.group("code"), "TULIP13")
35 # Normally they set it to xxxx, but sometimes it's empty...
36 def testEmpty560Num(self):
37 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=' target='iframe'></a></b></strong><small> (DT005)</small><br>O'CONNOR / SPARKS<br></span>"""
38 match = BusStopMashup._stop_rx.search(text)
39 self.assertNotEquals(match, None)
40 self.assertEquals(match.group("stopnum"), "")
41 self.assertEquals(match.group("code"), "DT005")
43 def testSnowIDWithSpaces(self):
44 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=xxxx' target='iframe'>xxxx</a></b></strong><small> (SNOW - 1)</small><br>ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A<br><a href='iframe.asp?route=&dir=11' target='iframe'></a> </span>"""
45 match = BusStopMashup._stop_rx.search(text)
46 self.assertNotEquals(match, None)
47 self.assertEquals(match.group("code"), "SNOW - 1")
49 def testSnowIDDashInWeirdPlaceMyTaxDollarsAtWork(self):
50 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=xxxx' target='iframe'>xxxx</a></b></strong><small> (SNOW- 26)</small><br>ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A<br><a href='iframe.asp?route=&dir=10' target='iframe'></a> </span>"""
51 match = BusStopMashup._stop_rx.search(text)
52 self.assertNotEquals(match, None)
53 self.assertEquals(match.group("code"), "SNOW- 26")
55 if __name__ == '__main__':
56 unittest.main()