Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(62)

Delta Between Two Patch Sets: python/test/testtransitfeed.py

Issue 75063: Adding validation for uniqueness of service_id X date in calendar_dates SVN Base: http://googletransitdatafeed.googlecode.com/svn/trunk/
Left Patch Set: Adding unit test (from the right directory) Created 5 months ago
Right Patch Set: Removing unnecessary linebreak Created 1 month, 1 week ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #!/usr/bin/python2.5 1 #!/usr/bin/python2.5
2 2
3 # Copyright (C) 2007 Google Inc. 3 # Copyright (C) 2007 Google Inc.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
11 # Unless required by applicable law or agreed to in writing, software 11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, 12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and 14 # See the License for the specific language governing permissions and
15 # limitations under the License. 15 # limitations under the License.
16 16
17 # Unit tests for the transitfeed module. 17 # Unit tests for the transitfeed module.
18 18
19 import datetime 19 import datetime
20 from datetime import date
20 import dircache 21 import dircache
21 import os.path 22 import os.path
22 import re 23 import re
23 import sys 24 import sys
24 import tempfile 25 import tempfile
25 import time 26 import time
26 import traceback 27 import traceback
27 import transitfeed 28 import transitfeed
28 import unittest 29 import unittest
29 from StringIO import StringIO 30 from StringIO import StringIO
30 import zipfile 31 import zipfile
31 import zlib 32 import zlib
32 33
34 import util
33 35
34 def DataPath(path): 36 def DataPath(path):
35 here = os.path.dirname(__file__) 37 here = os.path.dirname(__file__)
36 return os.path.join(here, 'data', path) 38 return os.path.join(here, 'data', path)
37 39
38 def GetDataPathContents(): 40 def GetDataPathContents():
39 here = os.path.dirname(__file__) 41 here = os.path.dirname(__file__)
40 return dircache.listdir(os.path.join(here, 'data')) 42 return dircache.listdir(os.path.join(here, 'data'))
41 43
42 44
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 "ColorLuminance('FFFFFF') should be 255*7 = 1785") 652 "ColorLuminance('FFFFFF') should be 255*7 = 1785")
651 RGBmsg = "ColorLuminance('RRGGBB') should be 2*<Red>+4*<Green>+<Blue>" 653 RGBmsg = "ColorLuminance('RRGGBB') should be 2*<Red>+4*<Green>+<Blue>"
652 self.assertEqual(transitfeed.ColorLuminance('800000'), 2*128, RGBmsg) 654 self.assertEqual(transitfeed.ColorLuminance('800000'), 2*128, RGBmsg)
653 self.assertEqual(transitfeed.ColorLuminance('008000'), 4*128, RGBmsg) 655 self.assertEqual(transitfeed.ColorLuminance('008000'), 4*128, RGBmsg)
654 self.assertEqual(transitfeed.ColorLuminance('000080'), 1*128, RGBmsg) 656 self.assertEqual(transitfeed.ColorLuminance('000080'), 1*128, RGBmsg)
655 self.assertEqual(transitfeed.ColorLuminance('1171B3'), 17*2 + 113*4 + 179*1, 657 self.assertEqual(transitfeed.ColorLuminance('1171B3'), 17*2 + 113*4 + 179*1,
656 RGBmsg) 658 RGBmsg)
657 pass 659 pass
658 660
659 INVALID_VALUE = Exception() 661 INVALID_VALUE = Exception()
660 class ValidationTestCase(unittest.TestCase): 662 class ValidationTestCase(util.TestCaseAsserts):
661 def setUp(self): 663 def setUp(self):
662 self.problems = RecordingProblemReporter(self, ("ExpirationDate",)) 664 self.problems = RecordingProblemReporter(self, ("ExpirationDate",))
663
664 def assertMatchesRegex(self, regex, string):
665 """Assert that regex is found in string."""
666 if not re.search(regex, string):
667 self.fail("string %r did not match regex %r" % (string, regex))
668 665
669 def ExpectNoProblems(self, object): 666 def ExpectNoProblems(self, object):
670 self.problems.AssertNoMoreExceptions() 667 self.problems.AssertNoMoreExceptions()
671 object.Validate(self.problems) 668 object.Validate(self.problems)
672 self.problems.AssertNoMoreExceptions() 669 self.problems.AssertNoMoreExceptions()
673 670
674 # TODO: Get rid of Expect*Closure methods. With the 671 # TODO: Get rid of Expect*Closure methods. With the
675 # RecordingProblemReporter it is now possible to replace 672 # RecordingProblemReporter it is now possible to replace
676 # self.ExpectMissingValueInClosure(lambda: o.method(...), foo) 673 # self.ExpectMissingValueInClosure(lambda: o.method(...), foo)
677 # with 674 # with
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 lambda: transitfeed.StopTime(self.problems, stop, 1045 lambda: transitfeed.StopTime(self.problems, stop,
1049 arrival_time="10:60:00", 1046 arrival_time="10:60:00",
1050 departure_time="11:02:00")) 1047 departure_time="11:02:00"))
1051 # The following should work 1048 # The following should work
1052 transitfeed.StopTime(self.problems, stop, arrival_time="10:00:00", 1049 transitfeed.StopTime(self.problems, stop, arrival_time="10:00:00",
1053 departure_time="10:05:00", pickup_type='1', drop_off_type='1') 1050 departure_time="10:05:00", pickup_type='1', drop_off_type='1')
1054 transitfeed.StopTime(self.problems, stop, arrival_time="1:00:00", 1051 transitfeed.StopTime(self.problems, stop, arrival_time="1:00:00",
1055 departure_time="1:05:00") 1052 departure_time="1:05:00")
1056 transitfeed.StopTime(self.problems, stop, arrival_time="24:59:00", 1053 transitfeed.StopTime(self.problems, stop, arrival_time="24:59:00",
1057 departure_time="25:05:00") 1054 departure_time="25:05:00")
1055 transitfeed.StopTime(self.problems, stop, arrival_time="101:01:00",
1056 departure_time="101:21:00")
1058 transitfeed.StopTime(self.problems, stop) 1057 transitfeed.StopTime(self.problems, stop)
1059 self.problems.AssertNoMoreExceptions() 1058 self.problems.AssertNoMoreExceptions()
1060 1059
1060 class TravelSpeedTestCase(ValidationTestCase):
1061 def runTest(self):
1062 schedule = transitfeed.Schedule(problem_reporter=self.problems)
1063 schedule.NewDefaultAgency(agency_name="Test Agency",
1064 agency_url="http://example.com",
1065 agency_timezone="America/Los_Angeles")
1066 route = schedule.AddRoute(short_name="54C", long_name="Polish Hill", route_t ype=3)
1067
1068 service_period = schedule.GetDefaultServicePeriod()
1069 service_period.SetDateHasService("20070101")
1070
1071 trip = route.AddTrip(schedule, 'via Polish Hill')
1072
1073 stop1 = schedule.AddStop(36.425288, -117.133162, "Demo Stop 1")
1074 stop2 = schedule.AddStop(36.440466, -117.132463, "Demo Stop 2")
1075 stop3 = schedule.AddStop(36.425999, -117.133999, "Demo Stop 3")
1076
1077 trip.AddStopTime(stop1, stop_time="12:00:00")
1078 trip.AddStopTime(stop2, stop_time="12:01:00")
1079 trip.AddStopTime(stop3, stop_time="12:02:00")
1080 trip.AddStopTime(stop1, stop_time="12:02:00")
1081
1082 trip.Validate(self.problems)
1083 e = self.problems.PopException('TooFastTravel')
1084 self.assertTrue(e.FormatProblem().find('High speed travel detected') != -1)
1085 self.assertTrue(e.FormatProblem().find('Stop 1 to Demo Stop 2') != -1)
1086 self.assertTrue(e.FormatProblem().find('1690 meters in 60 seconds') != -1)
1087 self.assertTrue(e.FormatProblem().find('(101.445967 km/h)') != -1)
1088 self.assertEqual(e.type, transitfeed.TYPE_WARNING)
1089 e = self.problems.PopException('TooFastTravel')
1090 self.assertTrue(e.FormatProblem().find('High speed travel detected') != -1)
1091 self.assertTrue(e.FormatProblem().find('Stop 3 to Demo Stop 1') != -1)
1092 self.assertTrue(e.FormatProblem().find('109 meters in 0 seconds') != -1)
1093 self.assertEqual(e.type, transitfeed.TYPE_WARNING)
1094 self.problems.AssertNoMoreExceptions()
1095
1096 # Run test without a route_type
1097 route.route_type = None
1098 trip.Validate(self.problems)
1099 e = self.problems.PopException('TooFastTravel')
1100 self.assertTrue(e.FormatProblem().find('High speed travel detected') != -1)
1101 self.assertTrue(e.FormatProblem().find('Stop 1 to Demo Stop 2') != -1)
1102 self.assertTrue(e.FormatProblem().find('1690 meters in 60 seconds') != -1)
1103 self.assertTrue(e.FormatProblem().find('(101.445967 km/h)') != -1)
1104 self.assertEqual(e.type, transitfeed.TYPE_WARNING)
1105 e = self.problems.PopException('TooFastTravel')
1106 self.assertTrue(e.FormatProblem().find('High speed travel detected') != -1)
1107 self.assertTrue(e.FormatProblem().find('Stop 2 to Demo Stop 3') != -1)
1108 self.assertTrue(e.FormatProblem().find('1616 meters in 60 seconds') != -1)
1109 self.assertTrue(e.FormatProblem().find('(96.979408 km/h)') != -1)
1110 self.assertEqual(e.type, transitfeed.TYPE_WARNING)
1111 e = self.problems.PopException('TooFastTravel')
1112 self.assertTrue(e.FormatProblem().find('High speed travel detected') != -1)
1113 self.assertTrue(e.FormatProblem().find('Stop 3 to Demo Stop 1') != -1)
1114 self.assertTrue(e.FormatProblem().find('109 meters in 0 seconds') != -1)
1115 self.assertEqual(e.type, transitfeed.TYPE_WARNING)
1116 self.problems.AssertNoMoreExceptions()
1061 1117
1062 class MemoryZipTestCase(unittest.TestCase): 1118 class MemoryZipTestCase(unittest.TestCase):
1063 def setUp(self): 1119 def setUp(self):
1064 self.problems = RecordingProblemReporter(self, ("ExpirationDate",)) 1120 self.problems = RecordingProblemReporter(self, ("ExpirationDate",))
1065 self.zipfile = StringIO() 1121 self.zipfile = StringIO()
1066 self.zip = zipfile.ZipFile(self.zipfile, 'a') 1122 self.zip = zipfile.ZipFile(self.zipfile, 'a')
1067 self.zip.writestr( 1123 self.zip.writestr(
1068 "agency.txt", 1124 "agency.txt",
1069 "agency_id,agency_name,agency_url,agency_timezone\n" 1125 "agency_id,agency_name,agency_url,agency_timezone\n"
1070 "DTA,Demo Agency,http://google.com,America/Los_Angeles\n") 1126 "DTA,Demo Agency,http://google.com,America/Los_Angeles\n")
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 self.assertEquals("parent_station", e.column_name) 1487 self.assertEquals("parent_station", e.column_name)
1432 self.assertTrue(e.FormatProblem().find("location_type=1") != -1) 1488 self.assertTrue(e.FormatProblem().find("location_type=1") != -1)
1433 self.problems.AssertNoMoreExceptions() 1489 self.problems.AssertNoMoreExceptions()
1434 1490
1435 def testStationWithParent(self): 1491 def testStationWithParent(self):
1436 self.zip.writestr( 1492 self.zip.writestr(
1437 "stops.txt", 1493 "stops.txt",
1438 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n" 1494 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1439 "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,STATION\n" 1495 "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,STATION\n"
1440 "STATION,Airport,36.868446,-116.784582,1,STATION2\n" 1496 "STATION,Airport,36.868446,-116.784582,1,STATION2\n"
1441 "STATION2,Airport 2,40.868446,-116.784582,1,\n" 1497 "STATION2,Airport 2,36.868000,-116.784000,1,\n"
1442 "BULLFROG,Bullfrog,36.88108,-116.81797,,STATION2\n" 1498 "BULLFROG,Bullfrog,36.868088,-116.784797,,STATION2\n"
1443 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n") 1499 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n")
1444 schedule = self.loader.Load() 1500 schedule = self.loader.Load()
1445 e = self.problems.PopException("InvalidValue") 1501 e = self.problems.PopException("InvalidValue")
1446 self.assertEquals("parent_station", e.column_name) 1502 self.assertEquals("parent_station", e.column_name)
1447 self.assertEquals(3, e.row_num) 1503 self.assertEquals(3, e.row_num)
1448 self.problems.AssertNoMoreExceptions() 1504 self.problems.AssertNoMoreExceptions()
1449 1505
1450 def testStationWithSelfParent(self): 1506 def testStationWithSelfParent(self):
1451 self.zip.writestr( 1507 self.zip.writestr(
1452 "stops.txt", 1508 "stops.txt",
1453 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n" 1509 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1454 "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,STATION\n" 1510 "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,STATION\n"
1455 "STATION,Airport,36.868446,-116.784582,1,STATION\n" 1511 "STATION,Airport,36.868446,-116.784582,1,STATION\n"
1456 "BULLFROG,Bullfrog,36.88108,-116.81797,,\n" 1512 "BULLFROG,Bullfrog,36.88108,-116.81797,,\n"
1457 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n") 1513 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n")
1458 schedule = self.loader.Load() 1514 schedule = self.loader.Load()
1459 e = self.problems.PopException("InvalidValue") 1515 e = self.problems.PopException("InvalidValue")
1460 self.assertEquals("parent_station", e.column_name) 1516 self.assertEquals("parent_station", e.column_name)
1461 self.assertEquals(3, e.row_num) 1517 self.assertEquals(3, e.row_num)
1518 self.problems.AssertNoMoreExceptions()
1519
1520 def testStopNearToNonParentStation(self):
1521 self.zip.writestr(
1522 "stops.txt",
1523 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1524 "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,\n"
1525 "BULLFROG,Bullfrog,36.868446,-116.784582,,\n"
1526 "BULLFROG_ST,Bullfrog,36.868446,-116.784582,1,\n"
1527 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n")
1528 schedule = self.loader.Load()
1529 e = self.problems.PopException("OtherProblem")
1530 self.assertTrue(e.FormatProblem().find(
1531 "The parent_station of stop \"Bullfrog\"") != -1)
1532 e = self.problems.PopException("OtherProblem")
1533 e = self.problems.PopException("OtherProblem")
1534 self.assertTrue(e.FormatProblem().find(
1535 "The parent_station of stop \"Airport\"") != -1)
1536 self.problems.AssertNoMoreExceptions()
1537
1538 def testStopTooFarFromParentStation(self):
1539 self.zip.writestr(
1540 "stops.txt",
1541 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1542 "BULLFROG_ST,Bullfrog,36.880,-116.817,1,\n" # Parent station of all.
1543 "BEATTY_AIRPORT,Airport,36.880,-116.816,,BULLFROG_ST\n" # ~ 90m far
1544 "BULLFROG,Bullfrog,36.881,-116.818,,BULLFROG_ST\n" # ~ 150m far
1545 "STAGECOACH,Stagecoach,36.915,-116.751,,BULLFROG_ST\n") # > 3km far
1546 schedule = self.loader.Load()
1547 e = self.problems.PopException("StopTooFarFromParentStation")
1548 self.assertEqual(1, e.type) # Warning
1549 self.assertTrue(e.FormatProblem().find(
1550 "Bullfrog (ID BULLFROG) is too far from its parent"
1551 " station Bullfrog (ID BULLFROG_ST)") != -1)
1552 e = self.problems.PopException("StopTooFarFromParentStation")
1553 self.assertEqual(0, e.type) # Error
1554 self.assertTrue(e.FormatProblem().find(
1555 "Stagecoach (ID STAGECOACH) is too far from its parent"
1556 " station Bullfrog (ID BULLFROG_ST)") != -1)
1462 self.problems.AssertNoMoreExceptions() 1557 self.problems.AssertNoMoreExceptions()
1463 1558
1464 #Uncomment once validation is implemented 1559 #Uncomment once validation is implemented
1465 #def testStationWithoutReference(self): 1560 #def testStationWithoutReference(self):
1466 # self.zip.writestr( 1561 # self.zip.writestr(
1467 # "stops.txt", 1562 # "stops.txt",
1468 # "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n" 1563 # "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1469 # "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,\n" 1564 # "BEATTY_AIRPORT,Airport,36.868446,-116.784582,,\n"
1470 # "STATION,Airport,36.868446,-116.784582,1,\n" 1565 # "STATION,Airport,36.868446,-116.784582,1,\n"
1471 # "BULLFROG,Bullfrog,36.88108,-116.81797,,\n" 1566 # "BULLFROG,Bullfrog,36.88108,-116.81797,,\n"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 self.problems.AssertNoMoreExceptions() 1642 self.problems.AssertNoMoreExceptions()
1548 1643
1549 1644
1550 class StopsNearEachOther(MemoryZipTestCase): 1645 class StopsNearEachOther(MemoryZipTestCase):
1551 def testTooNear(self): 1646 def testTooNear(self):
1552 self.zip.writestr( 1647 self.zip.writestr(
1553 "stops.txt", 1648 "stops.txt",
1554 "stop_id,stop_name,stop_lat,stop_lon\n" 1649 "stop_id,stop_name,stop_lat,stop_lon\n"
1555 "BEATTY_AIRPORT,Airport,48.20000,140\n" 1650 "BEATTY_AIRPORT,Airport,48.20000,140\n"
1556 "BULLFROG,Bullfrog,48.20001,140\n" 1651 "BULLFROG,Bullfrog,48.20001,140\n"
1557 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677\n") 1652 "STAGECOACH,Stagecoach Hotel,48.20016,140\n")
1558 schedule = self.loader.Load() 1653 schedule = self.loader.Load()
1559 e = self.problems.PopException('OtherProblem') 1654 e = self.problems.PopException('OtherProblem')
1560 self.assertTrue(e.FormatProblem().find("1.11m apart") != -1) 1655 self.assertTrue(e.FormatProblem().find("1.11m apart") != -1)
1561 self.problems.AssertNoMoreExceptions() 1656 self.problems.AssertNoMoreExceptions()
1562 1657
1563 def testJustFarEnough(self): 1658 def testJustFarEnough(self):
1564 self.zip.writestr( 1659 self.zip.writestr(
1565 "stops.txt", 1660 "stops.txt",
1566 "stop_id,stop_name,stop_lat,stop_lon\n" 1661 "stop_id,stop_name,stop_lat,stop_lon\n"
1567 "BEATTY_AIRPORT,Airport,48.20000,140\n" 1662 "BEATTY_AIRPORT,Airport,48.20000,140\n"
1568 "BULLFROG,Bullfrog,48.20002,140\n" 1663 "BULLFROG,Bullfrog,48.20002,140\n"
1569 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677\n") 1664 "STAGECOACH,Stagecoach Hotel,48.20016,140\n")
1570 schedule = self.loader.Load() 1665 schedule = self.loader.Load()
1571 # Stops are 2.2m apart 1666 # Stops are 2.2m apart
1572 self.problems.AssertNoMoreExceptions() 1667 self.problems.AssertNoMoreExceptions()
1573 1668
1574 def testSameLocation(self): 1669 def testSameLocation(self):
1575 self.zip.writestr( 1670 self.zip.writestr(
1576 "stops.txt", 1671 "stops.txt",
1577 "stop_id,stop_name,stop_lat,stop_lon\n" 1672 "stop_id,stop_name,stop_lat,stop_lon\n"
1578 "BEATTY_AIRPORT,Airport,48.2,140\n" 1673 "BEATTY_AIRPORT,Airport,48.2,140\n"
1579 "BULLFROG,Bullfrog,48.2,140\n" 1674 "BULLFROG,Bullfrog,48.2,140\n"
1580 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677\n") 1675 "STAGECOACH,Stagecoach Hotel,48.20016,140\n")
1581 schedule = self.loader.Load() 1676 schedule = self.loader.Load()
1582 e = self.problems.PopException('OtherProblem') 1677 e = self.problems.PopException('OtherProblem')
1583 self.assertTrue(e.FormatProblem().find("0.00m apart") != -1) 1678 self.assertTrue(e.FormatProblem().find("0.00m apart") != -1)
1584 self.problems.AssertNoMoreExceptions() 1679 self.problems.AssertNoMoreExceptions()
1585 1680
1586 def testStationsTooNear(self): 1681 def testStationsTooNear(self):
1587 self.zip.writestr( 1682 self.zip.writestr(
1588 "stops.txt", 1683 "stops.txt",
1589 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n" 1684 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1590 "BEATTY_AIRPORT,Airport,48.20000,140,,BEATTY_AIRPORT_STATION\n" 1685 "BEATTY_AIRPORT,Airport,48.20000,140,,BEATTY_AIRPORT_STATION\n"
1591 "BULLFROG,Bullfrog,48.20003,140,,BULLFROG_STATION\n" 1686 "BULLFROG,Bullfrog,48.20003,140,,BULLFROG_STATION\n"
1592 "BEATTY_AIRPORT_STATION,Airport,48.20001,140,1,\n" 1687 "BEATTY_AIRPORT_STATION,Airport,48.20001,140,1,\n"
1593 "BULLFROG_STATION,Bullfrog,48.20002,140,1,\n" 1688 "BULLFROG_STATION,Bullfrog,48.20002,140,1,\n"
1594 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n") 1689 "STAGECOACH,Stagecoach Hotel,48.20016,140,,\n")
1595 schedule = self.loader.Load() 1690 schedule = self.loader.Load()
1596 e = self.problems.PopException('OtherProblem') 1691 e = self.problems.PopException('OtherProblem')
1597 self.assertTrue(e.FormatProblem().find("1.11m apart") != -1) 1692 self.assertTrue(e.FormatProblem().find("1.11m apart") != -1)
1598 self.assertTrue(e.FormatProblem().find("BEATTY_AIRPORT_STATION") != -1) 1693 self.assertTrue(e.FormatProblem().find("BEATTY_AIRPORT_STATION") != -1)
1599 self.problems.AssertNoMoreExceptions() 1694 self.problems.AssertNoMoreExceptions()
1600 1695
1601 def testStopNearNonParentStation(self): 1696 def testStopNearNonParentStation(self):
1602 self.zip.writestr( 1697 self.zip.writestr(
1603 "stops.txt", 1698 "stops.txt",
1604 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n" 1699 "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station\n"
1605 "BEATTY_AIRPORT,Airport,48.20000,140,,\n" 1700 "BEATTY_AIRPORT,Airport,48.20000,140,,\n"
1606 "BULLFROG,Bullfrog,48.20005,140,,\n" 1701 "BULLFROG,Bullfrog,48.20005,140,,\n"
1607 "BULLFROG_STATION,Bullfrog,48.20006,140,1,\n" 1702 "BULLFROG_STATION,Bullfrog,48.20006,140,1,\n"
1608 "STAGECOACH,Stagecoach Hotel,36.915682,-116.751677,,\n") 1703 "STAGECOACH,Stagecoach Hotel,48.20016,140,,\n")
1609 schedule = self.loader.Load() 1704 schedule = self.loader.Load()
1610 e = self.problems.PopException('OtherProblem') 1705 e = self.problems.PopException('OtherProblem')
1611 fmt = e.FormatProblem() 1706 fmt = e.FormatProblem()
1612 self.assertTrue(re.search( 1707 self.assertTrue(re.search(
1613 r"parent_station of.*BULLFROG.*station.*BULLFROG_STATION.* 1.11m apart", 1708 r"parent_station of.*BULLFROG.*station.*BULLFROG_STATION.* 1.11m apart",
1614 fmt), fmt) 1709 fmt), fmt)
1615 self.problems.AssertNoMoreExceptions() 1710 self.problems.AssertNoMoreExceptions()
1616 1711
1617 1712
1618 class BadLatLonInStopUnitTest(ValidationTestCase): 1713 class BadLatLonInStopUnitTest(ValidationTestCase):
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 self.assertFalse(period_no_end.IsActiveOn('20071231')) 2438 self.assertFalse(period_no_end.IsActiveOn('20071231'))
2344 self.assertEquals(period_no_end.ActiveDates(), []) 2439 self.assertEquals(period_no_end.ActiveDates(), [])
2345 period_no_start = transitfeed.ServicePeriod() 2440 period_no_start = transitfeed.ServicePeriod()
2346 period_no_start.end_date = '20071230' 2441 period_no_start.end_date = '20071230'
2347 self.assertFalse(period_no_start.IsActiveOn('20071229')) 2442 self.assertFalse(period_no_start.IsActiveOn('20071229'))
2348 self.assertEquals(period_no_start.ActiveDates(), []) 2443 self.assertEquals(period_no_start.ActiveDates(), [])
2349 2444
2350 period_empty = transitfeed.ServicePeriod() 2445 period_empty = transitfeed.ServicePeriod()
2351 self.assertFalse(period_empty.IsActiveOn('20071231')) 2446 self.assertFalse(period_empty.IsActiveOn('20071231'))
2352 self.assertEquals(period_empty.ActiveDates(), []) 2447 self.assertEquals(period_empty.ActiveDates(), [])
2448
2449
2450 class GetServicePeriodsActiveEachDateTestCase(unittest.TestCase):
2451 def testEmpty(self):
2452 schedule = transitfeed.Schedule()
2453 self.assertEquals(
2454 [],
2455 schedule.GetServicePeriodsActiveEachDate(date(2009, 1, 1),
2456 date(2009, 1, 1)))
2457 self.assertEquals(
2458 [(date(2008, 12, 31), []), (date(2009, 1, 1), [])],
2459 schedule.GetServicePeriodsActiveEachDate(date(2008, 12, 31),
2460 date(2009, 1, 2)))
2461 def testOneService(self):
2462 schedule = transitfeed.Schedule()
2463 sp1 = transitfeed.ServicePeriod()
2464 sp1.service_id = "sp1"
2465 sp1.SetDateHasService("20090101")
2466 sp1.SetDateHasService("20090102")
2467 schedule.AddServicePeriodObject(sp1)
2468 self.assertEquals(
2469 [],
2470 schedule.GetServicePeriodsActiveEachDate(date(2009, 1, 1),
2471 date(2009, 1, 1)))
2472 self.assertEquals(
2473 [(date(2008, 12, 31), []), (date(2009, 1, 1), [sp1])],
2474 schedule.GetServicePeriodsActiveEachDate(date(2008, 12, 31),
2475 date(2009, 1, 2)))
2476
2477 def testTwoService(self):
2478 schedule = transitfeed.Schedule()
2479 sp1 = transitfeed.ServicePeriod()
2480 sp1.service_id = "sp1"
2481 sp1.SetDateHasService("20081231")
2482 sp1.SetDateHasService("20090101")
2483
2484 schedule.AddServicePeriodObject(sp1)
2485 sp2 = transitfeed.ServicePeriod()
2486 sp2.service_id = "sp2"
2487 sp2.SetStartDate("20081201")
2488 sp2.SetEndDate("20081231")
2489 sp2.SetWeekendService()
2490 sp2.SetWeekdayService()
2491 schedule.AddServicePeriodObject(sp2)
2492 self.assertEquals(
2493 [],
2494 schedule.GetServicePeriodsActiveEachDate(date(2009, 1, 1),
2495 date(2009, 1, 1)))
2496 date_services = schedule.GetServicePeriodsActiveEachDate(date(2008, 12, 31),
2497 date(2009, 1, 2))
2498 self.assertEquals(
2499 [date(2008, 12, 31), date(2009, 1, 1)], [d for d, _ in date_services])
2500 self.assertEquals(set([sp1, sp2]), set(date_services[0][1]))
2501 self.assertEquals([sp1], date_services[1][1])
2353 2502
2354 2503
2355 class TripMemoryZipTestCase(MemoryZipTestCase): 2504 class TripMemoryZipTestCase(MemoryZipTestCase):
2356 def assertLoadAndCheckExtraValues(self, schedule_file): 2505 def assertLoadAndCheckExtraValues(self, schedule_file):
2357 """Load file-like schedule_file and check for extra trip columns.""" 2506 """Load file-like schedule_file and check for extra trip columns."""
2358 load_problems = TestFailureProblemReporter( 2507 load_problems = TestFailureProblemReporter(
2359 self, ("ExpirationDate", "UnrecognizedColumn")) 2508 self, ("ExpirationDate", "UnrecognizedColumn"))
2360 loaded_schedule = transitfeed.Loader(schedule_file, 2509 loaded_schedule = transitfeed.Loader(schedule_file,
2361 problems=load_problems, 2510 problems=load_problems,
2362 extra_validation=True).Load() 2511 extra_validation=True).Load()
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 stop2 = transitfeed.Stop(36.424288, -117.158142, "Demo Stop 2", "STOP2") 2971 stop2 = transitfeed.Stop(36.424288, -117.158142, "Demo Stop 2", "STOP2")
2823 schedule.AddStopObject(stop2) 2972 schedule.AddStopObject(stop2)
2824 trip1.AddStopTime(stop2, arrival_time="5:15:00", departure_time="5:16:00", 2973 trip1.AddStopTime(stop2, arrival_time="5:15:00", departure_time="5:16:00",
2825 stop_sequence=1, shape_dist_traveled=1) 2974 stop_sequence=1, shape_dist_traveled=1)
2826 trip2.AddStopTime(stop2, arrival_time="5:25:00", departure_time="5:26:00", 2975 trip2.AddStopTime(stop2, arrival_time="5:25:00", departure_time="5:26:00",
2827 stop_sequence=1, shape_dist_traveled=1) 2976 stop_sequence=1, shape_dist_traveled=1)
2828 trip3.AddStopTime(stop2, arrival_time="6:15:00", departure_time="6:16:00", 2977 trip3.AddStopTime(stop2, arrival_time="6:15:00", departure_time="6:16:00",
2829 stop_sequence=0, shape_dist_traveled=0) 2978 stop_sequence=0, shape_dist_traveled=0)
2830 2979
2831 schedule.Validate(self.problems) 2980 schedule.Validate(self.problems)
2832 e = self.problems.PopException('OtherProblem') 2981 e = self.problems.PopException('DuplicateTrip')
2833 self.assertTrue(e.FormatProblem().find('t1 of route') != -1) 2982 self.assertTrue(e.FormatProblem().find('t1 of route') != -1)
2834 self.assertTrue(e.FormatProblem().find('t2 of route') != -1) 2983 self.assertTrue(e.FormatProblem().find('t2 of route') != -1)
2835 self.problems.AssertNoMoreExceptions() 2984 self.problems.AssertNoMoreExceptions()
2836 2985
2986
2987 class StopBelongsToBothSubwayAndBusTestCase(ValidationTestCase):
2988 def runTest(self):
2989 schedule = transitfeed.Schedule(self.problems)
2990
2991 schedule.AddAgency("Demo Agency", "http://example.com",
2992 "America/Los_Angeles")
2993 route1 = schedule.AddRoute(short_name="route1", long_name="route_1",
2994 route_type=3)
2995 route2 = schedule.AddRoute(short_name="route2", long_name="route_2",
2996 route_type=1)
2997
2998 service = schedule.GetDefaultServicePeriod()
2999 service.SetDateHasService("20070101")
3000
3001 trip1 = route1.AddTrip(schedule, "trip1", service, "t1")
3002 trip2 = route2.AddTrip(schedule, "trip2", service, "t2")
3003
3004 stop1 = schedule.AddStop(36.425288, -117.133162, "stop1")
3005 stop2 = schedule.AddStop(36.424288, -117.133142, "stop2")
3006 stop3 = schedule.AddStop(36.423288, -117.134142, "stop3")
3007
3008 trip1.AddStopTime(stop1, arrival_time="5:11:00", departure_time="5:12:00")
3009 trip1.AddStopTime(stop2, arrival_time="5:21:00", departure_time="5:22:00")
3010
3011 trip2.AddStopTime(stop1, arrival_time="6:11:00", departure_time="6:12:00")
3012 trip2.AddStopTime(stop3, arrival_time="6:21:00", departure_time="6:22:00")
3013
3014 schedule.Validate(self.problems)
3015 e = self.problems.PopException("StopWithMultipleRouteTypes")
3016 self.assertTrue(e.FormatProblem().find("Stop stop1") != -1)
3017 self.assertTrue(e.FormatProblem().find("subway (ID=1)") != -1)
3018 self.assertTrue(e.FormatProblem().find("bus line (ID=0)") != -1)
3019 self.problems.AssertNoMoreExceptions()
3020
3021
2837 class TripReplaceStopTimeObjectTestCase(unittest.TestCase): 3022 class TripReplaceStopTimeObjectTestCase(unittest.TestCase):
2838 def runTest(self): 3023 def runTest(self):
2839 schedule = transitfeed.Schedule() 3024 schedule = transitfeed.Schedule()
2840 schedule.AddAgency("\xc8\x8b Fly Agency", "http://iflyagency.com", 3025 schedule.AddAgency("\xc8\x8b Fly Agency", "http://iflyagency.com",
2841 "America/Los_Angeles") 3026 "America/Los_Angeles")
2842 service_period = \ 3027 service_period = \
2843 schedule.GetDefaultServicePeriod().SetDateHasService('20070101') 3028 schedule.GetDefaultServicePeriod().SetDateHasService('20070101')
2844 stop1 = schedule.AddStop(lng=140, lat=48.2, name="Stop 1") 3029 stop1 = schedule.AddStop(lng=140, lat=48.2, name="Stop 1")
2845 route = schedule.AddRoute("B", "Beta", "Bus") 3030 route = schedule.AddRoute("B", "Beta", "Bus")
2846 trip = route.AddTrip(schedule, "bus trip") 3031 trip = route.AddTrip(schedule, "bus trip")
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 self.problems.AssertNoMoreExceptions() 3205 self.problems.AssertNoMoreExceptions()
3021 3206
3022 3207
3023 3208
3024 class OnlyCalendarDatesTestCase(LoadTestCase): 3209 class OnlyCalendarDatesTestCase(LoadTestCase):
3025 def runTest(self): 3210 def runTest(self):
3026 self.Load('only_calendar_dates'), 3211 self.Load('only_calendar_dates'),
3027 self.problems.AssertNoMoreExceptions() 3212 self.problems.AssertNoMoreExceptions()
3028 3213
3029 3214
3030 class DuplicateServiceIdDateWarningTestCase(LoadTestCase): 3215 class DuplicateServiceIdDateWarningTestCase(MemoryZipTestCase):
3031 def runTest(self): 3216 def runTest(self):
3032 self.Load('duplicate_service_id_date') 3217 # Two lines with the same value of service_id and date.
3033 e = self.problems.PopException("DuplicateID") 3218 # Test for the warning.
3034 self.assertEquals(2, len(e.column_names)) 3219 self.zip.writestr(
3035 self.assertEquals("service_id", e.column_names[0]) 3220 'calendar_dates.txt',
3036 self.assertEquals("date", e.column_names[1]) 3221 'service_id,date,exception_type\n'
3222 'FULLW,20100604,1\n'
3223 'FULLW,20100604,2\n')
3224 schedule = self.loader.Load()
3225 e = self.problems.PopException('DuplicateID')
3226 self.assertEquals('(service_id, date)', e.column_name)
3227 self.assertEquals('(FULLW, 20100604)', e.value)
3228
3037 3229
3038 class AddStopTimeParametersTestCase(unittest.TestCase): 3230 class AddStopTimeParametersTestCase(unittest.TestCase):
3039 def runTest(self): 3231 def runTest(self):
3040 problem_reporter = TestFailureProblemReporter(self) 3232 problem_reporter = TestFailureProblemReporter(self)
3041 schedule = transitfeed.Schedule(problem_reporter=problem_reporter) 3233 schedule = transitfeed.Schedule(problem_reporter=problem_reporter)
3042 route = schedule.AddRoute(short_name="10", long_name="", route_type="Bus") 3234 route = schedule.AddRoute(short_name="10", long_name="", route_type="Bus")
3043 stop = schedule.AddStop(40, -128, "My stop") 3235 stop = schedule.AddStop(40, -128, "My stop")
3044 # Stop must be added to schedule so that the call 3236 # Stop must be added to schedule so that the call
3045 # AddStopTime -> AddStopTimeObject -> GetStopTimes -> GetStop can work 3237 # AddStopTime -> AddStopTimeObject -> GetStopTimes -> GetStop can work
3046 trip = transitfeed.Trip() 3238 trip = transitfeed.Trip()
3047 trip.route_id = route.route_id 3239 trip.route_id = route.route_id
3048 trip.service_id = schedule.GetDefaultServicePeriod().service_id 3240 trip.service_id = schedule.GetDefaultServicePeriod().service_id
3049 trip.trip_id = "SAMPLE_TRIP" 3241 trip.trip_id = "SAMPLE_TRIP"
3050 schedule.AddTripObject(trip) 3242 schedule.AddTripObject(trip)
3051 3243
3052 # First stop must have time 3244 # First stop must have time
3053 trip.AddStopTime(stop, arrival_secs=300, departure_secs=360) 3245 trip.AddStopTime(stop, arrival_secs=300, departure_secs=360)
3054 trip.AddStopTime(stop) 3246 trip.AddStopTime(stop)
3055 trip.AddStopTime(stop, arrival_time="00:07:00", departure_time="00:07:30") 3247 trip.AddStopTime(stop, arrival_time="00:07:00", departure_time="00:07:30")
3056 trip.Validate(problem_reporter) 3248 trip.Validate(problem_reporter)
3057 3249
3058 3250
3059 class ExpirationDateTestCase(unittest.TestCase): 3251 class ExpirationDateTestCase(unittest.TestCase):
3060 def runTest(self): 3252 def runTest(self):
3061 schedule = transitfeed.Schedule( 3253 problems = RecordingProblemReporter(self)
3062 problem_reporter=transitfeed.ExceptionProblemReporter( 3254 schedule = transitfeed.Schedule(problem_reporter=problems)
3063 raise_warnings=True))
3064 3255
3065 now = time.mktime(time.localtime()) 3256 now = time.mktime(time.localtime())
3066 seconds_per_day = 60 * 60 * 24 3257 seconds_per_day = 60 * 60 * 24
3067 two_weeks_ago = time.localtime(now - 14 * seconds_per_day) 3258 two_weeks_ago = time.localtime(now - 14 * seconds_per_day)
3068 two_weeks_from_now = time.localtime(now + 14 * seconds_per_day) 3259 two_weeks_from_now = time.localtime(now + 14 * seconds_per_day)
3069 two_months_from_now = time.localtime(now + 60 * seconds_per_day) 3260 two_months_from_now = time.localtime(now + 60 * seconds_per_day)
3070 date_format = "%Y%m%d" 3261 date_format = "%Y%m%d"
3071 3262
3072 service_period = schedule.GetDefaultServicePeriod() 3263 service_period = schedule.GetDefaultServicePeriod()
3073 service_period.SetWeekdayService(True) 3264 service_period.SetWeekdayService(True)
3074 service_period.SetStartDate("20070101") 3265 service_period.SetStartDate("20070101")
3266
3075 service_period.SetEndDate(time.strftime(date_format, two_months_from_now)) 3267 service_period.SetEndDate(time.strftime(date_format, two_months_from_now))
3076
3077 schedule.Validate() # should have no problems 3268 schedule.Validate() # should have no problems
3269 problems.AssertNoMoreExceptions()
3078 3270
3079 service_period.SetEndDate(time.strftime(date_format, two_weeks_from_now)) 3271 service_period.SetEndDate(time.strftime(date_format, two_weeks_from_now))
3080 3272 schedule.Validate()
3081 try: 3273 e = problems.PopException('ExpirationDate')
3082 schedule.Validate() 3274 self.assertTrue(e.FormatProblem().index('will soon expire'))
3083 self.fail('ExpirationDate exception expected') 3275 problems.AssertNoMoreExceptions()
3084 except transitfeed.ExpirationDate, e:
3085 # raises exception if not found
3086 e.FormatProblem().index('will soon expire')
3087 3276
3088 service_period.SetEndDate(time.strftime(date_format, two_weeks_ago)) 3277 service_period.SetEndDate(time.strftime(date_format, two_weeks_ago))
3089 3278 schedule.Validate()
3090 try: 3279 e = problems.PopException('ExpirationDate')
3091 schedule.Validate() 3280 self.assertTrue(e.FormatProblem().index('expired'))
3092 self.fail('ExpirationDate exception expected') 3281 problems.AssertNoMoreExceptions()
3093 except transitfeed.ExpirationDate, e: 3282
3094 # raises exception if not found 3283
3095 e.FormatProblem().index('expired') 3284 class FutureServiceStartDateTestCase(unittest.TestCase):
3285 def runTest(self):
3286 problems = RecordingProblemReporter(self)
3287 schedule = transitfeed.Schedule(problem_reporter=problems)
3288
3289 today = datetime.date.today()
3290 yesterday = today - datetime.timedelta(days=1)
3291 tomorrow = today + datetime.timedelta(days=1)
3292 two_months_from_today = today + datetime.timedelta(days=60)
3293
3294 service_period = schedule.GetDefaultServicePeriod()
3295 service_period.SetWeekdayService(True)
3296 service_period.SetWeekendService(True)
3297 service_period.SetEndDate(two_months_from_today.strftime("%Y%m%d"))
3298
3299 service_period.SetStartDate(yesterday.strftime("%Y%m%d"))
3300 schedule.Validate()
3301 problems.AssertNoMoreExceptions()
3302
3303 service_period.SetStartDate(today.strftime("%Y%m%d"))
3304 schedule.Validate()
3305 problems.AssertNoMoreExceptions()
3306
3307 service_period.SetStartDate(tomorrow.strftime("%Y%m%d"))
3308 schedule.Validate()
3309 problems.PopException('FutureService')
3310 problems.AssertNoMoreExceptions()
3311
3312
3313 class CalendarTxtIntegrationTestCase(MemoryZipTestCase):
3314 def testBadEndDateFormat(self):
3315 # A badly formatted end_date used to generate an InvalidValue report from
3316 # Schedule.Validate and ServicePeriod.Validate. Test for the bug.
3317 self.zip.writestr(
3318 "calendar.txt",
3319 "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,"
3320 "start_date,end_date\n"
3321 "FULLW,1,1,1,1,1,1,1,20070101,20101232\n"
3322 "WE,0,0,0,0,0,1,1,20070101,20101231\n")
3323 schedule = self.loader.Load()
3324 e = self.problems.PopInvalidValue('end_date')
3325 self.problems.AssertNoMoreExceptions()
3326
3327 def testBadStartDateFormat(self):
3328 self.zip.writestr(
3329 "calendar.txt",
3330 "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,"
3331 "start_date,end_date\n"
3332 "FULLW,1,1,1,1,1,1,1,200701xx,20101231\n"
3333 "WE,0,0,0,0,0,1,1,20070101,20101231\n")
3334 schedule = self.loader.Load()
3335 e = self.problems.PopInvalidValue('start_date')
3336 self.problems.AssertNoMoreExceptions()
3096 3337
3097 3338
3098 class DuplicateTripIDValidationTestCase(unittest.TestCase): 3339 class DuplicateTripIDValidationTestCase(unittest.TestCase):
3099 def runTest(self): 3340 def runTest(self):
3100 schedule = transitfeed.Schedule( 3341 schedule = transitfeed.Schedule(
3101 problem_reporter=ExceptionProblemReporterNoExpiration()) 3342 problem_reporter=ExceptionProblemReporterNoExpiration())
3102 schedule.AddAgency("Sample Agency", "http://example.com", 3343 schedule.AddAgency("Sample Agency", "http://example.com",
3103 "America/Los_Angeles") 3344 "America/Los_Angeles")
3104 route = transitfeed.Route() 3345 route = transitfeed.Route()
3105 route.route_id = "SAMPLE_ID" 3346 route.route_id = "SAMPLE_ID"
(...skipping 14 matching lines...) Expand all
3120 schedule.AddTripObject(trip1) 3361 schedule.AddTripObject(trip1)
3121 3362
3122 trip2 = transitfeed.Trip() 3363 trip2 = transitfeed.Trip()
3123 trip2.route_id = "SAMPLE_ID" 3364 trip2.route_id = "SAMPLE_ID"
3124 trip2.service_id = "WEEK" 3365 trip2.service_id = "WEEK"
3125 trip2.trip_id = "SAMPLE_TRIP" 3366 trip2.trip_id = "SAMPLE_TRIP"
3126 try: 3367 try:
3127 schedule.AddTripObject(trip2) 3368 schedule.AddTripObject(trip2)
3128 self.fail("Expected Duplicate ID validation failure") 3369 self.fail("Expected Duplicate ID validation failure")
3129 except transitfeed.DuplicateID, e: 3370 except transitfeed.DuplicateID, e:
3130 self.assertEqual("trip_id", e.column_names[0]) 3371 self.assertEqual("trip_id", e.column_name)
3131 self.assertEqual("SAMPLE_TRIP", e.values[0]) 3372 self.assertEqual("SAMPLE_TRIP", e.value)
3132 3373
3133 3374
3134 class DuplicateStopValidationTestCase(ValidationTestCase): 3375 class DuplicateStopValidationTestCase(ValidationTestCase):
3135 def runTest(self): 3376 def runTest(self):
3136 schedule = transitfeed.Schedule(problem_reporter=self.problems) 3377 schedule = transitfeed.Schedule(problem_reporter=self.problems)
3137 schedule.AddAgency("Sample Agency", "http://example.com", 3378 schedule.AddAgency("Sample Agency", "http://example.com",
3138 "America/Los_Angeles") 3379 "America/Los_Angeles")
3139 route = transitfeed.Route() 3380 route = transitfeed.Route()
3140 route.route_id = "SAMPLE_ID" 3381 route.route_id = "SAMPLE_ID"
3141 route.route_type = 3 3382 route.route_type = 3
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
3463 trip = route.AddTrip(schedule, headsign="To The End", 3704 trip = route.AddTrip(schedule, headsign="To The End",
3464 service_period=service_period) 3705 service_period=service_period)
3465 trip_id = trip.trip_id 3706 trip_id = trip.trip_id
3466 self.assertTrue(trip_id) 3707 self.assertTrue(trip_id)
3467 trip = schedule.GetTrip(trip_id) 3708 trip = schedule.GetTrip(trip_id)
3468 self.assertEqual("To The End", trip.trip_headsign) 3709 self.assertEqual("To The End", trip.trip_headsign)
3469 self.assertEqual(service_period, trip.service_period) 3710 self.assertEqual(service_period, trip.service_period)
3470 3711
3471 trip.AddStopTime(stop=stop1, arrival_secs=3600*8, departure_secs=3600*8) 3712 trip.AddStopTime(stop=stop1, arrival_secs=3600*8, departure_secs=3600*8)
3472 trip.AddStopTime(stop=stop2) 3713 trip.AddStopTime(stop=stop2)
3473 trip.AddStopTime(stop=stop3, arrival_secs=3600*8 + 60*15, 3714 trip.AddStopTime(stop=stop3, arrival_secs=3600*8 + 60*60,
3474 departure_secs=3600*8 + 60*15) 3715 departure_secs=3600*8 + 60*60)
3475 trip.AddStopTime(stop=stop4, arrival_time="8:25:00", 3716 trip.AddStopTime(stop=stop4, arrival_time="9:13:00",
3476 departure_secs=3600*8 + 60*26, stop_headsign="Last stop", 3717 departure_secs=3600*8 + 60*103, stop_headsign="Last stop",
3477 pickup_type=1, drop_off_type=3) 3718 pickup_type=1, drop_off_type=3)
3478 3719
3479 schedule.Validate() 3720 schedule.Validate()
3480 self.assertEqual(4, len(trip.GetTimeStops())) 3721 self.assertEqual(4, len(trip.GetTimeStops()))
3481 self.assertEqual(1, len(schedule.GetRouteList())) 3722 self.assertEqual(1, len(schedule.GetRouteList()))
3482 self.assertEqual(4, len(schedule.GetStopList())) 3723 self.assertEqual(4, len(schedule.GetStopList()))
3483 3724
3484 3725
3485 class WriteSampleFeedTestCase(TempFileTestCaseBase): 3726 class WriteSampleFeedTestCase(TempFileTestCaseBase):
3486 def assertEqualTimeString(self, a, b): 3727 def assertEqualTimeString(self, a, b):
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 stoptimes = self.trip1.GetStopTimes() 4396 stoptimes = self.trip1.GetStopTimes()
4156 for stoptimes_clone in stoptimes_list: 4397 for stoptimes_clone in stoptimes_list:
4157 self.assertEqual(len(stoptimes_clone), len(stoptimes)) 4398 self.assertEqual(len(stoptimes_clone), len(stoptimes))
4158 for st_clone, st in zip(stoptimes_clone, stoptimes): 4399 for st_clone, st in zip(stoptimes_clone, stoptimes):
4159 for name in st.__slots__: 4400 for name in st.__slots__:
4160 if name not in ('arrival_secs', 'departure_secs'): 4401 if name not in ('arrival_secs', 'departure_secs'):
4161 self.assertEqual(getattr(st, name), getattr(st_clone, name)) 4402 self.assertEqual(getattr(st, name), getattr(st_clone, name))
4162 4403
4163 if __name__ == '__main__': 4404 if __name__ == '__main__':
4164 unittest.main() 4405 unittest.main()
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497