def test_raw_feed(path, shapes): feed = Feed(path, config=empty_config()) for filename, shape in shapes.items(): assert ( feed.get(filename).shape == shape ), "{}/{} dataframe shape was incorrect".format(path, filename)
def test_filtered_columns(path): service_ids_by_date = ptg.read_service_ids_by_date(path) service_ids = list(service_ids_by_date.values())[0] feed_full = Feed(path) feed_view = Feed(path, view={"trips.txt": {"service_id": service_ids}}) feed_null = Feed(path, view={"trips.txt": {"service_id": "never-match"}}) assert set(feed_full.trips.columns) == set(feed_view.trips.columns) assert set(feed_full.trips.columns) == set(feed_null.trips.columns)
def validate_feed(feed: Feed, config: nx.DiGraph) -> Bool: """ Since Partridge lazily loads the df, load each file to make sure it actually works. """ try: for node in config.nodes.keys(): feed.get(node) return True except AttributeError: return False
def test_read_file(path, dates, shapes): service_ids_by_date = ptg.read_service_ids_by_date(path) service_ids = { service_id for date in dates if date in service_ids_by_date for service_id in service_ids_by_date[date] } if service_ids: feed = Feed(path, view={"trips.txt": {"service_id": service_ids}}) else: feed = Feed(path) for filename, shape in shapes.items(): assert (feed.get(filename).shape == shape ), "{}/{} dataframe shape was incorrect".format( path, filename)
def test_bad_edge_config(): config = default_config() # Remove the `dependencies` key from an edge config config.edges["stop_times.txt", "trips.txt"].pop("dependencies") feed = Feed(fixture("caltrain-2017-07-24"), config=config) with pytest.raises(ValueError, message="Edge missing `dependencies` attribute"): feed.stop_times
def test_set(): feed = Feed(fixture("caltrain-2017-07-24")) newval = object() feed.set("newkey", newval) assert feed.get("newkey") is newval
def test_duplicate_files(): with pytest.raises(ValueError, message="More than one"): Feed(fixtures_dir)
def test_invalid_source(): with pytest.raises(ValueError, message="Invalid source"): Feed(fixture("missing"))