Skip to content

Commit

Permalink
fix(typing): Resolve test_geo_interface
Browse files Browse the repository at this point in the history
Previously wasn't defined in a way that is compatible with the protocol
`mypy` doesn't check this as nothing *was* annotated
  • Loading branch information
dangotbanned committed Nov 5, 2024
1 parent 78f50e5 commit 8ff3456
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,5 @@ ignore=[
"./tests/test_jupyter_chart.py",
"./tests/utils/",
"./tests/test_magics.py",
"./tests/vegalite/v5/test_geo_interface.py",
"../../../**/Lib", # stdlib
]
31 changes: 20 additions & 11 deletions tests/vegalite/v5/test_geo_interface.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

import pytest

import altair.vegalite.v5 as alt

if TYPE_CHECKING:
from collections.abc import MutableMapping

from altair.utils.data import SupportsGeoInterface

def geom_obj(geom):

def geom_obj(geom: dict[str, Any]) -> SupportsGeoInterface:
class Geom:
pass
__geo_interface__: MutableMapping[str, Any]

geom_obj = Geom()
geom_obj.__geo_interface__ = geom
return geom_obj


# correct translation of Polygon geometry to Feature type
def test_geo_interface_polygon_feature():
geom = {
def test_geo_interface_polygon_feature() -> None:
geom: dict[str, Any] = {
"coordinates": [[(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]],
"type": "Polygon",
}
Expand All @@ -26,7 +35,7 @@ def test_geo_interface_polygon_feature():


# merge geometry with empty properties dictionary
def test_geo_interface_removal_empty_properties():
def test_geo_interface_removal_empty_properties() -> None:
geom = {
"geometry": {
"coordinates": [
Expand All @@ -46,7 +55,7 @@ def test_geo_interface_removal_empty_properties():


# only register metadata in the properties member
def test_geo_interface_register_foreign_member():
def test_geo_interface_register_foreign_member() -> None:
geom = {
"geometry": {
"coordinates": [
Expand All @@ -68,7 +77,7 @@ def test_geo_interface_register_foreign_member():


# correct serializing of arrays and nested tuples
def test_geo_interface_serializing_arrays_tuples():
def test_geo_interface_serializing_arrays_tuples() -> None:
import array as arr

geom = {
Expand Down Expand Up @@ -96,7 +105,7 @@ def test_geo_interface_serializing_arrays_tuples():


# overwrite existing 'type' value in properties with `Feature`
def test_geo_interface_reserved_members():
def test_geo_interface_reserved_members() -> None:
geom = {
"geometry": {
"coordinates": [
Expand All @@ -116,7 +125,7 @@ def test_geo_interface_reserved_members():


# an empty FeatureCollection is valid
def test_geo_interface_empty_feature_collection():
def test_geo_interface_empty_feature_collection() -> None:
geom = {"type": "FeatureCollection", "features": []}
feat = geom_obj(geom)

Expand All @@ -126,7 +135,7 @@ def test_geo_interface_empty_feature_collection():


# Features in a FeatureCollection only keep properties and geometry
def test_geo_interface_feature_collection():
def test_geo_interface_feature_collection() -> None:
geom = {
"type": "FeatureCollection",
"features": [
Expand Down Expand Up @@ -170,7 +179,7 @@ def test_geo_interface_feature_collection():
# notic that the index value is registerd as a commonly used identifier
# with the name "id" (in this case 49). Similar to serialization of a
# pandas DataFrame is the index not included in the output
def test_geo_interface_feature_collection_gdf():
def test_geo_interface_feature_collection_gdf() -> None:
geom = {
"bbox": (19.89, -26.82, 29.43, -17.66),
"features": [
Expand Down

0 comments on commit 8ff3456

Please sign in to comment.