diff --git a/.coveragerc b/.coveragerc index 9c9ab43bf..64e0cd063 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,5 @@ [report] -fail_under = 95 +fail_under = 96 exclude_lines = if TYPE_CHECKING: diff --git a/tests/extensions/test_sar.py b/tests/extensions/test_sar.py index 38ae253eb..dece77975 100644 --- a/tests/extensions/test_sar.py +++ b/tests/extensions/test_sar.py @@ -203,7 +203,3 @@ def test_should_raise_exception_when_passing_invalid_extension_object( SarExtension.ext, object(), ) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/extensions/test_scientific.py b/tests/extensions/test_scientific.py index 2897f4a21..9b5b16e49 100644 --- a/tests/extensions/test_scientific.py +++ b/tests/extensions/test_scientific.py @@ -456,7 +456,3 @@ def test_set_doi_summaries(self) -> None: assert new_dois is not None self.assertListEqual([PUB2_DOI], new_dois) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/extensions/test_version.py b/tests/extensions/test_version.py index 6a48d1698..73356cc89 100644 --- a/tests/extensions/test_version.py +++ b/tests/extensions/test_version.py @@ -473,7 +473,3 @@ def test_ext_add_to(self) -> None: _ = VersionExtension.ext(collection, add_if_missing=True) self.assertIn(VersionExtension.get_schema_uri(), collection.stac_extensions) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/serialization/test_identify.py b/tests/serialization/test_identify.py index 128e8aa72..73d546f34 100644 --- a/tests/serialization/test_identify.py +++ b/tests/serialization/test_identify.py @@ -1,5 +1,4 @@ import unittest -from urllib.error import HTTPError import pystac from pystac.cache import CollectionCache @@ -24,12 +23,9 @@ def test_identify(self) -> None: path = example.path d = pystac.StacIO.default().read_json(path) if identify_stac_object_type(d) == pystac.STACObjectType.ITEM: - try: - merge_common_properties( - d, json_href=path, collection_cache=collection_cache - ) - except HTTPError: - pass + merge_common_properties( + d, json_href=path, collection_cache=collection_cache + ) actual = identify_stac_object(d) # Explicitly cover __repr__ functions in tests diff --git a/tests/test_version.py b/tests/test_version.py index 3c20ee852..4864eba2f 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,5 +1,6 @@ import os import unittest +from unittest.mock import patch import pystac from tests.utils import TestCases @@ -7,22 +8,13 @@ class VersionTest(unittest.TestCase): def setUp(self) -> None: - self._prev_env_version = os.environ.get("PYSTAC_STAC_VERSION_OVERRIDE") - self._prev_version = pystac.get_stac_version() - - def tearDown(self) -> None: - if self._prev_env_version is None: - os.environ.pop("PYSTAC_STAC_VERSION_OVERRIDE", None) - else: - os.environ["PYSTAC_STAC_VERSION_OVERRIDE"] = self._prev_env_version - pystac.set_stac_version(None) + pystac.version.STACVersion._override_version = None def test_override_stac_version_with_environ(self) -> None: - override_version = "1.0.0-gamma.2" - os.environ["PYSTAC_STAC_VERSION_OVERRIDE"] = override_version - cat = TestCases.test_case_1() - d = cat.to_dict() + with patch.dict(os.environ, {"PYSTAC_STAC_VERSION_OVERRIDE": override_version}): + cat = TestCases.test_case_1() + d = cat.to_dict() self.assertEqual(d["stac_version"], override_version) def test_override_stac_version_with_call(self) -> None: diff --git a/tests/test_writing.py b/tests/test_writing.py index 665a053b9..61c52f644 100644 --- a/tests/test_writing.py +++ b/tests/test_writing.py @@ -4,7 +4,7 @@ import pystac from pystac import Collection, CatalogType, HIERARCHICAL_LINKS -from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href +from pystac.utils import is_absolute_href, make_absolute_href from pystac.validation import validate_dict from tests.utils import TestCases @@ -35,18 +35,6 @@ def validate_file(self, path: str, object_type: str) -> List[Any]: def validate_link_types( self, root_href: str, catalog_type: pystac.CatalogType ) -> None: - def validate_asset_href_type(item: pystac.Item, item_href: str) -> None: - for asset in item.assets.values(): - if not is_absolute_href(asset.href): - is_valid = not is_absolute_href(asset.href) - if not is_valid: - # If the item href and asset href don't share - # the same root, the asset href must be absolute - rel_href = make_relative_href(asset.href, item_href) - self.assertEqual(asset.href, rel_href) - else: - self.assertTrue(is_valid) - def validate_item_link_type( href: str, link_type: str, should_include_self: bool ) -> None: @@ -63,8 +51,6 @@ def validate_item_link_type( else: self.assertTrue(is_absolute_href(link.href)) - validate_asset_href_type(item, href) - rels = set([link["rel"] for link in item_dict["links"]]) self.assertEqual("self" in rels, should_include_self) @@ -73,10 +59,7 @@ def validate_catalog_link_type( ) -> None: cat_dict = pystac.StacIO.default().read_json(href) cat = pystac.read_file(href) - if not isinstance(cat, pystac.Catalog): - raise pystac.STACTypeError( - f"File at {href} is a {cat.STAC_OBJECT_TYPE} not a Catalog." - ) + assert isinstance(cat, pystac.Catalog) rels = set([link["rel"] for link in cat_dict["links"]]) self.assertEqual("self" in rels, should_include_self) diff --git a/tests/validation/test_validate.py b/tests/validation/test_validate.py index d411bed77..de2118f75 100644 --- a/tests/validation/test_validate.py +++ b/tests/validation/test_validate.py @@ -42,35 +42,27 @@ def test_validate_examples(self) -> None: path = example.path valid = example.valid - if stac_version < "0.8": + with self.subTest(path): with open(path, encoding="utf-8") as f: stac_json = json.load(f) - self.assertEqual(len(pystac.validation.validate_dict(stac_json)), 0) - else: - with self.subTest(path): - with open(path, encoding="utf-8") as f: - stac_json = json.load(f) - - # Check if common properties need to be merged - if stac_version < "1.0": - if example.object_type == pystac.STACObjectType.ITEM: - collection_cache = CollectionCache() - merge_common_properties( - stac_json, collection_cache, path + # Check if common properties need to be merged + if stac_version < "1.0": + if example.object_type == pystac.STACObjectType.ITEM: + collection_cache = CollectionCache() + merge_common_properties(stac_json, collection_cache, path) + + if valid: + pystac.validation.validate_dict(stac_json) + else: + with self.assertRaises(pystac.STACValidationError): + try: + pystac.validation.validate_dict(stac_json) + except pystac.STACValidationError as e: + self.assertIsInstance( + e.source, jsonschema.ValidationError ) - - if valid: - pystac.validation.validate_dict(stac_json) - else: - with self.assertRaises(pystac.STACValidationError): - try: - pystac.validation.validate_dict(stac_json) - except pystac.STACValidationError as e: - self.assertIsInstance( - e.source, jsonschema.ValidationError - ) - raise e + raise e def test_validate_error_contains_href(self) -> None: # Test that the exception message contains the HREF of the object if available.