コード例 #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())
コード例 #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())
コード例 #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
コード例 #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
コード例 #5
0
ファイル: gtfs.py プロジェクト: Robbe7730/realtime-gtfs
    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))
コード例 #6
0
def test_equal():
    """
    test_equal: check if __eq__ functions
    """
    assert MINIMAL_FA == MINIMAL_FA
    assert MINIMAL_FA != FULL_FA
    assert FULL_FA != MINIMAL_FA
    assert FULL_FA == FULL_FA
    assert MINIMAL_FA != "MINIMAL_FA"

    temp_dict = MINIMAL_FA_DICT.copy()
    temp_dict["fare_id"] = 2
    temp_fare_attribute = FareAttribute.from_dict(temp_dict)

    assert temp_fare_attribute != MINIMAL_FA
コード例 #7
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())
コード例 #8
0
ファイル: database.py プロジェクト: Robbe7730/realtime-gtfs
    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)
コード例 #9
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())
コード例 #10
0
    "currency_type": "EUR",
    "payment_method": "1",
    "transfers": "4"
}

FULL_FA_DICT = {
    "fare_id": "132",
    "price": "0.51",
    "currency_type": "USD",
    "payment_method": "0",
    "transfers": "0",
    "agency_id": "123",
    "transfer_duration": "3600"
}

MINIMAL_FA = FareAttribute.from_dict(MINIMAL_FA_DICT)
FULL_FA = FareAttribute.from_dict(FULL_FA_DICT)


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


def test_fare_attribute_happyflow_full():
    """
    test_fare_attribute_happyflow_full: full, correct example