From 6f4717fb040f4d1ac61ebff9045549aede822151 Mon Sep 17 00:00:00 2001 From: Luca Di Grazia Date: Thu, 18 Aug 2022 10:34:49 +0200 Subject: [PATCH 1/3] Attribute `code` has type `str` but is used as type `None` "filename": "tests/extensions/test_grid.py" "warning_type": "Incompatible attribute type [8]" "warning_message": " Attribute `code` declared in class `GridExtension` has type `str` but is used as type `None`." "warning_line": 89 "fix": None to "" --- tests/extensions/test_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/extensions/test_grid.py b/tests/extensions/test_grid.py index e2edb9610..7a836f1d6 100644 --- a/tests/extensions/test_grid.py +++ b/tests/extensions/test_grid.py @@ -86,7 +86,7 @@ def test_clear_code(self) -> None: GridExtension.ext(self.item).apply(code) with self.assertRaises(ValueError): - GridExtension.ext(self.item).code = None + GridExtension.ext(self.item).code = "" def test_extension_not_implemented(self) -> None: # Should raise exception if Item does not include extension URI From be4a7d3bcaacac91912dc95a7f985e9b76268796 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 30 Aug 2022 12:37:26 -0600 Subject: [PATCH 2/3] fix: type checking for grid test --- tests/extensions/test_grid.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/extensions/test_grid.py b/tests/extensions/test_grid.py index 7a836f1d6..73df02f64 100644 --- a/tests/extensions/test_grid.py +++ b/tests/extensions/test_grid.py @@ -1,4 +1,6 @@ """Tests for pystac.extensions.grid.""" +# This is for the type checking on GridTest.test_clear_code +# mypy: warn_unused_ignores=False import datetime from typing import Any, Dict @@ -86,7 +88,10 @@ def test_clear_code(self) -> None: GridExtension.ext(self.item).apply(code) with self.assertRaises(ValueError): - GridExtension.ext(self.item).code = "" + # Ignore type errors because this test intentionally checks behavior + # that does not conform to the type signature. + # https://github.com/stac-utils/pystac/pull/878#discussion_r957352232 + GridExtension.ext(self.item).code = None # type: ignore def test_extension_not_implemented(self) -> None: # Should raise exception if Item does not include extension URI From 3d6729e85d1eeb8bd538637e6c7423d6ad10047f Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 30 Aug 2022 12:37:45 -0600 Subject: [PATCH 3/3] feat, tests: more grid extension negative checks --- tests/extensions/test_grid.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/extensions/test_grid.py b/tests/extensions/test_grid.py index 73df02f64..77a9defce 100644 --- a/tests/extensions/test_grid.py +++ b/tests/extensions/test_grid.py @@ -92,6 +92,18 @@ def test_clear_code(self) -> None: # that does not conform to the type signature. # https://github.com/stac-utils/pystac/pull/878#discussion_r957352232 GridExtension.ext(self.item).code = None # type: ignore + with self.assertRaises(ValueError): + # First segment has to be all caps + # https://github.com/stac-utils/pystac/pull/878#discussion_r957354927 + GridExtension.ext(self.item).code = "this-is-not-a-grid-code" + with self.assertRaises(ValueError): + # Folks might try to put an epsg code in + # https://github.com/stac-utils/pystac/pull/878#discussion_r957355415 + GridExtension.ext(self.item).code = "4326" + with self.assertRaises(ValueError): + # Folks might try to put an epsg code in + # https://github.com/stac-utils/pystac/pull/878#discussion_r957355415 + GridExtension.ext(self.item).code = "EPSG:4326" def test_extension_not_implemented(self) -> None: # Should raise exception if Item does not include extension URI