Beispiel #1
0
def test_empty_value():
    """
    test_empty_value: test if it doesn't overwrite values with empty string
    """
    temp_dict = MINIMAL_FA_DICT.copy()
    temp_dict["fare_id"] = ""
    with pytest.raises(MissingKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
Beispiel #2
0
def test_invalid_key():
    """
    test_invalid_key: test if it errors if an invalid key is passed
    """
    temp_dict = MINIMAL_FA_DICT.copy()
    temp_dict["fare_attribute_favorite_food"] = "Pizza"
    with pytest.raises(InvalidKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
Beispiel #3
0
def test_fare_attribute_happyflow_full():
    """
    test_fare_attribute_happyflow_full: full, correct example
    """
    fare_attribute = FareAttribute.from_gtfs(FULL_FA_DICT.keys(),
                                             FULL_FA_DICT.values())
    assert fare_attribute == FULL_FA
Beispiel #4
0
def test_fare_attribute_happyflow_minimal():
    """
    test_fare_attribute_happyflow_minimal: minimal, correct example
    """
    fare_attribute = FareAttribute.from_gtfs(MINIMAL_FA_DICT.keys(),
                                             MINIMAL_FA_DICT.values())
    assert fare_attribute == MINIMAL_FA
Beispiel #5
0
    def parse_fare_attributes(self, fare_attribute):
        """
        parse_fare_attributes: read fare_attributes.txt

        Arguments:
        fare_attribute: bytes-like object containing the contents of `fare_attributes.txt`
        """
        fare_attribute_info = [
            line.strip().split(',')
            for line in str(fare_attribute, "UTF-8").strip().split('\n')
        ]
        for line in fare_attribute_info[1:]:
            self.fare_attributes.append(
                FareAttribute.from_gtfs(fare_attribute_info[0], line))
Beispiel #6
0
def test_missing_key():
    """
    test_missing_key: check if it errors if a required key is missing
    """
    temp_dict = FULL_FA_DICT.copy()
    del temp_dict["fare_id"]
    with pytest.raises(MissingKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    del temp_dict["price"]
    with pytest.raises(MissingKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    del temp_dict["currency_type"]
    with pytest.raises(MissingKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    del temp_dict["payment_method"]
    with pytest.raises(MissingKeyError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
Beispiel #7
0
def test_invalid_values():
    """
    test_invalid_values: test for values out of range, invalid enums, ...
    """
    # TODO: test currency_type
    temp_dict = FULL_FA_DICT.copy()
    temp_dict["price"] = "-0.5"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    temp_dict["payment_method"] = "-1"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
    temp_dict["payment_method"] = "2"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    temp_dict["transfers"] = "-1"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
    temp_dict["transfers"] = "6"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())
    del temp_dict["transfers"]
    FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = FULL_FA_DICT.copy()
    temp_dict["transfer_duration"] = "-2"
    with pytest.raises(InvalidValueError):
        FareAttribute.from_gtfs(temp_dict.keys(), temp_dict.values())