def test_invalid_timezone(): """ test_invalid_timezone: check if it raises InvalidValueError when given an invalid timezone """ temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["stop_timezone"] = "MiddleEarth/Shire" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values())
def test_empty_value(): """ test_empty_value: test if it doesn't overwrite values with empty string """ temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["stop_id"] = "" with pytest.raises(MissingKeyError): Stop.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_STOP_DICT.copy() temp_dict["stop_favorite_food"] = "Pizza" with pytest.raises(InvalidKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values())
def parse_stops(self, stops): """ parse_stops: read stops.txt Arguments: stops: bytes-like object containing the contents of `stops.txt` """ stop_info = [ line.strip().split(',') for line in str(stops, "UTF-8").strip().split('\n') ] for line in stop_info[1:]: self.stops.append(Stop.from_gtfs(stop_info[0], line))
def test_equal(): """ test_equal: check if __eq__ functions """ assert MINIMAL_STOP == MINIMAL_STOP assert MINIMAL_STOP != FULL_STOP assert FULL_STOP != MINIMAL_STOP assert FULL_STOP == FULL_STOP assert MINIMAL_STOP != "MINIMAL_STOP" temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["platform_code"] = 2 temp_stop = Stop.from_dict(temp_dict) assert temp_stop != MINIMAL_STOP
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_STOP_DICT.copy() temp_dict["stop_lat"] = "-100" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["stop_lon"] = "-200" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["location_type"] = "-1" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["location_type"] = "5" temp_dict["parent_station"] = "456" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["wheelchair_boarding"] = "-1" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict["wheelchair_boarding"] = "3" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["vehicle_type"] = "-1" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict["vehicle_type"] = "8" with pytest.raises(InvalidValueError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict["vehicle_type"] = "700" Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict["vehicle_type"] = "1701" with pytest.raises(InvalidValueError): Stop.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_STOP_DICT.copy() del temp_dict["stop_id"] with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() del temp_dict["stop_name"] with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() del temp_dict["stop_lat"] with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() del temp_dict["stop_lon"] with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["location_type"] = 2 with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values()) temp_dict = MINIMAL_STOP_DICT.copy() temp_dict["location_type"] = 1 temp_dict["parent_station"] = 123 with pytest.raises(MissingKeyError): Stop.from_gtfs(temp_dict.keys(), temp_dict.values())
def test_stop_happyflow_full(): """ test_stop_happyflow_full: full, correct example """ stop = Stop.from_gtfs(FULL_STOP_DICT.keys(), FULL_STOP_DICT.values()) assert stop == FULL_STOP
def test_stop_happyflow_minimal(): """ test_stop_happyflow_minimal: minimal, correct example """ stop = Stop.from_gtfs(MINIMAL_STOP_DICT.keys(), MINIMAL_STOP_DICT.values()) assert stop == MINIMAL_STOP
"stop_name": "Period", "stop_lat": "1.234", "stop_lon": "5.678", "stop_code": ".", "stop_desc": "A nice stop for taking a break", "stop_url": "https://period.com/", "location_type": "0", "stop_timezone": "Europe/Brussels", "wheelchair_boarding": "1", "platform_code": ".1", "zone_id": "123", "parent_station": "123", "level_id": "123" } MINIMAL_STOP = Stop.from_dict(MINIMAL_STOP_DICT) FULL_STOP = Stop.from_dict(FULL_STOP_DICT) def test_stop_happyflow_minimal(): """ test_stop_happyflow_minimal: minimal, correct example """ stop = Stop.from_gtfs(MINIMAL_STOP_DICT.keys(), MINIMAL_STOP_DICT.values()) assert stop == MINIMAL_STOP def test_stop_happyflow_full(): """ test_stop_happyflow_full: full, correct example """