def test_equal_operator(self): for row in ALL_CSV_ROWS: td1 = create_full_transit_data() td2 = create_full_transit_data() trip1 = td1.trips.add(**row) trip2 = td2.trips.add(**row) self.assertEqual(trip1, trip2)
def test_equal_operator(self): for row in ALL_CSV_ROWS: td1 = create_full_transit_data() td2 = create_full_transit_data() fare_rule1 = td1.fare_rules.add(**row) fare_rule2 = td2.fare_rules.add(**row) self.assertEqual(fare_rule1, fare_rule2)
def test_equal_operator(self): for row in ALL_CSV_ROWS: td1 = create_full_transit_data() td2 = create_full_transit_data() route1 = td1.routes.add(**row) route2 = td2.routes.add(**row) self.assertEqual(route1, route2)
def test_equal_operator(self): for row in ALL_CSV_ROWS: td1 = create_full_transit_data() td2 = create_full_transit_data() stop_time1 = td1.add_stop_time(**row) stop_time2 = td2.add_stop_time(**row) self.assertEqual(stop_time1, stop_time2)
def test_add_object(self): for row in ALL_CSV_ROWS: source_td = create_full_transit_data() dest_td = create_full_transit_data() source_fare_rule = source_td.fare_rules.add(**row) dest_fare_rule = dest_td.fare_rules.add_object(source_fare_rule) self.assertEqual(source_fare_rule, dest_fare_rule)
def test_add_object(self): for row in ALL_CSV_ROWS: source_td = create_full_transit_data() dest_td = create_full_transit_data() source_trip = source_td.trips.add(**row) dest_trip = dest_td.trips.add_object(source_trip) self.assertEqual(source_trip, dest_trip) trips_num = len(dest_td.trips) dest_td.trips.add_object(source_trip) self.assertEqual(trips_num, len(dest_td.trips)) source_trip.wheelchair_accessible = not source_trip.wheelchair_accessible self.assertRaises(Exception, dest_td.trips.add_object, source_trip)
def test_add_object(self): for row in ALL_CSV_ROWS: source_td = create_full_transit_data() dest_td = create_full_transit_data() source_route = source_td.routes.add(**row) dest_route = dest_td.routes.add_object(source_route) self.assertEqual(source_route, dest_route) routes_num = len(dest_td.routes) dest_td.routes.add_object(source_route) self.assertEqual(routes_num, len(dest_td.routes)) source_route.route_short_name = "2" self.assertRaises(Exception, dest_td.routes.add_object, source_route)
def test_minimum_properties(self): td = create_full_transit_data() fare_attribute = td.fare_attributes.add(**MINI_FARE_ATTRIBUTE_CSV_ROW) self.assertTrue(hasattr(fare_attribute, "id")) self.assertRaises(Exception, setattr, fare_attribute, "id", "2") test_property(self, fare_attribute, property_name="price", new_value=1) test_property(self, fare_attribute, property_name="currency_type", new_value="USD") test_property(self, fare_attribute, property_name="payment_method", new_value=1) test_property(self, fare_attribute, property_name="is_prepaid_needed", new_value=not fare_attribute.is_prepaid_needed) test_property(self, fare_attribute, property_name="transfers", new_value=1) test_property(self, fare_attribute, property_name="agency", new_value=td.agencies[15]) test_property(self, fare_attribute, property_name="transfer_duration", new_value=2)
def test_add(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() starting_fare_attributes_num = len(td.fare_attributes) fare_attribute = td.fare_attributes.add(**row) self.assertIn(fare_attribute, td.fare_attributes) self.assertIsInstance(fare_attribute.id, str) self.assertEqual(fare_attribute.id, row["fare_id"]) self.assertEqual(fare_attribute.price, float(row.get("price"))) self.assertEqual(fare_attribute.currency_type, row.get("currency_type")) self.assertEqual(fare_attribute.payment_method, row.get("payment_method")) self.assertEqual(fare_attribute.is_prepaid_needed, bool(row.get("payment_method"))) self.assertEqual(fare_attribute.transfers, row.get("transfers")) self.assertEqual( fare_attribute.agency, td.agencies[row.get("agency_id")] if "agency_id" in row else None) self.assertEqual(fare_attribute.transfer_duration, row.get("transfer_duration")) self.assertEqual(fare_attribute.attributes.get("test_attribute"), row.get("test_attribute")) self.assertEqual(len(fare_attribute.attributes), len(row) - 5) self.assertRaises(Exception, td.fare_attributes.add, **row) self.assertEqual(len(td.fare_attributes), starting_fare_attributes_num + 1)
def test_add(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() starting_routes_num = len(td.routes) route = td.routes.add(**row) self.assertIn(route, td.routes) self.assertEqual(route.id, row["route_id"]) self.assertEqual(route.route_short_name, row.get("route_short_name")) self.assertEqual(route.route_long_name, row.get("route_long_name")) self.assertEqual(route.route_type, row.get("route_type")) self.assertEqual(route.agency, td.agencies[row.get("agency_id")]) self.assertEqual(route.route_desc, row.get("route_desc")) self.assertEqual(route.route_url, row.get("route_url")) self.assertEqual(route.route_color, row.get("route_color")) self.assertEqual(route.route_text_color, row.get("route_text_color")) self.assertEqual(route.route_sort_order, row.get("route_sort_order")) self.assertEqual(route.attributes.get("test_attribute"), row.get("test_attribute")) self.assertEqual(len(route.attributes), len(row) - 5) self.assertRaises(Exception, td.routes.add, **row) self.assertEqual(len(td.routes), starting_routes_num + 1)
def test_add(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() starting_trips_num = len(td.trips) trip = td.trips.add(**row) self.assertIn(trip, td.trips) self.assertEqual(trip.id, row["trip_id"]) self.assertEqual(trip.route, td.routes[row.get("route_id")]) self.assertEqual(trip.service, td.calendar[row.get("service_id")]) self.assertEqual(trip.trip_headsign, row.get("trip_headsign")) self.assertEqual(trip.trip_short_name, row.get("trip_short_name")) self.assertEqual(trip.direction_id, row.get("direction_id")) self.assertEqual(trip.block_id, row.get("block_id")) self.assertEqual( trip.shape, td.shapes[row["shape_id"]] if "shape_id" in row else None) self.assertEqual(trip.bikes_allowed, parse_yes_no_unknown(row.get("bikes_allowed"))) self.assertEqual( trip.wheelchair_accessible, parse_yes_no_unknown(row.get("wheelchair_accessible"))) self.assertEqual(trip.original_trip_id, row.get("original_trip_id")) self.assertEqual(trip.attributes.get("test_attribute"), row.get("test_attribute")) self.assertEqual(len(trip.attributes), len(row) - 3) self.assertRaises(Exception, td.trips.add, **row) self.assertEqual(len(td.trips), starting_trips_num + 1)
def test_maximum_properties(self): td = create_full_transit_data() fare_rule = td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) test_property(self, fare_rule, property_name="fare", new_value=td.fare_attributes["2"]) test_property(self, fare_rule, property_name="route", new_value=td.routes["1002"]) test_property(self, fare_rule, property_name="origin_id", new_value=2) test_property(self, fare_rule, property_name="destination_id", new_value=1) test_property(self, fare_rule, property_name="contains_id", new_value=1) self.assertIn("test_attribute", fare_rule.attributes) test_attribute(self, fare_rule, attribute_name="test_attribute", new_value="new test data")
def test_add_object(self): for row in ALL_CSV_ROWS: source_td = create_full_transit_data() dest_td = create_full_transit_data() source_fare_attribute = source_td.fare_attributes.add(**row) dest_fare_attribute = dest_td.fare_attributes.add_object( source_fare_attribute) self.assertEqual(source_fare_attribute, dest_fare_attribute) fare_attributes_num = len(dest_td.fare_attributes) dest_td.fare_attributes.add_object(source_fare_attribute) self.assertEqual(fare_attributes_num, len(dest_td.fare_attributes)) source_fare_attribute.price = 2.4 self.assertRaises(Exception, dest_td.fare_attributes.add_object, source_fare_attribute)
def test_maximum_properties(self): td = create_full_transit_data() stop_time = td.add_stop_time(**FULL_STOP_TIME_CSV_ROW) test_property(self, stop_time, property_name="trip", new_value=td.trips["1001_2"]) test_property(self, stop_time, property_name="arrival_time", new_value=timedelta(hours=2)) test_property(self, stop_time, property_name="departure_time", new_value=timedelta(hours=3)) test_property(self, stop_time, property_name="stop", new_value=td.stops[20000]) test_property(self, stop_time, property_name="stop_sequence", new_value=1) test_property(self, stop_time, property_name="pickup_type", new_value=2) test_property(self, stop_time, property_name="drop_off_type", new_value=2) test_property(self, stop_time, property_name="allow_pickup", new_value=False) test_property(self, stop_time, property_name="allow_drop_off", new_value=False) test_property(self, stop_time, property_name="shape_dist_traveled", new_value=1) test_property(self, stop_time, property_name="stop_headsign", new_value="new headsign") test_property(self, stop_time, property_name="is_exact_time", new_value=not stop_time.is_exact_time) self.assertIn("test_attribute", stop_time.attributes) test_attribute(self, stop_time, attribute_name="test_attribute", new_value="new test data")
def test_remove(self): td = create_full_transit_data() fare_rule = td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) self.assertIn(fare_rule, td.fare_rules) td.fare_rules.remove(fare_rule) self.assertNotIn(fare_rule, td.fare_rules) td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) self.assertIn(fare_rule, td.fare_rules) td.fare_rules.remove(fare_rule) self.assertNotIn(fare_rule, td.fare_rules)
def test_remove(self): td = create_full_transit_data() trip = td.trips.add(**FULL_TRIP_CSV_ROW) self.assertIn(trip, td.trips) td.trips.remove(trip) self.assertNotIn(trip, td.trips) td.trips.add(**FULL_TRIP_CSV_ROW) self.assertIn(trip, td.trips) td.trips.remove(trip.id) self.assertNotIn(trip, td.trips)
def test_remove(self): td = create_full_transit_data() fare_attribute = td.fare_attributes.add(**FULL_FARE_ATTRIBUTE_CSV_ROW) self.assertIn(fare_attribute, td.fare_attributes) td.fare_attributes.remove(fare_attribute) self.assertNotIn(fare_attribute, td.fare_attributes) td.fare_attributes.add(**FULL_FARE_ATTRIBUTE_CSV_ROW) self.assertIn(fare_attribute, td.fare_attributes) td.fare_attributes.remove(fare_attribute.id) self.assertNotIn(fare_attribute, td.fare_attributes)
def test_remove(self): td = create_full_transit_data() route = td.routes.add(**FULL_ROUTE_CSV_ROW) self.assertIn(route, td.routes) td.routes.remove(route) self.assertNotIn(route, td.routes) td.routes.add(**FULL_ROUTE_CSV_ROW) self.assertIn(route, td.routes) td.routes.remove(route.id) self.assertNotIn(route, td.routes)
def test_maximum_properties(self): td = create_full_transit_data() trip = td.trips.add(**FULL_TRIP_CSV_ROW) self.assertTrue(hasattr(trip, "id")) self.assertRaises(Exception, setattr, trip, "id", "2") test_property(self, trip, property_name="route", new_value=td.routes['1002']) test_property(self, trip, property_name="service", new_value=td.calendar['2']) test_property(self, trip, property_name="trip_headsign", new_value="new headsign") test_property(self, trip, property_name="trip_short_name", new_value="2") test_property(self, trip, property_name="direction_id", new_value="2") test_property(self, trip, property_name="block_id", new_value='2') test_property(self, trip, property_name="shape", new_value=td.shapes['2']) test_property(self, trip, property_name="bikes_allowed", new_value=False) test_property(self, trip, property_name="wheelchair_accessible", new_value=True) test_property(self, trip, property_name="original_trip_id", new_value="2 origin") self.assertIn("test_attribute", trip.attributes) test_attribute(self, trip, attribute_name="test_attribute", new_value="new test data")
def test_clean(self): td = create_full_transit_data() for trip in td.trips: for stop_time in list(trip.stop_times): stop_time.trip.stop_times.remove(stop_time) stop_time.stop.stop_times.remove(stop_time) td.clean() self.assertEqual(0, len(td.agencies)) self.assertEqual(0, len(td.routes)) self.assertEqual(0, len(td.trips)) self.assertEqual(0, len(td.shapes)) self.assertEqual(0, len(td.calendar)) self.assertEqual(0, len(td.stops)) self.assertEqual(0, len(td.fare_attributes)) self.assertEqual(0, len(td.fare_rules))
def test_maximum_properties(self): td = create_full_transit_data() route = td.routes.add(**FULL_ROUTE_CSV_ROW) self.assertTrue(hasattr(route, "id")) self.assertRaises(Exception, setattr, route, "id", "2") test_property(self, route, property_name="route_short_name", new_value="2") test_property(self, route, property_name="route_long_name", new_value="new name") test_property(self, route, property_name="route_type", new_value=2) test_property(self, route, property_name="agency", new_value=td.agencies['15']) test_property(self, route, property_name="route_desc", new_value="new route desc") test_property(self, route, property_name="route_url", new_value="http://testurl.com/") test_property(self, route, property_name="route_color", new_value="FFFF00") test_property(self, route, property_name="route_text_color", new_value="0000FF") test_property(self, route, property_name="route_sort_order", new_value=2) self.assertIn("test_attribute", route.attributes) test_attribute(self, route, attribute_name="test_attribute", new_value="new test data")
def test_maximum_properties(self): td = create_full_transit_data() fare_attribute = td.fare_attributes.add(**FULL_FARE_ATTRIBUTE_CSV_ROW) self.assertTrue(hasattr(fare_attribute, "id")) self.assertRaises(Exception, setattr, fare_attribute, "id", "2") test_property(self, fare_attribute, property_name="price", new_value=1) test_property(self, fare_attribute, property_name="currency_type", new_value="USD") test_property(self, fare_attribute, property_name="payment_method", new_value=1) test_property(self, fare_attribute, property_name="is_prepaid_needed", new_value=not fare_attribute.is_prepaid_needed) test_property(self, fare_attribute, property_name="transfers", new_value=1) test_property(self, fare_attribute, property_name="agency", new_value=td.agencies[15]) test_property(self, fare_attribute, property_name="transfer_duration", new_value=2) self.assertIn("test_attribute", fare_attribute.attributes) fare_attribute.attributes["test_attribute"] = "new test data" self.assertEqual(fare_attribute.attributes["test_attribute"], "new test data") self.assertNotIn("test_attribute2", fare_attribute.attributes) fare_attribute.attributes["test_attribute2"] = "more test data" self.assertEqual(fare_attribute.attributes["test_attribute2"], "more test data")
def test_not_equal_operator(self): original_td = create_full_transit_data() original_fare_rule = original_td.fare_rules.add( **FULL_FARE_RULE_CSV_ROW) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.fare = new_td.fare_attributes["2"] self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.route = new_td.routes["1002"] self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.origin_id = 2 self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.destination_id = 1 self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.contains_id = 1 self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.attributes["test_attribute"] = "new test data" self.assertNotEqual(original_fare_rule, edited_fare_rule) new_td = create_full_transit_data() edited_fare_rule = new_td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) edited_fare_rule.attributes["test_attribute2"] = "new test data" self.assertNotEqual(original_fare_rule, edited_fare_rule)
def test_add(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() starting_fare_rules_num = len(td.fare_rules) fare_rule = td.fare_rules.add(**row) self.assertIn(fare_rule, td.fare_rules) self.assertEqual(fare_rule.fare, td.fare_attributes[row.get("fare_id")]) self.assertEqual( fare_rule.route, td.routes[row.get("route_id")] if "route_id" in row else None) self.assertEqual(fare_rule.origin_id, row.get("origin_id")) self.assertEqual(fare_rule.destination_id, row.get("destination_id")) self.assertEqual(fare_rule.contains_id, row.get("contains_id")) self.assertEqual(len(fare_rule.attributes), len(row) - 1) # self.assertRaises(Exception, td.fare_rules.add, **row) self.assertEqual(len(td.fare_rules), starting_fare_rules_num + 1)
def test_get_csv_fields(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() fare_rule = td.fare_rules.add(**row) self.assertListEqual(sorted(fare_rule.get_csv_fields()), sorted(row.iterkeys()))
def test_get_csv_line(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() fare_rule = td.fare_rules.add(**row) self.assertDictEqual(fare_rule.to_csv_line(), row)
def test_not_equal_operator(self): original_td = create_full_transit_data() original_trip = original_td.trips.add(**FULL_TRIP_CSV_ROW) new_td = create_full_transit_data() row = dict(FULL_TRIP_CSV_ROW) row["trip_id"] = "2" edited_trip = new_td.trips.add(**row) self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.route = new_td.routes['1002'] self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.service = new_td.calendar['2'] self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.trip_headsign = "new headsign" self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.trip_short_name = "2" self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.direction_id = 2 self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.block_id = 2 self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.shape = new_td.shapes['2'] self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.bikes_allowed = False self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.wheelchair_accessible = True self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.original_trip_id = "2 origin" self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.attributes["test_attribute"] = "new test data" self.assertNotEqual(original_trip, edited_trip) new_td = create_full_transit_data() edited_trip = new_td.trips.add(**FULL_TRIP_CSV_ROW) edited_trip.attributes["test_attribute2"] = "new test data" self.assertNotEqual(original_trip, edited_trip)
def test_clean(self): td = create_full_transit_data() trip = td.fare_rules.add(**FULL_FARE_RULE_CSV_ROW) self.assertIn(trip, td.fare_rules) td.fare_rules.clean() self.assertNotIn(trip, td.fare_rules)
def test_clean(self): td = create_full_transit_data() trip = td.trips.add(**FULL_TRIP_CSV_ROW) self.assertIn(trip, td.trips) td.trips.clean() self.assertNotIn(trip, td.trips)
def test_get_csv_fields(self): for row in ALL_CSV_ROWS: td = create_full_transit_data() trip = td.trips.add(**row) self.assertListEqual(sorted(trip.get_csv_fields()), sorted(list(row.keys())))