diff --git a/tests/gtfs/test_cleaners.py b/tests/gtfs/test_cleaners.py index 9e52185d..880f95f6 100644 --- a/tests/gtfs/test_cleaners.py +++ b/tests/gtfs/test_cleaners.py @@ -10,6 +10,7 @@ drop_trips, clean_consecutive_stop_fast_travel_warnings, clean_multiple_stop_fast_travel_warnings, + core_cleaners, ) @@ -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()