From 01c924a9de5dbef23ca82e6c9516b01351a6d752 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Mon, 24 May 2021 10:07:26 +1200 Subject: [PATCH] Fix several more type annotations --- docs/conf.py | 4 ++- pystac/extensions/base.py | 4 +-- setup.py | 2 +- tests/extensions/test_custom.py | 2 +- tests/extensions/test_pointcloud.py | 6 ++-- tests/extensions/test_projection.py | 20 ++++++------ tests/extensions/test_scientific.py | 4 ++- tests/extensions/test_version.py | 48 +++++++++++++++++++--------- tests/extensions/test_view.py | 5 +++ tests/serialization/test_identify.py | 2 +- tests/test_cache.py | 2 +- tests/test_catalog.py | 47 ++++++++++++++++++++------- tests/test_collection.py | 2 ++ tests/test_item.py | 2 +- tests/test_layout.py | 2 ++ tests/test_link.py | 9 ++++-- tests/test_stac_io.py | 2 +- tests/test_version.py | 2 +- tests/test_writing.py | 2 +- tests/validation/test_validate.py | 1 + 20 files changed, 113 insertions(+), 55 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 13b847d75..39a01df9e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,8 @@ import os import sys import subprocess +from typing import Any, Dict + sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('../')) from pystac.version import __version__ @@ -134,7 +136,7 @@ # -- Options for LaTeX output ------------------------------------------------ -latex_elements = { +latex_elements: Dict[str, Any] = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', diff --git a/pystac/extensions/base.py b/pystac/extensions/base.py index 904b0c97f..6ed1d4a55 100644 --- a/pystac/extensions/base.py +++ b/pystac/extensions/base.py @@ -28,8 +28,8 @@ class PropertiesExtension(ABC): properties: Dict[str, Any] additional_read_properties: Optional[Iterable[Dict[str, Any]]] = None - def _get_property(self, prop_name: str, typ: Type[P] = Type[Any]) -> Optional[P]: - result: Optional[typ] = self.properties.get(prop_name) + def _get_property(self, prop_name: str, typ: Type[P]) -> Optional[P]: + result = self.properties.get(prop_name) if result is not None: return result if self.additional_read_properties is not None: diff --git a/setup.py b/setup.py index 6851f848a..7993d8eb1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages from glob import glob -__version__ = load_source('pystac.version', 'pystac/version.py').__version__ +__version__ = load_source('pystac.version', 'pystac/version.py').__version__ # type: ignore from os.path import ( basename, diff --git a/tests/extensions/test_custom.py b/tests/extensions/test_custom.py index 79ea97bde..76fc5444f 100644 --- a/tests/extensions/test_custom.py +++ b/tests/extensions/test_custom.py @@ -34,7 +34,7 @@ def apply(self, test_prop: Optional[str]) -> None: @property def test_prop(self) -> Optional[str]: - self._get_property(TEST_PROP, str) + return self._get_property(TEST_PROP, str) @test_prop.setter def test_prop(self, v: Optional[str]) -> None: diff --git a/tests/extensions/test_pointcloud.py b/tests/extensions/test_pointcloud.py index 344ce174c..e88c0948e 100644 --- a/tests/extensions/test_pointcloud.py +++ b/tests/extensions/test_pointcloud.py @@ -122,9 +122,9 @@ def test_statistics(self) -> None: # Get self.assertIn("pc:statistics", pc_item.properties) - pc_statistics = [ - s.to_dict() for s in PointcloudExtension.ext(pc_item).statistics - ] + statistics = PointcloudExtension.ext(pc_item).statistics + assert statistics is not None + pc_statistics = [s.to_dict() for s in statistics] self.assertEqual(pc_statistics, pc_item.properties["pc:statistics"]) # Set diff --git a/tests/extensions/test_projection.py b/tests/extensions/test_projection.py index 61f477e1d..20ad81d7a 100644 --- a/tests/extensions/test_projection.py +++ b/tests/extensions/test_projection.py @@ -119,6 +119,7 @@ def test_epsg(self) -> None: self.assertEqual(proj_epsg, proj_item.properties["proj:epsg"]) # Set + assert proj_epsg is not None ProjectionExtension.ext(proj_item).epsg = proj_epsg + 100 self.assertEqual(proj_epsg + 100, proj_item.properties["proj:epsg"]) @@ -196,9 +197,9 @@ def test_projjson(self) -> None: ProjectionExtension.ext(asset_no_prop).projjson, ProjectionExtension.ext(proj_item).projjson, ) - self.assertEqual( - ProjectionExtension.ext(asset_prop).projjson["id"]["code"], 9999 - ) + asset_prop_json = ProjectionExtension.ext(asset_prop).projjson + assert asset_prop_json is not None + self.assertEqual(asset_prop_json["id"]["code"], 9999) # Set to Asset asset_value = deepcopy(PROJJSON) @@ -208,9 +209,9 @@ def test_projjson(self) -> None: ProjectionExtension.ext(asset_no_prop).projjson, ProjectionExtension.ext(proj_item).projjson, ) - self.assertEqual( - ProjectionExtension.ext(asset_no_prop).projjson["id"]["code"], 7777 - ) + asset_no_prop_json = ProjectionExtension.ext(asset_no_prop).projjson + assert asset_no_prop_json is not None + self.assertEqual(asset_no_prop_json["id"]["code"], 7777) # Validate proj_item.validate() @@ -239,10 +240,9 @@ def test_geometry(self) -> None: ProjectionExtension.ext(asset_no_prop).geometry, ProjectionExtension.ext(proj_item).geometry, ) - self.assertEqual( - ProjectionExtension.ext(asset_prop).geometry["coordinates"][0][0], - [0.0, 0.0], - ) + asset_prop_geometry = ProjectionExtension.ext(asset_prop).geometry + assert asset_prop_geometry is not None + self.assertEqual(asset_prop_geometry["coordinates"][0][0], [0.0, 0.0]) # Set to Asset asset_value: Dict[str, Any] = {"type": "Point", "coordinates": [1.0, 2.0]} diff --git a/tests/extensions/test_scientific.py b/tests/extensions/test_scientific.py index 9682f3a72..eb1052351 100644 --- a/tests/extensions/test_scientific.py +++ b/tests/extensions/test_scientific.py @@ -2,6 +2,7 @@ import datetime import unittest +from typing import List, Optional import pystac from pystac.extensions import scientific @@ -183,7 +184,8 @@ def make_collection() -> pystac.Collection: end = start + datetime.timedelta(5, 4, 3, 2, 1) bboxes = [[-180.0, -90.0, 180.0, 90.0]] spatial_extent = pystac.SpatialExtent(bboxes) - temporal_extent = pystac.TemporalExtent([[start, end]]) + intervals: List[List[Optional[datetime.datetime]]] = [[start, end]] + temporal_extent = pystac.TemporalExtent(intervals) extent = pystac.Extent(spatial_extent, temporal_extent) collection = pystac.Collection(asset_id, "desc", extent) collection.set_self_href(URL_TEMPLATE % 2019) diff --git a/tests/extensions/test_version.py b/tests/extensions/test_version.py index 8a5a30684..d61e31dda 100644 --- a/tests/extensions/test_version.py +++ b/tests/extensions/test_version.py @@ -2,6 +2,7 @@ import datetime import unittest +from typing import List, Optional import pystac from pystac.extensions import version @@ -134,17 +135,25 @@ def test_full_copy(self) -> None: # Retrieve the copied version of the items item1_copy = cat_copy.get_item("area-1-1-imagery", recursive=True) + assert item1_copy is not None item2_copy = cat_copy.get_item("area-2-2-imagery", recursive=True) + assert item2_copy is not None # Check to see if the version links point to the instances of the # item objects as they should. - predecessor = item1_copy.get_single_link(version.PREDECESSOR).target - successor = item2_copy.get_single_link(version.SUCCESSOR).target - latest = item2_copy.get_single_link(version.LATEST).target - - self.assertIs(predecessor, item2_copy) - self.assertIs(successor, item1_copy) - self.assertIs(latest, item1_copy) + predecessor = item1_copy.get_single_link(version.PREDECESSOR) + assert predecessor is not None + predecessor_target = predecessor.target + successor = item2_copy.get_single_link(version.SUCCESSOR) + assert successor is not None + successor_target = successor.target + latest = item2_copy.get_single_link(version.LATEST) + assert latest is not None + latest_target = latest.target + + self.assertIs(predecessor_target, item2_copy) + self.assertIs(successor_target, item1_copy) + self.assertIs(latest_target, item1_copy) def test_setting_none_clears_link(self) -> None: deprecated = False @@ -210,7 +219,8 @@ def make_collection(year: int) -> pystac.Collection: end = datetime.datetime(year, 1, 3, 4, 5) bboxes = [[-180.0, -90.0, 180.0, 90.0]] spatial_extent = pystac.SpatialExtent(bboxes) - temporal_extent = pystac.TemporalExtent([[start, end]]) + intervals: List[List[Optional[datetime.datetime]]] = [[start, end]] + temporal_extent = pystac.TemporalExtent(intervals) extent = pystac.Extent(spatial_extent, temporal_extent) collection = pystac.Collection(asset_id, "desc", extent) @@ -330,17 +340,25 @@ def test_full_copy(self) -> None: # Retrieve the copied version of the items col1_copy = cat_copy.get_child("area-1-1", recursive=True) + assert col1_copy is not None col2_copy = cat_copy.get_child("area-2-2", recursive=True) + assert col2_copy is not None # Check to see if the version links point to the instances of the # col objects as they should. - predecessor = col1_copy.get_single_link(version.PREDECESSOR).target - successor = col2_copy.get_single_link(version.SUCCESSOR).target - latest = col2_copy.get_single_link(version.LATEST).target - - self.assertIs(predecessor, col2_copy) - self.assertIs(successor, col1_copy) - self.assertIs(latest, col1_copy) + predecessor = col1_copy.get_single_link(version.PREDECESSOR) + assert predecessor is not None + predecessor_target = predecessor.target + successor = col2_copy.get_single_link(version.SUCCESSOR) + assert successor is not None + successor_target = successor.target + latest = col2_copy.get_single_link(version.LATEST) + assert latest is not None + latest_target = latest.target + + self.assertIs(predecessor_target, col2_copy) + self.assertIs(successor_target, col1_copy) + self.assertIs(latest_target, col1_copy) def test_setting_none_clears_link(self) -> None: deprecated = False diff --git a/tests/extensions/test_view.py b/tests/extensions/test_view.py index 294144fee..a4956bb60 100644 --- a/tests/extensions/test_view.py +++ b/tests/extensions/test_view.py @@ -46,6 +46,7 @@ def test_off_nadir(self) -> None: # Get self.assertIn("view:off_nadir", view_item.properties) view_off_nadir = ViewExtension.ext(view_item).off_nadir + assert view_off_nadir is not None self.assertEqual(view_off_nadir, view_item.properties["view:off_nadir"]) # Set @@ -79,6 +80,7 @@ def test_incidence_angle(self) -> None: # Get self.assertIn("view:incidence_angle", view_item.properties) view_incidence_angle = ViewExtension.ext(view_item).incidence_angle + assert view_incidence_angle is not None self.assertEqual( view_incidence_angle, view_item.properties["view:incidence_angle"] ) @@ -116,6 +118,7 @@ def test_azimuth(self) -> None: # Get self.assertIn("view:azimuth", view_item.properties) view_azimuth = ViewExtension.ext(view_item).azimuth + assert view_azimuth is not None self.assertEqual(view_azimuth, view_item.properties["view:azimuth"]) # Set @@ -149,6 +152,7 @@ def test_sun_azimuth(self) -> None: # Get self.assertIn("view:sun_azimuth", view_item.properties) view_sun_azimuth = ViewExtension.ext(view_item).sun_azimuth + assert view_sun_azimuth is not None self.assertEqual(view_sun_azimuth, view_item.properties["view:sun_azimuth"]) # Set @@ -184,6 +188,7 @@ def test_sun_elevation(self) -> None: # Get self.assertIn("view:sun_elevation", view_item.properties) view_sun_elevation = ViewExtension.ext(view_item).sun_elevation + assert view_sun_elevation is not None self.assertEqual(view_sun_elevation, view_item.properties["view:sun_elevation"]) # Set diff --git a/tests/serialization/test_identify.py b/tests/serialization/test_identify.py index 36a2c6eca..829f16cc7 100644 --- a/tests/serialization/test_identify.py +++ b/tests/serialization/test_identify.py @@ -59,7 +59,7 @@ def test_version_ordering(self) -> None: self.assertFalse(STACVersionID("0.9.0") > "0.9.0") # type:ignore self.assertTrue(STACVersionID("0.9.0") <= "0.9.0") # type:ignore self.assertTrue( - STACVersionID("1.0.0-beta.1") + STACVersionID("1.0.0-beta.1") # type:ignore <= STACVersionID("1.0.0-beta.2") # type:ignore ) self.assertFalse(STACVersionID("1.0.0") < STACVersionID("1.0.0-beta.2")) diff --git a/tests/test_cache.py b/tests/test_cache.py index fecda42ab..70e0bc886 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -20,7 +20,7 @@ def create_catalog(suffix: Any, include_href: bool = True) -> pystac.Catalog: class ResolvedObjectCacheTest(unittest.TestCase): - def tests_get_or_cache_returns_previously_cached_href(self): + def tests_get_or_cache_returns_previously_cached_href(self) -> None: cache = ResolvedObjectCache() cat = create_catalog(1) cache_result_1 = cache.get_or_cache(cat) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 35ee1e2dc..e38fd15e9 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -90,6 +90,7 @@ def test_read_remote(self) -> None: cat = Catalog.from_file(catalog_url) zanzibar = cat.get_child("zanzibar-collection") + assert zanzibar is not None self.assertEqual(len(list(zanzibar.get_items())), 2) @@ -212,7 +213,7 @@ def test_sets_catalog_type(self) -> None: self.assertEqual(cat.catalog_type, CatalogType.SELF_CONTAINED) def test_walk_iterates_correctly(self) -> None: - def test_catalog(cat: Catalog): + def test_catalog(cat: Catalog) -> None: expected_catalog_iterations = 1 actual_catalog_iterations = 0 with self.subTest(title="Testing catalog {}".format(cat.id)): @@ -300,7 +301,9 @@ def test_normalize_hrefs_sets_all_hrefs(self) -> None: catalog = TestCases.test_case_1() catalog.normalize_hrefs("http://example.com") for root, _, items in catalog.walk(): - self.assertTrue(root.get_self_href().startswith("http://example.com")) + self_href = root.get_self_href() + assert self_href is not None + self.assertTrue(self_href.startswith("http://example.com")) for link in root.links: if link.is_resolved(): target_href = cast(pystac.STACObject, link.target).self_href @@ -319,7 +322,9 @@ def test_normalize_hrefs_makes_absolute_href(self) -> None: catalog = TestCases.test_case_1() catalog.normalize_hrefs("./relativepath") abspath = os.path.abspath("./relativepath") - self.assertTrue(catalog.get_self_href().startswith(abspath)) + self_href = catalog.get_self_href() + assert self_href is not None + self.assertTrue(self_href.startswith(abspath)) def test_normalize_href_works_with_label_source_links(self) -> None: catalog = TestCases.test_case_1() @@ -341,6 +346,7 @@ def test_generate_subcatalogs_works_with_custom_properties(self) -> None: ) month_cat = catalog.get_child("8", recursive=True) + assert month_cat is not None type_cats = set([cat.id for cat in month_cat.get_children()]) self.assertEqual(type_cats, set(["PSScene4Band", "SkySatScene", "PlanetScope"])) @@ -410,8 +416,14 @@ def test_generate_subcatalogs_works_after_adding_more_items(self) -> None: catalog.generate_subcatalogs("${property1}/${property2}") catalog.normalize_hrefs("/tmp") - item1_parent = catalog.get_item("item1", recursive=True).get_parent() - item2_parent = catalog.get_item("item2", recursive=True).get_parent() + item1 = catalog.get_item("item1", recursive=True) + assert item1 is not None + item1_parent = item1.get_parent() + assert item1_parent is not None + item2 = catalog.get_item("item2", recursive=True) + assert item2 is not None + item2_parent = item2.get_parent() + assert item2_parent is not None self.assertEqual(item1_parent.get_self_href(), item2_parent.get_self_href()) def test_generate_subcatalogs_works_for_branched_subcatalogs(self) -> None: @@ -462,7 +474,9 @@ def test_generate_subcatalogs_works_for_subcatalogs_with_same_ids(self) -> None: catalog.normalize_hrefs("/") for item in catalog.get_all_items(): - parent_href = item.get_parent().self_href + item_parent = item.get_parent() + assert item_parent is not None + parent_href = item_parent.self_href path_to_parent, _ = os.path.split(parent_href) subcats = [el for el in path_to_parent.split("/") if el] self.assertEqual(len(subcats), 2, msg=" for item '{}'".format(item.id)) @@ -707,6 +721,7 @@ def test_make_all_asset_hrefs_absolute(self) -> None: cat = TestCases.test_case_2() cat.make_all_asset_hrefs_absolute() item = cat.get_item("cf73ec1a-d790-4b59-b077-e101738571ed", recursive=True) + assert item is not None href = item.assets["cf73ec1a-d790-4b59-b077-e101738571ed"].href self.assertTrue(is_absolute_href(href)) @@ -714,6 +729,7 @@ def test_make_all_asset_hrefs_absolute(self) -> None: def test_make_all_asset_hrefs_relative(self) -> None: cat = TestCases.test_case_2() item = cat.get_item("cf73ec1a-d790-4b59-b077-e101738571ed", recursive=True) + assert item is not None asset = item.assets["cf73ec1a-d790-4b59-b077-e101738571ed"] original_href = asset.href cat.make_all_asset_hrefs_absolute() @@ -726,7 +742,7 @@ def test_make_all_asset_hrefs_relative(self) -> None: self.assertEqual(asset.href, original_href) def test_make_all_links_relative_or_absolute(self) -> None: - def check_all_relative(cat: Catalog): + def check_all_relative(cat: Catalog) -> None: for root, catalogs, items in cat.walk(): for link in root.links: if link.rel in HIERARCHICAL_LINKS: @@ -736,7 +752,7 @@ def check_all_relative(cat: Catalog): if link.rel in HIERARCHICAL_LINKS: self.assertFalse(is_absolute_href(link.href)) - def check_all_absolute(cat: Catalog): + def check_all_absolute(cat: Catalog) -> None: for root, catalogs, items in cat.walk(): for link in root.links: self.assertTrue(is_absolute_href(link.href)) @@ -796,6 +812,7 @@ def test_validate_all(self) -> None: # Make one invalid, write it off, read it in, ensure it throws cat = TestCases.test_case_1() item = cat.get_item("area-1-1-labels", recursive=True) + assert item is not None item.geometry = {"type": "INVALID", "coordinates": "NONE"} with TemporaryDirectory() as tmp_dir: cat.normalize_hrefs(tmp_dir) @@ -813,6 +830,7 @@ def test_set_hrefs_manually(self) -> None: year = 2004 month = 2 for item in catalog.get_all_items(): + assert item.datetime is not None item.datetime = item.datetime.replace(year=year, month=month) year += 1 month += 1 @@ -832,6 +850,7 @@ def test_set_hrefs_manually(self) -> None: # Set each item's HREF based on it's datetime for item in items: + assert item.datetime is not None item_href = "{}/{}-{}/{}.json".format( root_dir, item.datetime.year, item.datetime.month, item.id ) @@ -854,10 +873,13 @@ def test_set_hrefs_manually(self) -> None: os.path.join(d, root.id, root.DEFAULT_FILE_NAME), ) for item in items: + assert item.datetime is not None end = "{}-{}/{}.json".format( item.datetime.year, item.datetime.month, item.id ) - self.assertTrue(item.get_self_href().endswith(end)) + self_href = item.get_self_href() + assert self_href is not None + self.assertTrue(self_href.endswith(end)) def test_collections_cache_correctly(self) -> None: catalogs = TestCases.all_test_catalogs() @@ -941,7 +963,7 @@ def test_catalog_with_href_caches_by_href(self) -> None: class FullCopyTest(unittest.TestCase): - def check_link(self, link: pystac.Link, tag: str): + def check_link(self, link: pystac.Link, tag: str) -> None: if link.is_resolved(): target_href: str = cast(pystac.STACObject, link.target).self_href else: @@ -951,11 +973,11 @@ def check_link(self, link: pystac.Link, tag: str): '[{}] {} does not contain "{}"'.format(link.rel, target_href, tag), ) - def check_item(self, item: Item, tag: str): + def check_item(self, item: Item, tag: str) -> None: for link in item.links: self.check_link(link, tag) - def check_catalog(self, c: Catalog, tag: str): + def check_catalog(self, c: Catalog, tag: str) -> None: self.assertEqual(len(c.get_links("root")), 1) for link in c.links: @@ -1065,6 +1087,7 @@ def test_full_copy_4(self) -> None: # Check that the relative asset link was saved correctly in the copy. item = cat2.get_item("cf73ec1a-d790-4b59-b077-e101738571ed", recursive=True) + assert item is not None href = item.assets[ "cf73ec1a-d790-4b59-b077-e101738571ed" diff --git a/tests/test_collection.py b/tests/test_collection.py index 7bf301563..cb341f7a0 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -54,6 +54,7 @@ def test_multiple_extents(self) -> None: country = cat1.get_child("country-1") assert country is not None col1 = country.get_child("area-1-1") + assert col1 is not None col1.validate() self.assertIsInstance(col1, Collection) validate_dict(col1.to_dict(), pystac.STACObjectType.COLLECTION) @@ -79,6 +80,7 @@ def test_multiple_extents(self) -> None: def test_extra_fields(self) -> None: catalog = TestCases.test_case_2() collection = catalog.get_child("1a8c1632-fa91-4a62-b33e-3a87c2ebdf16") + assert collection is not None collection.extra_fields["test"] = "extra" diff --git a/tests/test_item.py b/tests/test_item.py index 20b3bab1f..3215feeba 100644 --- a/tests/test_item.py +++ b/tests/test_item.py @@ -15,7 +15,7 @@ class ItemTest(unittest.TestCase): - def get_example_item_dict(self): + def get_example_item_dict(self) -> Dict[str, Any]: m = TestCases.get_path("data-files/item/sample-item.json") with open(m) as f: item_dict = json.load(f) diff --git a/tests/test_layout.py b/tests/test_layout.py index 488479569..5158fb580 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -81,6 +81,7 @@ def test_templates_item_collection(self) -> None: template = LayoutTemplate("${collection}/item.json") collection = TestCases.test_case_4().get_child("acc") + assert collection is not None item = next(iter(collection.get_all_items())) assert item.collection_id is not None @@ -96,6 +97,7 @@ def test_throws_for_no_collection(self) -> None: template = LayoutTemplate("${collection}/item.json") collection = TestCases.test_case_4().get_child("acc") + assert collection is not None item = next(iter(collection.get_all_items())) item.set_collection(None) assert item.collection_id is None diff --git a/tests/test_link.py b/tests/test_link.py index 137546264..088f9896e 100644 --- a/tests/test_link.py +++ b/tests/test_link.py @@ -1,5 +1,6 @@ import datetime import unittest +from typing import Any, Dict, List import pystac from tests.utils.test_cases import ARBITRARY_EXTENT @@ -74,6 +75,7 @@ def test_link_does_not_fail_if_href_is_none(self) -> None: catalog.set_self_href("/some/href") link = catalog.get_single_link("item") + assert link is not None self.assertIsNone(link.get_href()) def test_resolve_stac_object_no_root_and_target_is_item(self) -> None: @@ -83,11 +85,11 @@ def test_resolve_stac_object_no_root_and_target_is_item(self) -> None: class StaticLinkTest(unittest.TestCase): def test_from_dict_round_trip(self) -> None: - test_cases = [ + test_cases: List[Dict[str, Any]] = [ {"rel": "", "href": ""}, # Not valid, but works. {"rel": "r", "href": "t"}, {"rel": "r", "href": "/t"}, - {"rel": "r", "href": "t", "type": "a/b", "title": "t", "c": "d", 1: 2}, + {"rel": "r", "href": "t", "type": "a/b", "title": "t", "c": "d", "1": 2}, # Special case. {"rel": "self", "href": "t"}, ] @@ -96,7 +98,8 @@ def test_from_dict_round_trip(self) -> None: self.assertEqual(d, d2) def test_from_dict_failures(self) -> None: - for d in [{}, {"href": "t"}, {"rel": "r"}]: + dicts: List[Dict[str, Any]] = [{}, {"href": "t"}, {"rel": "r"}] + for d in dicts: with self.assertRaises(KeyError): pystac.Link.from_dict(d) diff --git a/tests/test_stac_io.py b/tests/test_stac_io.py index 0f91e480a..58ac51e23 100644 --- a/tests/test_stac_io.py +++ b/tests/test_stac_io.py @@ -20,7 +20,7 @@ def test_stac_io_issues_warnings(self) -> None: self.assertEqual(len(w), 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) - def test_read_text(self): + def test_read_text(self) -> None: _ = pystac.read_file( TestCases.get_path("data-files/collections/multi-extent.json") ) diff --git a/tests/test_version.py b/tests/test_version.py index 410a85c10..3c20ee852 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -10,7 +10,7 @@ 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): + def tearDown(self) -> None: if self._prev_env_version is None: os.environ.pop("PYSTAC_STAC_VERSION_OVERRIDE", None) else: diff --git a/tests/test_writing.py b/tests/test_writing.py index d43a220bc..4bbe2e3b8 100644 --- a/tests/test_writing.py +++ b/tests/test_writing.py @@ -35,7 +35,7 @@ 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): + 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) diff --git a/tests/validation/test_validate.py b/tests/validation/test_validate.py index 737446cd6..6c2dae259 100644 --- a/tests/validation/test_validate.py +++ b/tests/validation/test_validate.py @@ -76,6 +76,7 @@ def test_validate_error_contains_href(self) -> None: # Test that the exception message contains the HREF of the object if available. cat = TestCases.test_case_1() item = cat.get_item("area-1-1-labels", recursive=True) + assert item is not None assert item.get_self_href() is not None item.geometry = {"type": "INVALID"}