From 1f1fb799aec252ba5dc78a8ae90ce32d254a108e Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 12 Aug 2007 23:01:34 -0400 Subject: [PATCH] Fix some corner cases: mostly tulip fest around Kent & Albert --- BusStopMashup.py | 4 ++-- tests/test_busstopmash_regexes.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/BusStopMashup.py b/BusStopMashup.py index 79d8613..6a904b1 100644 --- a/BusStopMashup.py +++ b/BusStopMashup.py @@ -180,8 +180,8 @@ _station_rx = re.compile(_station_re) # Marker for a regular stop # 613-560-1000 plus 4897 (RA040)
BANK / TRANSITWAY
1 5 111 141 148
-_stop_re = (r'(?i)INFO_PHONE=(?P\w+)' - r'.*\((?P[A-Z]{2,3}[0-9]{3})\)' +_stop_re = (r'(?i)INFO_PHONE=(?P\w*)' + r'.*?\\s*\((?P[A-Z0-9 -]{5,})\)' # The stop name could be BLAH, BLAH / BLAH, BLAH STOP/ARR?T 1A. # Look for some English letters and numbers at the start, then let # anything in. diff --git a/tests/test_busstopmash_regexes.py b/tests/test_busstopmash_regexes.py index cb0c06c..cf86eb6 100755 --- a/tests/test_busstopmash_regexes.py +++ b/tests/test_busstopmash_regexes.py @@ -20,5 +20,37 @@ class TestStopRegex(unittest.TestCase): self.assertNotEquals(match, None) self.assertEquals(match.group("code"), "SCO018") + def testCodeTULIP(self): + text = r"""span>613-560-1000 plus xxxx (TULIP)
ARR¿T TULIPES / TULIP STOP / MACKENZIE/YORK
""" + match = BusStopMashup._stop_rx.search(text) + self.assertNotEquals(match, None) + self.assertEquals(match.group("code"), "TULIP") + + def testCodeTULIP13(self): + text = r"""613-560-1000 plus xxxx (TULIP13)
ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A
""" + match = BusStopMashup._stop_rx.search(text) + self.assertNotEquals(match, None) + self.assertEquals(match.group("code"), "TULIP13") + + # Normally they set it to xxxx, but sometimes it's empty... + def testEmpty560Num(self): + text = r"""613-560-1000 plus (DT005)
O'CONNOR / SPARKS
""" + match = BusStopMashup._stop_rx.search(text) + self.assertNotEquals(match, None) + self.assertEquals(match.group("stopnum"), "") + self.assertEquals(match.group("code"), "DT005") + + def testSnowIDWithSpaces(self): + text = r"""613-560-1000 plus xxxx (SNOW - 1)
ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A
""" + match = BusStopMashup._stop_rx.search(text) + self.assertNotEquals(match, None) + self.assertEquals(match.group("code"), "SNOW - 1") + + def testSnowIDDashInWeirdPlaceMyTaxDollarsAtWork(self): + text = r"""613-560-1000 plus xxxx (SNOW- 26)
ARR¿T TULIPES / TULIP STOP/ N.A.C. / C.N.A
""" + match = BusStopMashup._stop_rx.search(text) + self.assertNotEquals(match, None) + self.assertEquals(match.group("code"), "SNOW- 26") + if __name__ == '__main__': unittest.main() -- 2.11.4.GIT