Example #1
0
def test_invalid_key():
    """
    test_invalid_key: test if it errors if an invalid key is passed
    """
    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_favorite_food"] = "Pizza"
    with pytest.raises(InvalidKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())
Example #2
0
def test_empty_value():
    """
    test_empty_value: test if it doesn't overwrite values with empty string
    """
    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_id"] = ""
    with pytest.raises(MissingKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())
Example #3
0
    def parse_shapes(self, shape):
        """
        parse_shapes: read shapes.txt

        Arguments:
        shape: bytes-like object containing the contents of `shapes.txt`
        """
        shape_info = [
            line.strip().split(',')
            for line in str(shape, "UTF-8").strip().split('\n')
        ]
        for line in shape_info[1:]:
            self.shapes.append(Shape.from_gtfs(shape_info[0], line))
Example #4
0
    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)
Example #5
0
def test_missing_key():
    """
    test_missing_key: check if it errors if a required key is missing
    """
    temp_dict = MINIMAL_SHAPE_DICT.copy()
    del temp_dict["shape_id"]
    with pytest.raises(MissingKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    del temp_dict["shape_pt_lat"]
    with pytest.raises(MissingKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    del temp_dict["shape_pt_lon"]
    with pytest.raises(MissingKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    del temp_dict["shape_pt_sequence"]
    with pytest.raises(MissingKeyError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_pt_lat"] = "-100"
    with pytest.raises(InvalidValueError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_pt_lon"] = "-200"
    with pytest.raises(InvalidValueError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_pt_sequence"] = "-2"
    with pytest.raises(InvalidValueError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())

    temp_dict = MINIMAL_SHAPE_DICT.copy()
    temp_dict["shape_dist_traveled"] = "-2"
    with pytest.raises(InvalidValueError):
        Shape.from_gtfs(temp_dict.keys(), temp_dict.values())
Example #6
0
def test_shape_happyflow_full():
    """
    test_shape_happyflow_full: full, correct example
    """
    shape = Shape.from_gtfs(FULL_SHAPE_DICT.keys(), FULL_SHAPE_DICT.values())
    assert shape == FULL_SHAPE
Example #7
0
def test_shape_happyflow_minimal():
    """
    test_shape_happyflow_minimal: minimal, correct example
    """
    shape = Shape.from_gtfs(MINIMAL_SHAPE_DICT.keys(), MINIMAL_SHAPE_DICT.values())
    assert shape == MINIMAL_SHAPE
Example #8
0
MINIMAL_SHAPE_DICT = {
    "shape_id": "123",
    "shape_pt_lat": "4.5",
    "shape_pt_lon": "6.7",
    "shape_pt_sequence": "8"
}

FULL_SHAPE_DICT = {
    "shape_id": "123",
    "shape_pt_lat": "7.6",
    "shape_pt_lon": "6.5",
    "shape_pt_sequence": "7",
    "shape_dist_traveled": "13.37"
}

MINIMAL_SHAPE = Shape.from_dict(MINIMAL_SHAPE_DICT)
FULL_SHAPE = Shape.from_dict(FULL_SHAPE_DICT)

def test_shape_happyflow_minimal():
    """
    test_shape_happyflow_minimal: minimal, correct example
    """
    shape = Shape.from_gtfs(MINIMAL_SHAPE_DICT.keys(), MINIMAL_SHAPE_DICT.values())
    assert shape == MINIMAL_SHAPE

def test_shape_happyflow_full():
    """
    test_shape_happyflow_full: full, correct example
    """
    shape = Shape.from_gtfs(FULL_SHAPE_DICT.keys(), FULL_SHAPE_DICT.values())
    assert shape == FULL_SHAPE