Skip to content

Commit

Permalink
Add tests for core_cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
CBROWN-ONS committed Oct 19, 2023
1 parent ad38cac commit 3cb7443
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/gtfs/test_cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
drop_trips,
clean_consecutive_stop_fast_travel_warnings,
clean_multiple_stop_fast_travel_warnings,
core_cleaners,
)


Expand Down Expand Up @@ -275,3 +276,88 @@ def test_clean_multiple_stop_fast_travel_warnings_on_pass(
clean_multiple_stop_fast_travel_warnings(
gtfs=gtfs_fixture, validate=True
)


class TestCoreCleaner(object):
"""Tests for core_cleaners().
Notes
-----
There are no passing tests for this function as it relies on function from
gtfs-kit which have already been tested.
"""

@pytest.mark.parametrize(
(
"clean_ids, clean_times, clean_route_short_names, drop_zombies, "
"raises, match"
),
[
(
1,
True,
True,
True,
TypeError,
r".*expected .*bool.* Got .*int.*",
),
(
True,
dict(),
True,
True,
TypeError,
r".*expected .*bool.* Got .*dict.*",
),
(
True,
True,
"test string",
True,
TypeError,
r".*expected .*bool.* Got .*str.*",
),
(
True,
True,
True,
2.12,
TypeError,
r".*expected .*bool.* Got .*float.*",
),
],
)
def test_core_claners_defence(
self,
gtfs_fixture,
clean_ids,
clean_times,
clean_route_short_names,
drop_zombies,
raises,
match,
):
"""Defensive tests for core_cleaners."""
with pytest.raises(raises, match=match):
gtfs_fixture.is_valid()
core_cleaners(
gtfs_fixture,
clean_ids,
clean_times,
clean_route_short_names,
drop_zombies,
)

def test_core_cleaners_drop_zombies_warns(self, gtfs_fixture):
"""Test that warnings are emitted when shape_id isn't present in...
trips.
"""
gtfs_fixture.feed.trips.drop("shape_id", axis=1, inplace=True)
with pytest.warns(
UserWarning,
match=r".*drop_zombies cleaner was unable to operate.*",
):
gtfs_fixture.is_valid(validators={"core_validation": None})
gtfs_fixture.clean_feed()

0 comments on commit 3cb7443

Please sign in to comment.