Skip to content

Commit

Permalink
feat: additional tests for new sorting features
Browse files Browse the repository at this point in the history
  • Loading branch information
CBROWN-ONS committed Feb 9, 2024
1 parent 7cb934d commit e53e09c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/transport_performance/gtfs/multi_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def _summarise_core(
sort_by = sort_by.lower().strip()
if sort_by not in ["days", "route_type"]:
raise ValueError(
"'sort_by' must be on of ['days', 'route_type']. "
"'sort_by' must be one of ['days', 'route_type']. "
f"Got {sort_by}"
)

Expand Down
28 changes: 23 additions & 5 deletions tests/gtfs/test_multi_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,24 +453,34 @@ def test_filter_to_bbox(self, multi_gtfs_fixture):
), "Gtfs inst[1] not as expected after filter"

@pytest.mark.parametrize(
"which, summ_ops, raises, match",
"which, summ_ops, sort_by, raises, match",
(
["route", True, TypeError, ".*summ_ops.*list.*bool"],
[True, [np.max], TypeError, ".*which.*str.*bool"],
["route", True, "days", TypeError, ".*summ_ops.*list.*bool"],
[True, [np.max], "days", TypeError, ".*which.*str.*bool"],
[
"not_which",
[np.max],
"days",
ValueError,
".*which.*trips.*routes.*not_which.*",
],
[
"trips",
[np.max],
"not_sort",
ValueError,
".*sort_by.*days.*route_type.*not_sort.*",
],
),
)
def test__summarise_core_defence(
self, multi_gtfs_fixture, which, summ_ops, raises, match
self, multi_gtfs_fixture, which, summ_ops, sort_by, raises, match
):
"""Defensive tests for _summarise_core()."""
with pytest.raises(raises, match=match):
multi_gtfs_fixture._summarise_core(which=which, summ_ops=summ_ops)
multi_gtfs_fixture._summarise_core(
which=which, summ_ops=summ_ops, sort_by=sort_by
)

def test__summarise_core(self, multi_gtfs_fixture):
"""General tests for _summarise_core()."""
Expand Down Expand Up @@ -532,6 +542,14 @@ def test__summarise_core(self, multi_gtfs_fixture):
assert (
dated_sum[dated_sum.date == "2024-04-06"].route_count.iloc[0] == 9
), "Unexpecteed number of routes on 2024-04-06"
# test sorting to route_type
route_sort = multi_gtfs_fixture._summarise_core(
which="routes", to_days=True, sort_by="route_type"
)
first_three_types = route_sort.route_type[:3]
assert np.array_equal(
first_three_types, [3, 3, 3]
), "Summary not sorted by route_type"

def test_summarise_trips(self, multi_gtfs_fixture):
"""General tests for summarise_trips()."""
Expand Down

0 comments on commit e53e09c

Please sign in to comment.