def test_empty_value(): """ test_empty_value: test if it doesn't overwrite values with empty string """ temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["to_stop_id"] = "" with pytest.raises(MissingKeyError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values())
def test_invalid_key(): """ test_invalid_key: test if it errors if an invalid key is passed """ temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["transfer_favorite_food"] = "Pizza" with pytest.raises(InvalidKeyError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values())
def test_missing_key(): """ test_missing_key: check if it errors if a required key is missing """ temp_dict = MINIMAL_TRANSFER_DICT.copy() del temp_dict["from_stop_id"] with pytest.raises(MissingKeyError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_TRANSFER_DICT.copy() del temp_dict["to_stop_id"] with pytest.raises(MissingKeyError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values())
def test_transfer_happyflow_full(): """ test_transfer_happyflow_full: full, correct example """ transfer = Transfer.from_gtfs(FULL_TRANSFER_DICT.keys(), FULL_TRANSFER_DICT.values()) assert transfer == FULL_TRANSFER
def test_transfer_happyflow_minimal(): """ test_transfer_happyflow_minimal: minimal, correct example """ transfer = Transfer.from_gtfs(MINIMAL_TRANSFER_DICT.keys(), MINIMAL_TRANSFER_DICT.values()) assert transfer == MINIMAL_TRANSFER
def test_default(): """ test_default: check for correct default values (wheelchair_boarding and location_type) """ temp_dict = MINIMAL_TRANSFER_DICT.copy() del temp_dict["transfer_type"] temp_transfer = Transfer.from_gtfs(temp_dict.keys(), temp_dict.values()) assert temp_transfer.transfer_type == 0
def parse_transfers(self, transfer): """ parse_transfers: read transfers.txt Arguments: transfer: bytes-like object containing the contents of `transfers.txt` """ transfer_info = [ line.strip().split(',') for line in str(transfer, "UTF-8").strip().split('\n') ] for line in transfer_info[1:]: self.transfers.append(Transfer.from_gtfs(transfer_info[0], line))
def test_equal(): """ test_equal: check if __eq__ functions """ assert MINIMAL_TRANSFER == MINIMAL_TRANSFER assert MINIMAL_TRANSFER != FULL_TRANSFER assert FULL_TRANSFER != MINIMAL_TRANSFER assert FULL_TRANSFER == FULL_TRANSFER assert MINIMAL_TRANSFER != "MINIMAL_TRANSFER" temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["to_stop_id"] = "124" temp_transfer = Transfer.from_dict(temp_dict) assert temp_transfer != MINIMAL_TRANSFER
def __init__(self, url): self.engine = sqlalchemy.create_engine(url) self.connection = self.engine.connect() self.meta = sqlalchemy.MetaData() self.meta.bind = self.engine self.tables = {} self.tables["agencies"] = Agency.create_table(self.meta) self.tables["fare_attributes"] = FareAttribute.create_table(self.meta) self.tables["routes"] = Route.create_table(self.meta) self.tables["stops"] = Stop.create_table(self.meta) self.tables["fare_rules"] = FareRule.create_table(self.meta) self.tables["feed_infos"] = FeedInfo.create_table(self.meta) self.tables["frequencies"] = Frequency.create_table(self.meta) self.tables["levels"] = Level.create_table(self.meta) self.tables["pathways"] = Pathway.create_table(self.meta) self.tables["services"] = Service.create_table(self.meta) self.tables["shapes"] = Shape.create_table(self.meta) self.tables["stop_times"] = StopTime.create_table(self.meta) self.tables["transfers"] = Transfer.create_table(self.meta) self.tables["translations"] = Translation.create_table(self.meta) self.tables["trips"] = Trip.create_table(self.meta)
def test_invalid_values(): """ test_invalid_values: test for values out of range, invalid enums, ... """ temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["transfer_type"] = "-1" with pytest.raises(InvalidValueError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["transfer_type"] = "4" with pytest.raises(InvalidValueError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_TRANSFER_DICT.copy() temp_dict["min_transfer_time"] = "-1" with pytest.raises(InvalidValueError): Transfer.from_gtfs(temp_dict.keys(), temp_dict.values())
"to_stop_id": "123", "transfer_type": "2" } FULL_TRANSFER_DICT = { "from_stop_id": "124", "to_stop_id": "124", "transfer_type": "1", "min_transfer_time": "12", "from_route_id": "abc", "to_route_id": "abc", "from_trip_id": "abc", "to_trip_id": "abc" } MINIMAL_TRANSFER = Transfer.from_dict(MINIMAL_TRANSFER_DICT) FULL_TRANSFER = Transfer.from_dict(FULL_TRANSFER_DICT) def test_transfer_happyflow_minimal(): """ test_transfer_happyflow_minimal: minimal, correct example """ transfer = Transfer.from_gtfs(MINIMAL_TRANSFER_DICT.keys(), MINIMAL_TRANSFER_DICT.values()) assert transfer == MINIMAL_TRANSFER def test_transfer_happyflow_full(): """ test_transfer_happyflow_full: full, correct example