Skip to content

Commit

Permalink
Fix several more type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed May 23, 2021
1 parent db169d7 commit 424602a
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 53 deletions.
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -134,7 +136,7 @@

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
latex_elements: Dict[str, Any] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
4 changes: 2 additions & 2 deletions pystac/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/extensions/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/extensions/test_pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,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
Expand Down
20 changes: 10 additions & 10 deletions tests/extensions/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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]}
Expand Down
44 changes: 30 additions & 14 deletions tests/extensions/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,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
Expand Down Expand Up @@ -330,17 +338,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
Expand Down
5 changes: 5 additions & 0 deletions tests/extensions/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/serialization/test_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 424602a

Please sign in to comment.