2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
9 class TestFullRx(unittest
.TestCase
):
11 def testSimpleAddresses(self
):
12 text
= " 101 champagne to 18 auriga "
13 match
= CommandParser
._full
_rx
.match(text
)
14 self
.assertEquals(match
.group("start"), "101 champagne")
15 self
.assertEquals(match
.group("end"), "18 auriga")
17 def testSimpleAddressesWithTime(self
):
18 text
= "101 champagne to 18 auriga at 11:30 pm "
19 match
= CommandParser
._full
_rx
.match(text
)
20 self
.assertEquals(match
.group("start"), "101 champagne")
21 self
.assertEquals(match
.group("end"), "18 auriga")
22 self
.assertEquals(match
.group("rule"), "at")
23 self
.assertEquals(match
.group("time"), "11:30 pm")
25 def testIntersectionWithAtAsSecondLoc(self
):
26 text
= "101 champagne to auriga at antares "
27 match
= CommandParser
._full
_rx
.match(text
)
28 self
.assertEquals(match
.group("start"), "101 champagne")
29 self
.assertEquals(match
.group("end"), "auriga at antares")
31 def testIntersectionWithAtAsSecondLocAndTime(self
):
32 text
= "101 champagne to auriga at antares at 130 "
33 match
= CommandParser
._full
_rx
.match(text
)
34 self
.assertEquals(match
.group("start"), "101 champagne")
35 self
.assertEquals(match
.group("end"), "auriga at antares")
36 self
.assertEquals(match
.group("rule"), "at")
37 self
.assertEquals(match
.group("time"), "130")
39 class TestLocationRxes(unittest
.TestCase
):
40 def testIntersectionRX(self
):
41 text
= "antares at hunt club"
42 match
= CommandParser
._intersection
_rx
.match(text
)
43 self
.assertEquals(match
.group(1), "antares")
44 self
.assertEquals(match
.group(2), "hunt club")
48 match
= CommandParser
._stop
_rx
.match(text
)
49 self
.assertEquals(match
.group(1), "6037")
51 def testStopRXNoStop(self
):
53 match
= CommandParser
._stop
_rx
.match(text
)
54 self
.assertEquals(match
.group(1), "6037")
56 def testStreetAddressRX(self
):
58 self
.assert_(CommandParser
._address
_rx
.match(text
))
60 class TestTimeDecoder(unittest
.TestCase
):
61 def testMorningOneDigit(self
):
62 text
= "stop 6037 to antares and hunt club at 9:30"
63 cmd
= CommandParser
.CommandParser(text
).cmd
64 self
.assertEquals(cmd
.time
.unixtime
, today(9, 30))
65 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
67 def testMorningOneDigitNoColon(self
):
68 text
= "stop 6037 to antares and hunt club at 930"
69 cmd
= CommandParser
.CommandParser(text
).cmd
70 self
.assertEquals(cmd
.time
.unixtime
, today(9, 30))
71 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
73 def testMorningTwoDigits(self
):
74 text
= "stop 6037 to antares and hunt club at 11:30"
75 cmd
= CommandParser
.CommandParser(text
).cmd
76 self
.assertEquals(cmd
.time
.unixtime
, today(11, 30))
77 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
79 def testMorningTwoDigitsNoColon(self
):
80 text
= "stop 6037 to antares and hunt club at 1130"
81 cmd
= CommandParser
.CommandParser(text
).cmd
82 self
.assertEquals(cmd
.time
.unixtime
, today(11, 30))
83 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
86 text
= "stop 6037 to antares and hunt club at 8:30 pm"
87 cmd
= CommandParser
.CommandParser(text
).cmd
88 self
.assertEquals(cmd
.time
.unixtime
, today(20, 30))
89 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
91 def testPMNoColon(self
):
92 text
= "stop 6037 to antares and hunt club at 830 pm"
93 cmd
= CommandParser
.CommandParser(text
).cmd
94 self
.assertEquals(cmd
.time
.unixtime
, today(20, 30))
95 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_LEAVE_AFTER
)
97 def testPMNoMinute(self
):
98 text
= "stop 6037 to antares and hunt club by 9pm"
99 cmd
= CommandParser
.CommandParser(text
).cmd
100 self
.assertEquals(cmd
.time
.unixtime
, today(21, 0))
101 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_ARRIVE_BEFORE
)
103 def testAMNoMinute(self
):
104 text
= "stop 6037 to antares and hunt club by 9"
105 cmd
= CommandParser
.CommandParser(text
).cmd
106 self
.assertEquals(cmd
.time
.unixtime
, today(9, 0))
107 self
.assertEquals(cmd
.time
.constraint
, PlanTime
.MUST_ARRIVE_BEFORE
)
109 def today(hour
, min):
110 t
= list(time
.localtime())
113 return time
.mktime(t
)
115 if __name__
== '__main__':