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_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