Script to grab stop codes from allstops.xml and sort
[ottawa-travel-planner.git] / tests / test_busstopmash_regexes.py
bloba4a5b281292df6513db15a61a1bfede812f6a7fb
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 def testWinterludeStopShortCode(self):
56 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=' target='iframe'></a></b></strong><small> (STO)</small><br>WINTERLUDE STOP - ARRÊT<br><a href='iframe.asp?route=&dir=10' target='iframe'></a> </span>"""
57 match = BusStopMashup._stop_rx.search(text)
58 self.assertNotEquals(match, None)
59 self.assertEquals(match.group("code"), "STO")
60 self.assertEquals(match.group("name"), "WINTERLUDE STOP - ARRÊT")
61 self.assertEquals(match.group("stopnum"), "")
63 def testTulipStopAccentedCode(self):
64 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> (SNO CAFÉ)</small><br>ARRÊT TULIPES / TULIP PARC COMMISSIONERS PARK<br></span>"""
65 match = BusStopMashup._stop_rx.search(text)
66 self.assertNotEquals(match, None)
67 self.assertEquals(match.group("code"), "SNO CAFÉ")
68 self.assertEquals(match.group("name"), "ARRÊT TULIPES / TULIP PARC COMMISSIONERS PARK")
69 self.assertEquals(match.group("stopnum"), "xxxx")
71 def testNotreDameHighSchool(self):
72 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=' target='iframe'></a></b></strong><small> (NODE5443)</small><br>É.S. NOTRE DAME H.S.<br></span>"""
73 match = BusStopMashup._stop_rx.search(text)
74 self.assertNotEquals(match, None)
75 self.assertEquals(match.group("code"), "NODE5443")
76 self.assertEquals(match.group("name"), "É.S. NOTRE DAME H.S.")
77 self.assertEquals(match.group("stopnum"), "")
82 class TestStationRx(unittest.TestCase):
83 def testBillingsBridge(self):
84 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=3034' target='iframe'>3034</a><br><a href='iframe.asp?route=bus_station&INFO_PHONE=3034&station_name=BILLINGS BRIDGE&station_id=BIB' target='iframe'>BILLINGS BRIDGE</b></strong></span>"""
85 match = BusStopMashup._station_rx.search(text)
86 self.assertNotEquals(match, None)
87 self.assertEquals(match.group("stopnum"), "3034")
88 self.assertEquals(match.group("name"), "BILLINGS BRIDGE")
89 self.assertEquals(match.group("code"), "BIB")
91 def testSlaterBay(self):
92 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=3005' target='iframe'>3005</a><br><a href='iframe.asp?route=bus_station&INFO_PHONE=3005&station_name=SLATER / BAY&station_id=SLBA' target='iframe'>SLATER / BAY</b></strong></span>"""
93 match = BusStopMashup._station_rx.search(text)
94 self.assertNotEquals(match, None)
95 self.assertEquals(match.group("stopnum"), "3005")
96 self.assertEquals(match.group("name"), "SLATER / BAY")
97 self.assertEquals(match.group("code"), "SLBA")
99 def testTunneysPasture(self):
100 text = r"""<span><strong><b>613-560-1000 plus <a href='iframe.asp?route=busstop&INFO_PHONE=3011' target='iframe'>3011</a><br><a href='iframe.asp?route=bus_station&INFO_PHONE=3011&station_name=TUNNEY'S PASTURE&station_id=TUP' target='iframe'>TUNNEY'S PASTURE</b></strong></span>"""
101 match = BusStopMashup._station_rx.search(text)
102 self.assertNotEquals(match, None)
103 self.assertEquals(match.group("stopnum"), "3011")
104 self.assertEquals(match.group("name"), "TUNNEY'S PASTURE")
105 self.assertEquals(match.group("code"), "TUP")
109 if __name__ == '__main__':
110 unittest.main()