<s> from __future__ import absolute_import <EOL> import transitfeed <EOL> from tests import util <EOL> class ZeroBasedStopSequenceTestCase ( util . LoadTestCase ) : <EOL> def runTest ( self ) : <EOL> self . ExpectInvalidValue ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class StopTimeValidationTestCase ( util . ValidationTestCase ) : <EOL> def runTest ( self ) : <EOL> stop = transitfeed . Stop ( ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = '<STR_LIT>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = '<STR_LIT>' , <EOL> pickup_type = '<STR_LIT>' , <EOL> drop_off_type = '<STR_LIT:0>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT:a>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = '<STR_LIT>' , <EOL> pickup_type = '<STR_LIT:3>' , <EOL> drop_off_type = '<STR_LIT:a>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT:$>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = '<STR_LIT>' , <EOL> pickup_type = '<STR_LIT:3>' , <EOL> drop_off_type = '<STR_LIT:0>' , <EOL> shape_dist_traveled = '<STR_LIT:$>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = '<STR_LIT>' , <EOL> pickup_type = '<STR_LIT:3>' , <EOL> drop_off_type = '<STR_LIT:0>' , <EOL> shape_dist_traveled = '<STR_LIT>' ) ) <EOL> self . ExpectOtherProblemInClosure ( <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> pickup_type = '<STR_LIT:1>' , drop_off_type = '<STR_LIT:1>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT:x>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , timepoint = '<STR_LIT:x>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT:2>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , timepoint = '<STR_LIT:2>' ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectMissingValueInClosure ( '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectMissingValueInClosure ( '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> departure_time = "<STR_LIT>" , <EOL> arrival_time = "<STR_LIT>" ) ) <EOL> self . ExpectMissingValueInClosure ( '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" ) ) <EOL> self . ExpectMissingValueInClosure ( '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : transitfeed . StopTime ( self . problems , stop , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , "<STR_LIT:id>" , <EOL> lambda : transitfeed . StopTime ( self . problems , "<STR_LIT:id>" , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , "<STR_LIT:3>" , <EOL> lambda : transitfeed . StopTime ( self . problems , "<STR_LIT:3>" , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> self . ExpectInvalidValueInClosure ( '<STR_LIT>' , None , <EOL> lambda : transitfeed . StopTime ( self . problems , None , <EOL> arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) ) <EOL> transitfeed . StopTime ( self . problems , stop , arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" , pickup_type = '<STR_LIT:1>' , drop_off_type = '<STR_LIT:1>' ) <EOL> transitfeed . StopTime ( self . problems , stop , arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" , pickup_type = '<STR_LIT:1>' , drop_off_type = '<STR_LIT:1>' ) <EOL> transitfeed . StopTime ( self . problems , stop , arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) <EOL> transitfeed . StopTime ( self . problems , stop , arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) <EOL> transitfeed . StopTime ( self . problems , stop , arrival_time = "<STR_LIT>" , <EOL> departure_time = "<STR_LIT>" ) <EOL> transitfeed . StopTime ( self . problems , stop ) <EOL> transitfeed . StopTime ( self . problems , stop , timepoint = None ) <EOL> transitfeed . StopTime ( self . problems , stop , timepoint = <NUM_LIT:1> ) <EOL> transitfeed . StopTime ( self . problems , stop , timepoint = '<STR_LIT:1>' ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> class TooFastTravelTestCase ( util . ValidationTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TooFastTravelTestCase , self ) . setUp ( ) <EOL> self . schedule = self . SimpleSchedule ( ) <EOL> self . route = self . schedule . GetRoute ( "<STR_LIT>" ) <EOL> self . trip = self . route . AddTrip ( ) <EOL> def AddStopDistanceTime ( self , dist_time_list ) : <EOL> magic_lat = <NUM_LIT> <EOL> stop = self . schedule . AddStop ( magic_lat , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> time = <NUM_LIT:0> <EOL> self . trip . AddStopTime ( stop , arrival_secs = time , departure_secs = time ) <EOL> for i , ( dist_delta , time_delta ) in enumerate ( dist_time_list ) : <EOL> stop = self . schedule . AddStop ( <EOL> magic_lat , stop . stop_lon + dist_delta * <NUM_LIT> , <EOL> "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> time += time_delta <EOL> self . trip . AddStopTime ( stop , arrival_secs = time , departure_secs = time ) <EOL> def testMovingTooFast ( self ) : <EOL> self . AddStopDistanceTime ( [ ( <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> self . route . route_type = <NUM_LIT:4> <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> self . route . route_type = None <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( r'<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testNoTimeDelta ( self ) : <EOL> self . AddStopDistanceTime ( [ ( <NUM_LIT> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:1000> , <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:0> ) ] ) <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> self . route . route_type = <NUM_LIT:4> <EOL> self . trip . Validate ( self . problems ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> self . route . route_type = None <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testNoTimeDeltaNotRounded ( self ) : <EOL> self . AddStopDistanceTime ( [ ( <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:0> ) ] ) <EOL> self . trip . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertMatchesRegex ( '<STR_LIT>' , e . FormatProblem ( ) ) <EOL> self . assertEqual ( e . type , transitfeed . TYPE_WARNING ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> class TooManyConsecutiveStopTimesWithSameTime ( util . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . accumulator = util . RecordingProblemAccumulator ( <EOL> self , ( "<STR_LIT>" ) ) <EOL> self . problems = transitfeed . ProblemReporter ( self . accumulator ) <EOL> self . schedule = transitfeed . Schedule ( problem_reporter = self . problems ) <EOL> self . schedule . AddAgency ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> self . stop1 = self . schedule . AddStop ( lng = - <NUM_LIT> , <EOL> lat = <NUM_LIT> , <EOL> name = "<STR_LIT>" , <EOL> stop_id = "<STR_LIT>" ) <EOL> self . stop2 = self . schedule . AddStop ( lng = - <NUM_LIT> , <EOL> lat = <NUM_LIT> , <EOL> name = "<STR_LIT>" , <EOL> stop_id = "<STR_LIT>" ) <EOL> route = self . schedule . AddRoute ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , route_id = "<STR_LIT>" ) <EOL> self . trip = route . AddTrip ( self . schedule , trip_id = "<STR_LIT>" ) <EOL> def testTooManyConsecutiveStopTimesWithSameTime ( self ) : <EOL> trip = self . trip <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> for _ in range ( <NUM_LIT:6> ) : <EOL> trip . AddStopTime ( self . stop2 , stop_time = "<STR_LIT>" ) <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . trip_id , '<STR_LIT>' ) <EOL> self . assertEqual ( e . number_of_stop_times , <NUM_LIT:6> ) <EOL> self . assertEqual ( e . stop_time , '<STR_LIT>' ) <EOL> self . assertEqual ( e . FormatProblem ( ) , <EOL> "<STR_LIT>" "<STR_LIT>" ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testNotTooManyConsecutiveStopTimesWithSameTime ( self ) : <EOL> trip = self . trip <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> for _ in range ( <NUM_LIT:5> ) : <EOL> trip . AddStopTime ( self . stop2 , stop_time = "<STR_LIT>" ) <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testTooManyConsecutiveStopTimesWithSameTimeAtStart ( self ) : <EOL> trip = self . trip <EOL> for _ in range ( <NUM_LIT:6> ) : <EOL> trip . AddStopTime ( self . stop2 , stop_time = "<STR_LIT>" ) <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . trip_id , '<STR_LIT>' ) <EOL> self . assertEqual ( e . number_of_stop_times , <NUM_LIT:6> ) <EOL> self . assertEqual ( e . stop_time , '<STR_LIT>' ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testTooManyConsecutiveStopTimesWithSameTimeAtEnd ( self ) : <EOL> trip = self . trip <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> for _ in range ( <NUM_LIT:6> ) : <EOL> trip . AddStopTime ( self . stop2 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . trip_id , '<STR_LIT>' ) <EOL> self . assertEqual ( e . number_of_stop_times , <NUM_LIT:6> ) <EOL> self . assertEqual ( e . stop_time , '<STR_LIT>' ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testTooManyConsecutiveStopTimesWithUnspecifiedTimes ( self ) : <EOL> trip = self . trip <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> for _ in range ( <NUM_LIT:4> ) : <EOL> trip . AddStopTime ( self . stop2 ) <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> e = self . accumulator . PopException ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . trip_id , '<STR_LIT>' ) <EOL> self . assertEqual ( e . number_of_stop_times , <NUM_LIT:6> ) <EOL> self . assertEqual ( e . stop_time , '<STR_LIT>' ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) <EOL> def testNotTooManyConsecutiveStopTimesWithUnspecifiedTimes ( self ) : <EOL> trip = self . trip <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> for _ in range ( <NUM_LIT:4> ) : <EOL> trip . AddStopTime ( self . stop2 ) <EOL> trip . AddStopTime ( self . stop1 , stop_time = "<STR_LIT>" ) <EOL> self . schedule . Validate ( self . problems ) <EOL> self . accumulator . AssertNoMoreExceptions ( ) </s>
