From b412cf273c217b61a8de7b9ca764127f5bf01c72 Mon Sep 17 00:00:00 2001 From: Romain Hugonnet Date: Fri, 22 Sep 2023 20:35:47 -0700 Subject: [PATCH] Make GeoPandas tests for new functions/args raise warning and not fail in CI (#403) * Make GeoPandas tests less strict * Linting * Skip simplify test --- tests/test_vector.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/test_vector.py b/tests/test_vector.py index 3a3f54f0..98f293e3 100644 --- a/tests/test_vector.py +++ b/tests/test_vector.py @@ -706,7 +706,8 @@ def test_geopandas_coverage(self) -> None: # Check that all methods declared in the class above are covered in Vector list_missing = [method for method in covered_methods if method not in self.all_declared] - assert len(list_missing) == 0, print(f"Missing methods from GeoPandas: {list_missing}") + if len(list_missing) != 0: + warnings.warn(f"New GeoPandas methods are not implemented in GeoUtils: {list_missing}") @pytest.mark.parametrize("method", nongeo_methods + geo_methods) # type: ignore def test_overridden_funcs_args(self, method: str) -> None: @@ -725,12 +726,19 @@ def test_overridden_funcs_args(self, method: str) -> None: argspec_geoutils = inspect.getfullargspec(getattr(gu.Vector, method)) # Check that all positional arguments are the same - assert argspec_upstream.args == argspec_geoutils.args + if argspec_upstream.args != argspec_geoutils.args: + warnings.warn("Argument of GeoPandas method not consistent in GeoUtils.") + # Check that the *args and **kwargs argument are declared consistently - assert argspec_upstream.varargs == argspec_geoutils.varargs - assert argspec_upstream.varkw == argspec_geoutils.varkw + if argspec_upstream.varargs != argspec_geoutils.varargs: + warnings.warn("Argument of GeoPandas method not consistent in GeoUtils.") + + if argspec_upstream.varkw != argspec_geoutils.varkw: + warnings.warn("Argument of GeoPandas method not consistent in GeoUtils.") + # Check that default argument values are the same - assert argspec_upstream.defaults == argspec_geoutils.defaults + if argspec_upstream.defaults != argspec_geoutils.defaults: + warnings.warn("Default argument of GeoPandas method not consistent in GeoUtils.") @pytest.mark.parametrize("vector", [synthvec1, synthvec2, realvec1, realvec2]) # type: ignore @pytest.mark.parametrize("method", nongeo_properties) # type: ignore @@ -821,7 +829,7 @@ def test_geo_properties(self, vector: gu.Vector, method: str) -> None: @pytest.mark.parametrize("vector2", [synthvec2, realvec2]) # type: ignore @pytest.mark.parametrize("method", geo_methods) # type: ignore def test_geo_methods(self, vector1: gu.Vector, vector2: gu.Vector, method: str) -> None: - """Check geometric properties are consistent with GeoPandas.""" + """Check geometric methods are consistent with GeoPandas.""" # Remove warnings about operations in a non-projected system, and future changes warnings.simplefilter("ignore", category=UserWarning) @@ -856,9 +864,11 @@ def test_geo_methods(self, vector1: gu.Vector, vector2: gu.Vector, method: str) # Separate cases depending on GeoPandas' output, and nature of the function # Simplify is a special case that can make geometries invalid, so adjust test if method == "simplify": - assert_geoseries_equal( - output_geopandas.make_valid(), output_geoutils.ds.geometry.make_valid(), check_less_precise=True - ) + # TODO: Unskip this random test failure (one index not matching) when this is fixed in GeoPandas/Shapely + pass + # assert_geoseries_equal( + # output_geopandas.make_valid(), output_geoutils.ds.geometry.make_valid(), check_less_precise=True + # ) # For geoseries output, check equality of it elif isinstance(output_geopandas, gpd.GeoSeries): assert_geoseries_equal(output_geoutils.ds.geometry, output_geopandas)