Ejemplo n.º 1
0
  def runTest(self):
    schedule = self.SimpleSchedule()

    shape = transitfeed.Shape("shape_1")
    shape.AddPoint(36.425288, -117.133162, 0)
    shape.AddPoint(36.424288, -117.143142, 1)
    schedule.AddShapeObject(shape)

    trip = schedule.GetRoute("054C").AddTrip(trip_id="054C-00")
    trip.shape_id = "shape_1"

    # Stop 1 is only 600 meters away from shape, which is allowed.
    stop = transitfeed.Stop(36.425288, -117.139162, "Demo Stop 1", "STOP1")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:11:00", departure_time="5:12:00",
                     stop_sequence=0, shape_dist_traveled=0)
    # Stop 2 is more than 1000 meters away from shape, which is not allowed.
    stop = transitfeed.Stop(36.424288, -117.158142, "Demo Stop 2", "STOP2")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:15:00", departure_time="5:16:00",
                     stop_sequence=1, shape_dist_traveled=1)

    schedule.Validate(self.problems)
    e = self.accumulator.PopException('StopTooFarFromShapeWithDistTraveled')
    self.assertTrue(e.FormatProblem().find('Demo Stop 2') != -1)
    self.assertTrue(e.FormatProblem().find('1344 meters away') != -1)
    self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 2
0
    def testWithoutSchedule(self):
        stop = transitfeed.Stop()
        stop.Validate(self.problems)
        for name in "stop_id stop_name stop_lat stop_lon".split():
            e = self.accumulator.PopException("MissingValue")
            self.assertEquals(name, e.column_name)
        self.accumulator.AssertNoMoreExceptions()

        stop = transitfeed.Stop()
        # Test behaviour for unset and unknown attribute
        self.assertEquals(stop["new_column"], "")
        try:
            t = stop.new_column
            self.fail("Expecting AttributeError")
        except AttributeError as e:
            pass  # Expected
        stop.stop_id = "a"
        stop.stop_name = "my stop"
        stop.new_column = "val"
        stop.stop_lat = 5.909
        stop.stop_lon = "40.02"
        self.assertEquals(stop.new_column, "val")
        self.assertEquals(stop["new_column"], "val")
        self.assertTrue(isinstance(stop["stop_lat"], basestring))
        self.assertAlmostEqual(float(stop["stop_lat"]), 5.909)
        self.assertTrue(isinstance(stop["stop_lon"], basestring))
        self.assertAlmostEqual(float(stop["stop_lon"]), 40.02)
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()
        # After validation stop.stop_lon has been converted to a float
        self.assertAlmostEqual(stop.stop_lat, 5.909)
        self.assertAlmostEqual(stop.stop_lon, 40.02)
        self.assertEquals(stop.new_column, "val")
        self.assertEquals(stop["new_column"], "val")
Ejemplo n.º 3
0
    def testWithoutSchedule(self):
        stop = transitfeed.Stop()
        stop.validate(self.problems)
        for name in "stop_id stop_name stop_lat stop_lon".split():
            e = self.accumulator.pop_exception('MissingValue')
            self.assertEquals(name, e.column_name)
        self.accumulator.assert_no_more_exceptions()

        stop = transitfeed.Stop()
        # Test behaviour for unset and unknown attribute
        self.assertEquals(stop['new_column'], '')
        try:
            t = stop.new_column
            self.fail('Expecting AttributeError')
        except AttributeError:
            pass  # Expected
        stop.stop_id = 'a'
        stop.stop_name = 'my stop'
        stop.new_column = 'val'
        stop.stop_lat = 5.909
        stop.stop_lon = 40.02
        self.assertEquals(stop.new_column, 'val')
        self.assertEquals(stop['new_column'], 'val')
        self.assertTrue(isinstance(stop['stop_lat'], str))
        self.assertAlmostEqual(float(stop['stop_lat']), 5.909)
        self.assertTrue(isinstance(stop['stop_lon'], str))
        self.assertAlmostEqual(float(stop['stop_lon']), 40.02)
        stop.validate(self.problems)
        self.accumulator.assert_no_more_exceptions()
        # After validation stop.stop_lon has been converted to a float
        self.assertAlmostEqual(stop.stop_lat, 5.909)
        self.assertAlmostEqual(stop.stop_lon, 40.02)
        self.assertEquals(stop.new_column, 'val')
        self.assertEquals(stop['new_column'], 'val')
Ejemplo n.º 4
0
    def testWithSchedule(self):
        schedule = transitfeed.Schedule(problem_reporter=self.problems)

        stop = transitfeed.Stop(field_dict={})
        # AddStopObject silently fails for Stop objects without stop_id
        schedule.AddStopObject(stop)
        self.assertFalse(schedule.GetStopList())
        self.assertFalse(stop._schedule)

        # Okay to add a stop with only stop_id
        stop = transitfeed.Stop(field_dict={"stop_id": "b"})
        schedule.AddStopObject(stop)
        stop.Validate(self.problems)
        for name in "stop_name stop_lat stop_lon".split():
            e = self.accumulator.PopException("MissingValue")
            self.assertEquals(name, e.column_name)
        self.accumulator.AssertNoMoreExceptions()

        stop.new_column = "val"
        self.assertTrue("new_column" in schedule.GetTableColumns("stops"))

        # Adding a duplicate stop_id fails
        schedule.AddStopObject(transitfeed.Stop(field_dict={"stop_id": "b"}))
        self.accumulator.PopException("DuplicateID")
        self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 5
0
  def runTest(self):
    schedule = transitfeed.Schedule(problem_reporter=self.problems)
    schedule.AddAgency("Sample Agency", "http://example.com",
                       "America/Los_Angeles")
    route = transitfeed.Route()
    route.route_id = "SAMPLE_ID"
    route.route_type = 3
    route.route_long_name = "Sample Route"
    schedule.AddRouteObject(route)

    service_period = transitfeed.ServicePeriod("WEEK")
    service_period.SetStartDate("20070101")
    service_period.SetEndDate("20071231")
    service_period.SetWeekdayService(True)
    schedule.AddServicePeriodObject(service_period)

    trip = transitfeed.Trip()
    trip.route_id = "SAMPLE_ID"
    trip.service_id = "WEEK"
    trip.trip_id = "SAMPLE_TRIP"
    schedule.AddTripObject(trip)

    stop1 = transitfeed.Stop()
    stop1.stop_id = "STOP1"
    stop1.stop_name = "Stop 1"
    stop1.stop_lat = 78.243587
    stop1.stop_lon = 32.258937
    schedule.AddStopObject(stop1)
    trip.AddStopTime(stop1, arrival_time="12:00:00", departure_time="12:00:00")

    stop2 = transitfeed.Stop()
    stop2.stop_id = "STOP2"
    stop2.stop_name = "Stop 2"
    stop2.stop_lat = 78.253587
    stop2.stop_lon = 32.258937
    schedule.AddStopObject(stop2)
    trip.AddStopTime(stop2, arrival_time="12:05:00", departure_time="12:05:00")
    schedule.Validate()

    stop3 = transitfeed.Stop()
    stop3.stop_id = "STOP3"
    stop3.stop_name = "Stop 3"
    stop3.stop_lat = 78.243587
    stop3.stop_lon = 32.268937
    schedule.AddStopObject(stop3)
    trip.AddStopTime(stop3, arrival_time="12:10:00", departure_time="12:10:00")
    schedule.Validate()
    self.accumulator.AssertNoMoreExceptions()

    stop4 = transitfeed.Stop()
    stop4.stop_id = "STOP4"
    stop4.stop_name = "Stop 4"
    stop4.stop_lat = 78.243588
    stop4.stop_lon = 32.268936
    schedule.AddStopObject(stop4)
    trip.AddStopTime(stop4, arrival_time="12:15:00", departure_time="12:15:00")
    schedule.Validate()
    e = self.accumulator.PopException('StopsTooClose')
    self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 6
0
 def testBlankAttributeName(self):
     stop1 = transitfeed.Stop(field_dict={"": "a"})
     stop2 = transitfeed.Stop(field_dict=stop1)
     self.assertEquals("a", getattr(stop1, ""))
     # The attribute "" is treated as private and not copied
     self.assertRaises(AttributeError, getattr, stop2, "")
     self.assertEquals(set(), set(stop1.keys()))
     self.assertEquals(set(), set(stop2.keys()))
Ejemplo n.º 7
0
  def runTest(self):
    schedule = self.SimpleSchedule()

    shape = transitfeed.Shape("shape_1")
    shape.AddPoint(36.425288, -117.133162, 0)
    shape.AddPoint(36.424288, -117.133142, 1)
    schedule.AddShapeObject(shape)

    trip = schedule.GetRoute("054C").AddTrip(trip_id="054C-00")
    trip.shape_id = "shape_1"

    stop = transitfeed.Stop(36.425288, -117.133162, "Demo Stop 1", "STOP1")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:11:00", departure_time="5:12:00",
                     stop_sequence=0, shape_dist_traveled=0)
    stop = transitfeed.Stop(36.424288, -117.133142, "Demo Stop 2", "STOP2")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:15:00", departure_time="5:16:00",
                     stop_sequence=1, shape_dist_traveled=1)

    stop = transitfeed.Stop(36.423288, -117.133122, "Demo Stop 3", "STOP3")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:18:00", departure_time="5:19:00",
                     stop_sequence=2, shape_dist_traveled=2)
    self.accumulator.AssertNoMoreExceptions()
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('OtherProblem')
    self.assertMatchesRegex('shape_dist_traveled=2', e.FormatProblem())
    self.accumulator.AssertNoMoreExceptions()

    # Error if the distance decreases.
    shape.AddPoint(36.421288, -117.133132, 2)
    stop = transitfeed.Stop(36.421288, -117.133122, "Demo Stop 4", "STOP4")
    schedule.AddStopObject(stop)
    stoptime = transitfeed.StopTime(self.problems, stop,
                                    arrival_time="5:29:00",
                                    departure_time="5:29:00", stop_sequence=3,
                                    shape_dist_traveled=1.7)
    trip.AddStopTimeObject(stoptime, schedule=schedule)
    self.accumulator.AssertNoMoreExceptions()
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('InvalidValue')
    self.assertMatchesRegex('stop STOP4 has', e.FormatProblem())
    self.assertMatchesRegex('shape_dist_traveled=1.7', e.FormatProblem())
    self.assertMatchesRegex('distance was 2.0.', e.FormatProblem())
    self.assertEqual(e.type, transitfeed.TYPE_ERROR)
    self.accumulator.AssertNoMoreExceptions()

    # Warning if distance remains the same between two stop_times
    stoptime.shape_dist_traveled = 2.0
    trip.ReplaceStopTimeObject(stoptime, schedule=schedule)
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('InvalidValue')
    self.assertMatchesRegex('stop STOP4 has', e.FormatProblem())
    self.assertMatchesRegex('shape_dist_traveled=2.0', e.FormatProblem())
    self.assertMatchesRegex('distance was 2.0.', e.FormatProblem())
    self.assertEqual(e.type, transitfeed.TYPE_WARNING)
    self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 8
0
    def runTest(self):
        stop = transitfeed.Stop(field_dict={"stop_id": "STOP1",
                                            "stop_name": "Stop one",
                                            "stop_lat": "0x20",
                                            "stop_lon": "140.01"})
        self.ValidateAndExpectInvalidValue(stop, "stop_lat")

        stop = transitfeed.Stop(field_dict={"stop_id": "STOP1",
                                            "stop_name": "Stop one",
                                            "stop_lat": "13.0",
                                            "stop_lon": "1e2"})
        self.ValidateAndExpectInvalidFloatValue(stop, "1e2")
Ejemplo n.º 9
0
    def runTest(self):
        import transitfeed

        schedule = transitfeed.Schedule()
        schedule.AddAgency("Sample Agency", "http://example.com",
                           "America/Los_Angeles")
        route = transitfeed.Route()
        route.route_id = "SAMPLE_ID"
        route.route_type = 3
        route.route_short_name = "66"
        route.route_long_name = "Sample Route"
        schedule.AddRouteObject(route)

        service_period = transitfeed.ServicePeriod("WEEK")
        service_period.SetStartDate("20070101")
        service_period.SetEndDate("20071231")
        service_period.SetWeekdayService(True)
        schedule.AddServicePeriodObject(service_period)

        trip = transitfeed.Trip()
        trip.route_id = "SAMPLE_ID"
        trip.service_period = service_period
        trip.trip_id = "SAMPLE_TRIP"
        trip.direction_id = "0"
        trip.block_id = None
        schedule.AddTripObject(trip)

        stop1 = transitfeed.Stop()
        stop1.stop_id = "STOP1"
        stop1.stop_name = "Stop 1"
        stop1.stop_lat = 78.243587
        stop1.stop_lon = 32.258937
        schedule.AddStopObject(stop1)
        trip.AddStopTime(stop1,
                         arrival_time="12:00:00",
                         departure_time="12:00:00")

        stop2 = transitfeed.Stop()
        stop2.stop_id = "STOP2"
        stop2.stop_name = "Stop 2"
        stop2.stop_lat = 78.253587
        stop2.stop_lon = 32.258937
        schedule.AddStopObject(stop2)
        trip.AddStopTime(stop2,
                         arrival_time="12:05:00",
                         departure_time="12:05:00")

        schedule.Validate()  # not necessary, but helpful for finding problems
        schedule.WriteGoogleTransitFeed("new_feed.zip")
Ejemplo n.º 10
0
    def testWithoutSchedule(self):
        stop = transitfeed.Stop()
        stop.Validate(self.problems)
        for name in "stop_id stop_name stop_lat stop_lon".split():
            e = self.accumulator.PopException('MissingValue')
            self.assertEquals(name, e.column_name)
        self.accumulator.AssertNoMoreExceptions()

        stop = transitfeed.Stop()
        # Test behaviour for unset and unknown attribute
        self.assertEquals(stop['new_column'], '')
        try:
            t = stop.new_column
            self.fail('Expecting AttributeError')
        except AttributeError, e:
            pass  # Expected
    def runTest(self):
        schedule = transitfeed.Schedule()
        schedule.AddAgency("Sample Agency", "http://example.com",
                           "America/Los_Angeles")
        route = transitfeed.Route()
        route.route_id = "SAMPLE_ID"
        route.route_type = 3
        route.route_short_name = "66"
        route.route_long_name = "Sample Route acute letter e\202"
        schedule.AddRouteObject(route)

        service_period = transitfeed.ServicePeriod("WEEK")
        service_period.SetStartDate("20070101")
        service_period.SetEndDate("20071231")
        service_period.SetWeekdayService(True)
        schedule.AddServicePeriodObject(service_period)

        trip = transitfeed.Trip()
        trip.route_id = "SAMPLE_ID"
        trip.service_period = service_period
        trip.trip_id = "SAMPLE_TRIP"
        schedule.AddTripObject(trip)

        stop1 = transitfeed.Stop()
        stop1.stop_id = "STOP1"
        stop1.stop_name = u'Stop 1 acute letter e\202'
        stop1.stop_lat = 78.243587
        stop1.stop_lon = 32.258937
        schedule.AddStopObject(stop1)
        trip.AddStopTime(stop1,
                         arrival_time="12:00:00",
                         departure_time="12:00:00")

        stop2 = transitfeed.Stop()
        stop2.stop_id = "STOP2"
        stop2.stop_name = "Stop 2"
        stop2.stop_lat = 78.253587
        stop2.stop_lon = 32.258937
        schedule.AddStopObject(stop2)
        trip.AddStopTime(stop2,
                         arrival_time="12:05:00",
                         departure_time="12:05:00")

        schedule.Validate()
        schedule.WriteGoogleTransitFeed(self.tempfilepath)
Ejemplo n.º 12
0
    def runTest(self):
        schedule = self.SimpleSchedule()
        trip = schedule.get_route("054C").add_trip(trip_id="054C-00")

        # We should get an OtherProblem here because the trip has no stops.
        self.ValidateAndExpectOtherProblem(schedule)

        # It should trigger a TYPE_ERROR if there are frequencies for the trip
        # but no stops
        trip.add_frequency("01:00:00", "12:00:00", 600)
        schedule.validate(self.problems)
        self.accumulator.pop_exception('OtherProblem')  # pop first warning
        e = self.accumulator.pop_exception(
            'OtherProblem')  # pop frequency error
        self.assertTrue(
            e.format_problem().find('Frequencies defined, but') != -1)
        self.assertTrue(e.format_problem().find('given in trip 054C-00') != -1)
        self.assertEquals(transitfeed.TYPE_ERROR, e.type)
        self.accumulator.assert_no_more_exceptions()
        trip.clear_frequencies()

        # Add a stop, but with only one stop passengers have nowhere to exit!
        stop = transitfeed.Stop(36.425288, -117.133162, "Demo Stop 1", "STOP1")
        schedule.add_stop_object(stop)
        trip.add_stop_time(stop,
                           arrival_time="5:11:00",
                           departure_time="5:12:00")
        self.ValidateAndExpectOtherProblem(schedule)

        # Add another stop, and then validation should be happy.
        stop = transitfeed.Stop(36.424288, -117.133142, "Demo Stop 2", "STOP2")
        schedule.add_stop_object(stop)
        trip.add_stop_time(stop,
                           arrival_time="5:15:00",
                           departure_time="5:16:00")
        schedule.validate(self.problems)

        trip.add_stop_time(stop, stop_time="05:20:00")
        trip.add_stop_time(stop, stop_time="05:22:00")

        # Last stop must always have a time
        trip.add_stop_time(stop, arrival_secs=None, departure_secs=None)
        self.ExpectInvalidValueInClosure(
            'arrival_time',
            c=lambda: trip.get_end_time(loader_problems=self.problems))
Ejemplo n.º 13
0
def create_gtfs_stop_entries(stops_shapefile, mode_config, schedule):
    """This function requires that in the stops shapefile, there is an
    attribute called 'Name' listing the name of the stop. (Note: it is ok if
    this is actually just a number, but it will be treated as a string.)"""

    # print "%s() called." % inspect.stack()[0][3]

    stop_id_to_gtfs_stop_id_map = {}
    layer = stops_shapefile.GetLayer(0)
    stop_prefix = mode_config['stop_prefix']
    for stop_cnt, stop_feature in enumerate(layer):

        stop_id = stop_feature.GetField(tp_model.STOP_ID_FIELD)
        if stop_id is None:
            continue
        stop_name = None
        try:
            stop_name = stop_feature.GetField(tp_model.STOP_NAME_FIELD)
        except ValueError:
            pass
        if not stop_name:
            # This will catch empty stop names also.
            stop_name = tp_model.get_stop_feature_default_name(
                stop_feature, stop_prefix)
        assert stop_name
        stop_desc = None
        stop_code = None
        # stop_id_gtfs = str(mode_config['index'] + stop_cnt)
        stop_id_gtfs = str(stop_id)
        stop_id_to_gtfs_stop_id_map[stop_id] = stop_id_gtfs
        geom = stop_feature.GetGeometryRef()
        lng = geom.GetX()
        lat = geom.GetY()
        # TODO: For now assume they are in Lat/Lon WGS84 - really should
        # double-check and do a coordinate transform if not.

        stop = transitfeed.Stop(
            stop_id=stop_id_gtfs,
            name=stop_name,
            stop_code=stop_code,
            lat=lat,
            lng=lng,
        )
        if VERBOSE:
            print("Adding stop with ID %s, name '%s', lat,long of (%3f,%3f)" % \
                (stop_id_gtfs, stop_name, lat, lng))
        schedule.AddStopObject(stop)
    # See http://gis.stackexchange.com/questions/76683/python-ogr-nested-loop-only-loops-once
    layer.ResetReading()  # Necessary as we need to loop thru again later
    return stop_id_to_gtfs_stop_id_map
Ejemplo n.º 14
0
    def _add_stop_to_feed(self, stop, feed):
        """
        This function adds a single Stop or Station object as a stop to GTFS.
        It can be overridden by custom creators to change how stop_ids are made
        up.

        :return stop_id: A string with the stop_id in the GTFS
        """
        try:
            parent_station = stop.get_parent_station()
        except AttributeError:
            parent_station = None

        # Send stop_id creation through overridable function
        gtfs_stop_id = self._define_stop_id(stop)

        # Save defined stop_id to the object for further use in other creators
        stop.set_stop_id(gtfs_stop_id)

        # Set stop name
        stop_name = self._define_stop_name(stop)

        # Collect all data together for the stop creation
        field_dict = {
            "stop_id": self._define_stop_id(stop),
            "stop_name": stop_name,
            "stop_lat": round(float(stop.lat), 10),
            "stop_lon": round(float(stop.lon), 10),
            "location_type": stop.location_type,
            "parent_station": parent_station,
        }

        # Add stop to GTFS object
        feed.AddStopObject(transitfeed.Stop(field_dict=field_dict))

        if type(stop_name).__name__ == "unicode":
            stop_name = stop_name.encode('utf-8')

        logging.info("Added stop: %s - %s", stop_name, stop.osm_url)

        # Return the stop_id of the stop added
        return field_dict['stop_id']
Ejemplo n.º 15
0
    def add_stop(self, schedule, stop, parent_station=None, is_station=False):

        stop_dict = {
            "stop_lat": float(stop.lat),
            "stop_lon": float(stop.lon),
            "stop_name": stop.name
        }

        if is_station:
            stop_dict["stop_id"] = "SA" + str(stop.id)
            stop_dict["location_type"] = "1"
        else:
            stop_dict["stop_id"] = str(stop.id)
            stop_dict["location_type"] = ""

        if parent_station is None:
            stop_dict["parent_station"] = ""
        else:
            stop_dict["parent_station"] = parent_station.stop_id

        # Add stop to GTFS object
        stop = transitfeed.Stop(field_dict=stop_dict)
        schedule.AddStopObject(stop)
        return stop
Ejemplo n.º 16
0
  def runTest(self):

    schedule = transitfeed.Schedule(self.problems)
    schedule._check_duplicate_trips = True;

    agency = transitfeed.Agency('Demo agency', 'http://google.com',
                                'America/Los_Angeles', 'agency1')
    schedule.AddAgencyObject(agency)

    service = schedule.GetDefaultServicePeriod()
    service.SetDateHasService('20070101')

    route1 = transitfeed.Route('Route1', 'route 1', 3, 'route_1', 'agency1')
    schedule.AddRouteObject(route1)
    route2 = transitfeed.Route('Route2', 'route 2', 3, 'route_2', 'agency1')
    schedule.AddRouteObject(route2)

    trip1 = transitfeed.Trip()
    trip1.route_id = 'route_1'
    trip1.trip_id = 't1'
    trip1.trip_headsign = 'via Polish Hill'
    trip1.direction_id = '0'
    trip1.service_id = service.service_id
    schedule.AddTripObject(trip1)

    trip2 = transitfeed.Trip()
    trip2.route_id = 'route_2'
    trip2.trip_id = 't2'
    trip2.trip_headsign = 'New'
    trip2.direction_id = '0'
    trip2.service_id = service.service_id
    schedule.AddTripObject(trip2)

    trip3 = transitfeed.Trip()
    trip3.route_id = 'route_1'
    trip3.trip_id = 't3'
    trip3.trip_headsign = 'New Demo'
    trip3.direction_id = '0'
    trip3.service_id = service.service_id
    schedule.AddTripObject(trip3)

    stop1 = transitfeed.Stop(36.425288, -117.139162, "Demo Stop 1", "STOP1")
    schedule.AddStopObject(stop1)
    trip1.AddStopTime(stop1, arrival_time="5:11:00", departure_time="5:12:00",
                     stop_sequence=0, shape_dist_traveled=0)
    trip2.AddStopTime(stop1, arrival_time="5:11:00", departure_time="5:12:00",
                     stop_sequence=0, shape_dist_traveled=0)
    trip3.AddStopTime(stop1, arrival_time="6:11:00", departure_time="6:12:00",
                     stop_sequence=0, shape_dist_traveled=0)

    stop2 = transitfeed.Stop(36.424288, -117.158142, "Demo Stop 2", "STOP2")
    schedule.AddStopObject(stop2)
    trip1.AddStopTime(stop2, arrival_time="5:15:00", departure_time="5:16:00",
                      stop_sequence=1, shape_dist_traveled=1)
    trip2.AddStopTime(stop2, arrival_time="5:25:00", departure_time="5:26:00",
                      stop_sequence=1, shape_dist_traveled=1)
    trip3.AddStopTime(stop2, arrival_time="6:15:00", departure_time="6:16:00",
                      stop_sequence=1, shape_dist_traveled=1)

    schedule.Validate(self.problems)
    e = self.accumulator.PopException('DuplicateTrip')
    self.assertTrue(e.FormatProblem().find('t1 of route') != -1)
    self.assertTrue(e.FormatProblem().find('t2 of route') != -1)
    self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 17
0
    def runTest(self):
        # success case
        stop = transitfeed.Stop()
        stop.stop_id = "45"
        stop.stop_name = "Couch AT End Table"
        stop.stop_lat = 50.0
        stop.stop_lon = 50.0
        stop.stop_desc = "Edge of the Couch"
        stop.zone_id = "A"
        stop.stop_url = "http://example.com"
        stop.wheelchair_boarding = "2"
        stop.Validate(self.problems)

        # latitude too large
        stop.stop_lat = 100.0
        self.ValidateAndExpectInvalidValue(stop, "stop_lat")
        stop.stop_lat = 50.0

        # latitude as a string works when it is valid
        # empty strings or whitespaces should get reported as MissingValue
        stop.stop_lat = "50.0"
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()
        stop.stop_lat = "10f"
        self.ValidateAndExpectInvalidValue(stop, "stop_lat")
        stop.stop_lat = "None"
        self.ValidateAndExpectInvalidValue(stop, "stop_lat")
        stop.stop_lat = ""
        self.ValidateAndExpectMissingValue(stop, "stop_lat")
        stop.stop_lat = " "
        self.ValidateAndExpectMissingValue(stop, "stop_lat")
        stop.stop_lat = 50.0

        # longitude too large
        stop.stop_lon = 200.0
        self.ValidateAndExpectInvalidValue(stop, "stop_lon")
        stop.stop_lon = 50.0

        # longitude as a string works when it is valid
        # empty strings or whitespaces should get reported as MissingValue
        stop.stop_lon = "50.0"
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()
        stop.stop_lon = "10f"
        self.ValidateAndExpectInvalidValue(stop, "stop_lon")
        stop.stop_lon = "None"
        self.ValidateAndExpectInvalidValue(stop, "stop_lon")
        stop.stop_lon = ""
        self.ValidateAndExpectMissingValue(stop, "stop_lon")
        stop.stop_lon = " "
        self.ValidateAndExpectMissingValue(stop, "stop_lon")
        stop.stop_lon = 50.0

        # lat, lon too close to 0, 0
        stop.stop_lat = 0.0
        stop.stop_lon = 0.0
        self.ValidateAndExpectInvalidValue(stop, "stop_lat")
        stop.stop_lat = 50.0
        stop.stop_lon = 50.0

        # invalid stop_url
        stop.stop_url = "www.example.com"
        self.ValidateAndExpectInvalidValue(stop, "stop_url")
        stop.stop_url = "http://example.com"

        stop.stop_id = "   "
        self.ValidateAndExpectMissingValue(stop, "stop_id")
        stop.stop_id = "45"

        stop.stop_name = ""
        self.ValidateAndExpectMissingValue(stop, "stop_name")
        stop.stop_name = " "
        self.ValidateAndExpectMissingValue(stop, "stop_name")
        stop.stop_name = "Couch AT End Table"

        # description same as name
        stop.stop_desc = "Couch AT End Table"
        self.ValidateAndExpectInvalidValue(stop, "stop_desc")
        stop.stop_desc = "Edge of the Couch"
        self.accumulator.AssertNoMoreExceptions()

        stop.stop_timezone = "This_Timezone/Does_Not_Exist"
        self.ValidateAndExpectInvalidValue(stop, "stop_timezone")
        stop.stop_timezone = "America/Los_Angeles"
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()

        # invalid wheelchair_boarding
        stop.wheelchair_boarding = "3"
        self.ValidateAndExpectInvalidValue(stop, "wheelchair_boarding")
        stop.wheelchair_boarding = None
Ejemplo n.º 18
0
    def runTest(self):

        schedule = transitfeed.Schedule(self.problems)
        schedule._check_duplicate_trips = True

        agency = transitfeed.Agency("Demo agency", "http://google.com",
                                    "America/Los_Angeles", "agency1")
        schedule.AddAgencyObject(agency)

        service = schedule.GetDefaultServicePeriod()
        service.SetDateHasService("20070101")

        route1 = transitfeed.Route("Route1", "route 1", 3, "route_1",
                                   "agency1")
        schedule.AddRouteObject(route1)
        route2 = transitfeed.Route("Route2", "route 2", 3, "route_2",
                                   "agency1")
        schedule.AddRouteObject(route2)

        trip1 = transitfeed.Trip()
        trip1.route_id = "route_1"
        trip1.trip_id = "t1"
        trip1.trip_headsign = "via Polish Hill"
        trip1.direction_id = "0"
        trip1.service_id = service.service_id
        schedule.AddTripObject(trip1)

        trip2 = transitfeed.Trip()
        trip2.route_id = "route_2"
        trip2.trip_id = "t2"
        trip2.trip_headsign = "New"
        trip2.direction_id = "0"
        trip2.service_id = service.service_id
        schedule.AddTripObject(trip2)

        trip3 = transitfeed.Trip()
        trip3.route_id = "route_1"
        trip3.trip_id = "t3"
        trip3.trip_headsign = "New Demo"
        trip3.direction_id = "0"
        trip3.service_id = service.service_id
        schedule.AddTripObject(trip3)

        stop1 = transitfeed.Stop(36.425288, -117.139162, "Demo Stop 1",
                                 "STOP1")
        schedule.AddStopObject(stop1)
        trip1.AddStopTime(
            stop1,
            arrival_time="5:11:00",
            departure_time="5:12:00",
            stop_sequence=0,
            shape_dist_traveled=0,
        )
        trip2.AddStopTime(
            stop1,
            arrival_time="5:11:00",
            departure_time="5:12:00",
            stop_sequence=0,
            shape_dist_traveled=0,
        )
        trip3.AddStopTime(
            stop1,
            arrival_time="6:11:00",
            departure_time="6:12:00",
            stop_sequence=0,
            shape_dist_traveled=0,
        )

        stop2 = transitfeed.Stop(36.424288, -117.158142, "Demo Stop 2",
                                 "STOP2")
        schedule.AddStopObject(stop2)
        trip1.AddStopTime(
            stop2,
            arrival_time="5:15:00",
            departure_time="5:16:00",
            stop_sequence=1,
            shape_dist_traveled=1,
        )
        trip2.AddStopTime(
            stop2,
            arrival_time="5:25:00",
            departure_time="5:26:00",
            stop_sequence=1,
            shape_dist_traveled=1,
        )
        trip3.AddStopTime(
            stop2,
            arrival_time="6:15:00",
            departure_time="6:16:00",
            stop_sequence=1,
            shape_dist_traveled=1,
        )

        schedule.Validate(self.problems)
        e = self.accumulator.PopException("DuplicateTrip")
        self.assertTrue(e.FormatProblem().find("t1 of route") != -1)
        self.assertTrue(e.FormatProblem().find("t2 of route") != -1)
        self.accumulator.AssertNoMoreExceptions()
    def runTest(self):
        accumulator = util.RecordingProblemAccumulator(
            self, ignore_types=("ExpirationDate", ))
        problems = transitfeed.ProblemReporter(accumulator)
        schedule = transitfeed.Schedule(problem_reporter=problems)
        agency = transitfeed.Agency()
        agency.agency_id = "DTA"
        agency.agency_name = "Demo Transit Authority"
        agency.agency_url = "http://google.com"
        agency.agency_timezone = "America/Los_Angeles"
        agency.agency_lang = 'en'
        # Test that unknown columns, such as agency_mission, are preserved
        agency.agency_mission = "Get You There"
        schedule.AddAgencyObject(agency)

        routes = []
        route_data = [("AB", "DTA", "10", "Airport - Bullfrog", 3),
                      ("BFC", "DTA", "20", "Bullfrog - Furnace Creek Resort",
                       3),
                      ("STBA", "DTA", "30", "Stagecoach - Airport Shuttle", 3),
                      ("CITY", "DTA", "40", "City", 3),
                      ("AAMV", "DTA", "50", "Airport - Amargosa Valley", 3)]

        for route_entry in route_data:
            route = transitfeed.Route()
            (route.route_id, route.agency_id, route.route_short_name,
             route.route_long_name, route.route_type) = route_entry
            routes.append(route)
            schedule.AddRouteObject(route)

        shape_data = [
            (36.915760, -116.751709),
            (36.905018, -116.763206),
            (36.902134, -116.777969),
            (36.904091, -116.788185),
            (36.883602, -116.814537),
            (36.874523, -116.795593),
            (36.873302, -116.786491),
            (36.869202, -116.784241),
            (36.868515, -116.784729),
        ]

        shape = transitfeed.Shape("BFC1S")
        for (lat, lon) in shape_data:
            shape.AddPoint(lat, lon)
        schedule.AddShapeObject(shape)

        week_period = transitfeed.ServicePeriod()
        week_period.service_id = "FULLW"
        week_period.start_date = "20070101"
        week_period.end_date = "20071231"
        week_period.SetWeekdayService()
        week_period.SetWeekendService()
        week_period.SetDateHasService("20070604", False)
        schedule.AddServicePeriodObject(week_period)

        weekend_period = transitfeed.ServicePeriod()
        weekend_period.service_id = "WE"
        weekend_period.start_date = "20070101"
        weekend_period.end_date = "20071231"
        weekend_period.SetWeekendService()
        schedule.AddServicePeriodObject(weekend_period)

        stops = []
        stop_data = [
            ("FUR_CREEK_RES", "Furnace Creek Resort (Demo)", 36.425288,
             -117.133162, "zone-a", "1234"),
            ("BEATTY_AIRPORT", "Nye County Airport (Demo)", 36.868446,
             -116.784682, "zone-a", "1235"),
            ("BULLFROG", "Bullfrog (Demo)", 36.88108, -116.81797, "zone-b",
             "1236"),
            ("STAGECOACH", "Stagecoach Hotel & Casino (Demo)", 36.915682,
             -116.751677, "zone-c", "1237"),
            ("NADAV", "North Ave / D Ave N (Demo)", 36.914893, -116.76821, "",
             ""),
            ("NANAA", "North Ave / N A Ave (Demo)", 36.914944, -116.761472, "",
             ""),
            ("DADAN", "Doing AVe / D Ave N (Demo)", 36.909489, -116.768242, "",
             ""),
            ("EMSI", "E Main St / S Irving St (Demo)", 36.905697, -116.76218,
             "", ""),
            ("AMV", "Amargosa Valley (Demo)", 36.641496, -116.40094, "", ""),
        ]
        for stop_entry in stop_data:
            stop = transitfeed.Stop()
            (stop.stop_id, stop.stop_name, stop.stop_lat, stop.stop_lon,
             stop.zone_id, stop.stop_code) = stop_entry
            schedule.AddStopObject(stop)
            stops.append(stop)
        # Add a value to an unknown column and make sure it is preserved
        schedule.GetStop("BULLFROG").stop_sound = "croak!"

        trip_data = [
            ("AB", "FULLW", "AB1", "to Bullfrog", "0", "1", None),
            ("AB", "FULLW", "AB2", "to Airport", "1", "2", None),
            ("STBA", "FULLW", "STBA", "Shuttle", None, None, None),
            ("CITY", "FULLW", "CITY1", None, "0", None, None),
            ("CITY", "FULLW", "CITY2", None, "1", None, None),
            ("BFC", "FULLW", "BFC1", "to Furnace Creek Resort", "0", "1",
             "BFC1S"),
            ("BFC", "FULLW", "BFC2", "to Bullfrog", "1", "2", None),
            ("AAMV", "WE", "AAMV1", "to Amargosa Valley", "0", None, None),
            ("AAMV", "WE", "AAMV2", "to Airport", "1", None, None),
            ("AAMV", "WE", "AAMV3", "to Amargosa Valley", "0", None, None),
            ("AAMV", "WE", "AAMV4", "to Airport", "1", None, None),
        ]

        trips = []
        for trip_entry in trip_data:
            trip = transitfeed.Trip()
            (trip.route_id, trip.service_id, trip.trip_id, trip.trip_headsign,
             trip.direction_id, trip.block_id, trip.shape_id) = trip_entry
            trips.append(trip)
            schedule.AddTripObject(trip)

        stop_time_data = {
            "STBA":
            [("6:00:00", "6:00:00", "STAGECOACH", None, None, None, None),
             ("6:20:00", "6:20:00", "BEATTY_AIRPORT", None, None, None, None)],
            "CITY1":
            [("6:00:00", "6:00:00", "STAGECOACH", 1.34, 0, 0, "stop 1"),
             ("6:05:00", "6:07:00", "NANAA", 2.40, 1, 2, "stop 2"),
             ("6:12:00", "6:14:00", "NADAV", 3.0, 2, 2, "stop 3"),
             ("6:19:00", "6:21:00", "DADAN", 4, 2, 2, "stop 4"),
             ("6:26:00", "6:28:00", "EMSI", 5.78, 2, 3, "stop 5")],
            "CITY2": [("6:28:00", "6:28:00", "EMSI", None, None, None, None),
                      ("6:35:00", "6:37:00", "DADAN", None, None, None, None),
                      ("6:42:00", "6:44:00", "NADAV", None, None, None, None),
                      ("6:49:00", "6:51:00", "NANAA", None, None, None, None),
                      ("6:56:00", "6:58:00", "STAGECOACH", None, None, None,
                       None)],
            "AB1":
            [("8:00:00", "8:00:00", "BEATTY_AIRPORT", None, None, None, None),
             ("8:10:00", "8:15:00", "BULLFROG", None, None, None, None)],
            "AB2":
            [("12:05:00", "12:05:00", "BULLFROG", None, None, None, None),
             ("12:15:00", "12:15:00", "BEATTY_AIRPORT", None, None, None, None)
             ],
            "BFC1": [
                ("8:20:00", "8:20:00", "BULLFROG", None, None, None, None),
                ("9:20:00", "9:20:00", "FUR_CREEK_RES", None, None, None, None)
            ],
            "BFC2":
            [("11:00:00", "11:00:00", "FUR_CREEK_RES", None, None, None, None),
             ("12:00:00", "12:00:00", "BULLFROG", None, None, None, None)],
            "AAMV1": [("8:00:00", "8:00:00", "BEATTY_AIRPORT", None, None,
                       None, None),
                      ("9:00:00", "9:00:00", "AMV", None, None, None, None)],
            "AAMV2": [("10:00:00", "10:00:00", "AMV", None, None, None, None),
                      ("11:00:00", "11:00:00", "BEATTY_AIRPORT", None, None,
                       None, None)],
            "AAMV3": [("13:00:00", "13:00:00", "BEATTY_AIRPORT", None, None,
                       None, None),
                      ("14:00:00", "14:00:00", "AMV", None, None, None, None)],
            "AAMV4": [("15:00:00", "15:00:00", "AMV", None, None, None, None),
                      ("16:00:00", "16:00:00", "BEATTY_AIRPORT", None, None,
                       None, None)],
        }

        for trip_id, stop_time_list in stop_time_data.items():
            for stop_time_entry in stop_time_list:
                (arrival_time, departure_time, stop_id, shape_dist_traveled,
                 pickup_type, drop_off_type, stop_headsign) = stop_time_entry
                trip = schedule.GetTrip(trip_id)
                stop = schedule.GetStop(stop_id)
                trip.AddStopTime(stop,
                                 arrival_time=arrival_time,
                                 departure_time=departure_time,
                                 shape_dist_traveled=shape_dist_traveled,
                                 pickup_type=pickup_type,
                                 drop_off_type=drop_off_type,
                                 stop_headsign=stop_headsign)

        self.assertEqual(
            0,
            schedule.GetTrip("CITY1").GetStopTimes()[0].pickup_type)
        self.assertEqual(
            1,
            schedule.GetTrip("CITY1").GetStopTimes()[1].pickup_type)

        headway_data = [
            ("STBA", "6:00:00", "22:00:00", 1800),
            ("CITY1", "6:00:00", "7:59:59", 1800),
            ("CITY2", "6:00:00", "7:59:59", 1800),
            ("CITY1", "8:00:00", "9:59:59", 600),
            ("CITY2", "8:00:00", "9:59:59", 600),
            ("CITY1", "10:00:00", "15:59:59", 1800),
            ("CITY2", "10:00:00", "15:59:59", 1800),
            ("CITY1", "16:00:00", "18:59:59", 600),
            ("CITY2", "16:00:00", "18:59:59", 600),
            ("CITY1", "19:00:00", "22:00:00", 1800),
            ("CITY2", "19:00:00", "22:00:00", 1800),
        ]

        headway_trips = {}
        for headway_entry in headway_data:
            (trip_id, start_time, end_time, headway) = headway_entry
            headway_trips[trip_id] = []  # adding to set to check later
            trip = schedule.GetTrip(trip_id)
            trip.AddFrequency(start_time, end_time, headway, 0, problems)
        for trip_id in headway_trips:
            headway_trips[trip_id] = \
                schedule.GetTrip(trip_id).GetFrequencyTuples()

        fare_data = [
            ("p", 1.25, "USD", 0, 0),
            ("a", 5.25, "USD", 0, 0),
        ]

        fares = []
        for fare_entry in fare_data:
            fare = transitfeed.FareAttribute(fare_entry[0], fare_entry[1],
                                             fare_entry[2], fare_entry[3],
                                             fare_entry[4])
            fares.append(fare)
            schedule.AddFareAttributeObject(fare)

        fare_rule_data = [
            ("p", "AB", "zone-a", "zone-b", None),
            ("p", "STBA", "zone-a", None, "zone-c"),
            ("p", "BFC", None, "zone-b", "zone-a"),
            ("a", "AAMV", None, None, None),
        ]

        for fare_id, route_id, orig_id, dest_id, contains_id in fare_rule_data:
            rule = transitfeed.FareRule(fare_id=fare_id,
                                        route_id=route_id,
                                        origin_id=orig_id,
                                        destination_id=dest_id,
                                        contains_id=contains_id)
            schedule.AddFareRuleObject(rule, problems)

        schedule.Validate(problems)
        accumulator.AssertNoMoreExceptions()
        schedule.WriteGoogleTransitFeed(self.tempfilepath)

        read_schedule = \
            transitfeed.Loader(self.tempfilepath, problems=problems,
                               extra_validation=True).Load()
        e = accumulator.PopException("UnrecognizedColumn")
        self.assertEqual(e.file_name, "agency.txt")
        self.assertEqual(e.column_name, "agency_mission")
        e = accumulator.PopException("UnrecognizedColumn")
        self.assertEqual(e.file_name, "stops.txt")
        self.assertEqual(e.column_name, "stop_sound")
        accumulator.AssertNoMoreExceptions()

        self.assertEqual(1, len(read_schedule.GetAgencyList()))
        self.assertEqual(agency, read_schedule.GetAgency(agency.agency_id))

        self.assertEqual(len(routes), len(read_schedule.GetRouteList()))
        for route in routes:
            self.assertEqual(route, read_schedule.GetRoute(route.route_id))

        self.assertEqual(2, len(read_schedule.GetServicePeriodList()))
        self.assertEqual(
            week_period,
            read_schedule.GetServicePeriod(week_period.service_id))
        self.assertEqual(
            weekend_period,
            read_schedule.GetServicePeriod(weekend_period.service_id))

        self.assertEqual(len(stops), len(read_schedule.GetStopList()))
        for stop in stops:
            self.assertEqual(stop, read_schedule.GetStop(stop.stop_id))
        self.assertEqual("croak!",
                         read_schedule.GetStop("BULLFROG").stop_sound)

        self.assertEqual(len(trips), len(read_schedule.GetTripList()))
        for trip in trips:
            self.assertEqual(trip, read_schedule.GetTrip(trip.trip_id))

        for trip_id in headway_trips:
            self.assertEqual(
                headway_trips[trip_id],
                read_schedule.GetTrip(trip_id).GetFrequencyTuples())

        for trip_id, stop_time_list in stop_time_data.items():
            trip = read_schedule.GetTrip(trip_id)
            read_stoptimes = trip.GetStopTimes()
            self.assertEqual(len(read_stoptimes), len(stop_time_list))
            for stop_time_entry, read_stoptime in zip(stop_time_list,
                                                      read_stoptimes):
                (arrival_time, departure_time, stop_id, shape_dist_traveled,
                 pickup_type, drop_off_type, stop_headsign) = stop_time_entry
                self.assertEqual(stop_id, read_stoptime.stop_id)
                self.assertEqual(read_schedule.GetStop(stop_id),
                                 read_stoptime.stop)
                self.assertEqualTimeString(arrival_time,
                                           read_stoptime.arrival_time)
                self.assertEqualTimeString(departure_time,
                                           read_stoptime.departure_time)
                self.assertEqual(shape_dist_traveled,
                                 read_stoptime.shape_dist_traveled)
                self.assertEqualWithDefault(pickup_type,
                                            read_stoptime.pickup_type, 0)
                self.assertEqualWithDefault(drop_off_type,
                                            read_stoptime.drop_off_type, 0)
                self.assertEqualWithDefault(stop_headsign,
                                            read_stoptime.stop_headsign, '')

        self.assertEqual(len(fares), len(read_schedule.GetFareAttributeList()))
        for fare in fares:
            self.assertEqual(fare,
                             read_schedule.GetFareAttribute(fare.fare_id))

        read_fare_rules_data = []
        for fare in read_schedule.GetFareAttributeList():
            for rule in fare.GetFareRuleList():
                self.assertEqual(fare.fare_id, rule.fare_id)
                read_fare_rules_data.append(
                    (fare.fare_id, rule.route_id, rule.origin_id,
                     rule.destination_id, rule.contains_id))

        fare_rule_data.sort()
        read_fare_rules_data.sort()
        self.assertEqual(len(read_fare_rules_data), len(fare_rule_data))
        for rf, f in zip(read_fare_rules_data, fare_rule_data):
            self.assertEqual(rf, f)

        self.assertEqual(1, len(read_schedule.GetShapeList()))
        self.assertEqual(shape, read_schedule.GetShape(shape.shape_id))
Ejemplo n.º 20
0
    def runTest(self):
        stop = transitfeed.Stop()
        self.ExpectInvalidValueInClosure(
            'arrival_time', '1a:00:00', lambda: transitfeed.StopTime(
                self.problems, stop, arrival_time="1a:00:00"))
        self.ExpectInvalidValueInClosure(
            'departure_time', '1a:00:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='1a:00:00'))
        self.ExpectInvalidValueInClosure(
            'pickup_type', '7.8',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='7.8',
                                         drop_off_type='0'))
        self.ExpectInvalidValueInClosure(
            'drop_off_type', 'a',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='a'))
        self.ExpectInvalidValueInClosure(
            'shape_dist_traveled', '$',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='0',
                                         shape_dist_traveled='$'))
        self.ExpectInvalidValueInClosure(
            'shape_dist_traveled', '0,53',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='0',
                                         shape_dist_traveled='0,53'))
        self.ExpectOtherProblemInClosure(lambda: transitfeed.StopTime(
            self.problems, stop, pickup_type='1', drop_off_type='1'))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:00:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="11:00:00",
                                         departure_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'arrival_time', lambda: transitfeed.StopTime(
                self.problems, stop, departure_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'arrival_time',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         departure_time="10:00:00",
                                         arrival_time=""))
        self.ExpectMissingValueInClosure(
            'departure_time', lambda: transitfeed.StopTime(
                self.problems, stop, arrival_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'departure_time',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time=""))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:70:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time="10:70:00"))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:00:62',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time="10:00:62"))
        self.ExpectInvalidValueInClosure(
            'arrival_time', '10:00:63',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:63",
                                         departure_time="10:10:00"))
        self.ExpectInvalidValueInClosure(
            'arrival_time', '10:60:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:60:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', "id",
            lambda: transitfeed.StopTime(self.problems,
                                         "id",
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', "3",
            lambda: transitfeed.StopTime(self.problems,
                                         "3",
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', None,
            lambda: transitfeed.StopTime(self.problems,
                                         None,
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))

        # The following should work
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="10:00:00",
                             departure_time="10:05:00",
                             pickup_type='1',
                             drop_off_type='1')
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="10:00:00",
                             departure_time="10:05:00",
                             pickup_type='1',
                             drop_off_type='1')
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="1:00:00",
                             departure_time="1:05:00")
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="24:59:00",
                             departure_time="25:05:00")
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="101:01:00",
                             departure_time="101:21:00")
        transitfeed.StopTime(self.problems, stop)
        self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 21
0
    def runTest(self):
        # success case
        stop = transitfeed.Stop()
        stop.stop_id = '45'
        stop.stop_name = 'Couch AT End Table'
        stop.stop_lat = 50.0
        stop.stop_lon = 50.0
        stop.stop_desc = 'Edge of the Couch'
        stop.zone_id = 'A'
        stop.stop_url = 'http://example.com'
        stop.wheelchair_boarding = '2'
        stop.Validate(self.problems)

        # latitude too large
        stop.stop_lat = 100.0
        self.ValidateAndExpectInvalidValue(stop, 'stop_lat')
        stop.stop_lat = 50.0

        # latitude as a string works when it is valid
        # empty strings or whitespaces should get reported as MissingValue
        stop.stop_lat = '50.0'
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()
        stop.stop_lat = '10f'
        self.ValidateAndExpectInvalidValue(stop, 'stop_lat')
        stop.stop_lat = 'None'
        self.ValidateAndExpectInvalidValue(stop, 'stop_lat')
        stop.stop_lat = ''
        self.ValidateAndExpectMissingValue(stop, 'stop_lat')
        stop.stop_lat = ' '
        self.ValidateAndExpectMissingValue(stop, 'stop_lat')
        stop.stop_lat = 50.0

        # longitude too large
        stop.stop_lon = 200.0
        self.ValidateAndExpectInvalidValue(stop, 'stop_lon')
        stop.stop_lon = 50.0

        # longitude as a string works when it is valid
        # empty strings or whitespaces should get reported as MissingValue
        stop.stop_lon = '50.0'
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()
        stop.stop_lon = '10f'
        self.ValidateAndExpectInvalidValue(stop, 'stop_lon')
        stop.stop_lon = 'None'
        self.ValidateAndExpectInvalidValue(stop, 'stop_lon')
        stop.stop_lon = ''
        self.ValidateAndExpectMissingValue(stop, 'stop_lon')
        stop.stop_lon = ' '
        self.ValidateAndExpectMissingValue(stop, 'stop_lon')
        stop.stop_lon = 50.0

        # lat, lon too close to 0, 0
        stop.stop_lat = 0.0
        stop.stop_lon = 0.0
        self.ValidateAndExpectInvalidValue(stop, 'stop_lat')
        stop.stop_lat = 50.0
        stop.stop_lon = 50.0

        # invalid stop_url
        stop.stop_url = 'www.example.com'
        self.ValidateAndExpectInvalidValue(stop, 'stop_url')
        stop.stop_url = 'http://example.com'

        stop.stop_id = '   '
        self.ValidateAndExpectMissingValue(stop, 'stop_id')
        stop.stop_id = '45'

        stop.stop_name = ''
        self.ValidateAndExpectMissingValue(stop, 'stop_name')
        stop.stop_name = ' '
        self.ValidateAndExpectMissingValue(stop, 'stop_name')
        stop.stop_name = 'Couch AT End Table'

        # description same as name
        stop.stop_desc = 'Couch AT End Table'
        self.ValidateAndExpectInvalidValue(stop, 'stop_desc')
        stop.stop_desc = 'Edge of the Couch'
        self.accumulator.AssertNoMoreExceptions()

        stop.stop_timezone = 'This_Timezone/Does_Not_Exist'
        self.ValidateAndExpectInvalidValue(stop, 'stop_timezone')
        stop.stop_timezone = 'America/Los_Angeles'
        stop.Validate(self.problems)
        self.accumulator.AssertNoMoreExceptions()

        # invalid wheelchair_boarding
        stop.wheelchair_boarding = '3'
        self.ValidateAndExpectInvalidValue(stop, 'wheelchair_boarding')
        stop.wheelchair_boarding = None