Skip to content

Commit 7afb188

Browse files
committed
ignore test typing issues related to JSON manipulation
1 parent bcfb82a commit 7afb188

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

tests/test_schema.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
import pystac
66
import pytest
7+
from jsonschema.exceptions import ValidationError
78
from pystac.validation.stac_validator import STACValidator
89

910
from stac_model.base import JSON
1011
from stac_model.schema import SCHEMA_URI
1112

1213
from conftest import get_all_stac_item_examples
1314

15+
# ignore typing errors introduced by generic JSON manipulation errors
16+
# mypy: disable_error_code="arg-type,call-overload,index,union-attr"
17+
1418

1519
@pytest.mark.parametrize(
1620
"mlm_example", # value passed to 'mlm_example' fixture
@@ -34,15 +38,15 @@ def test_mlm_schema(
3438
)
3539
def test_mlm_no_undefined_prefixed_field_item_properties(
3640
mlm_validator: STACValidator,
37-
mlm_example: Dict[str, JSON],
41+
mlm_example: dict[str, JSON],
3842
) -> None:
3943
mlm_data = copy.deepcopy(mlm_example)
4044
mlm_item = pystac.Item.from_dict(mlm_data)
4145
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid
4246

4347
# undefined property anywhere in the schema
4448
mlm_data = copy.deepcopy(mlm_example)
45-
mlm_data["properties"]["mlm:unknown"] = "random" # type: ignore
49+
mlm_data["properties"]["mlm:unknown"] = "random"
4650
with pytest.raises(pystac.errors.STACValidationError) as exc:
4751
mlm_item = pystac.Item.from_dict(mlm_data)
4852
pystac.validation.validate(mlm_item, validator=mlm_validator)
@@ -53,12 +57,13 @@ def test_mlm_no_undefined_prefixed_field_item_properties(
5357

5458
# defined property only allowed at the Asset level
5559
mlm_data = copy.deepcopy(mlm_example)
56-
mlm_data["properties"]["mlm:artifact_type"] = "torch.save" # type: ignore
60+
mlm_data["properties"]["mlm:artifact_type"] = "torch.save"
5761
with pytest.raises(pystac.errors.STACValidationError) as exc:
5862
mlm_item = pystac.Item.from_dict(mlm_data)
5963
pystac.validation.validate(mlm_item, validator=mlm_validator)
60-
assert "mlm:artifact_type" in str(exc.value.source[0].validator_value)
61-
assert exc.value.source[0].schema["description"] == "Fields that are disallowed under the Item properties."
64+
errors = cast(list[ValidationError], exc.value.source)
65+
assert "mlm:artifact_type" in str(errors[0].validator_value)
66+
assert errors[0].schema["description"] == "Fields that are disallowed under the Item properties."
6267

6368

6469
@pytest.mark.parametrize(
@@ -85,17 +90,17 @@ def test_mlm_no_undefined_prefixed_field_asset_properties(
8590
mlm_data = copy.deepcopy(mlm_example)
8691
mlm_item = pystac.Item.from_dict(mlm_data)
8792
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid
88-
assert mlm_data["assets"]["weights"] # type: ignore
93+
assert mlm_data["assets"]["weights"]
8994

9095
mlm_data = copy.deepcopy(mlm_example)
91-
mlm_data["assets"]["weights"][test_field] = test_value # type: ignore
96+
mlm_data["assets"]["weights"][test_field] = test_value
9297
with pytest.raises(pystac.errors.STACValidationError) as exc:
9398
mlm_item = pystac.Item.from_dict(mlm_data)
9499
pystac.validation.validate(mlm_item, validator=mlm_validator)
95-
assert len(exc.value.source) == 1 # type: ignore
96-
schema_error = exc.value.source[0] # type: ignore
97-
assert test_field in schema_error.instance
98-
assert schema_error.schema["description"] in [
100+
assert len(exc.value.source) == 1
101+
errors = cast(list[ValidationError], exc.value.source)
102+
assert test_field in errors[0].instance
103+
assert errors[0].schema["description"] in [
99104
"All possible MLM fields regardless of the level they apply (Collection, Item, Asset, Link).",
100105
"Fields that are disallowed under the Asset properties."
101106
]
@@ -112,7 +117,7 @@ def test_mlm_allowed_field_asset_properties_override(
112117
) -> None:
113118
# defined property allowed both at the Item at the Asset level
114119
mlm_data = copy.deepcopy(mlm_example)
115-
mlm_data["assets"]["weights"]["mlm:accelerator"] = "cuda" # type: ignore
120+
mlm_data["assets"]["weights"]["mlm:accelerator"] = "cuda"
116121
mlm_item = pystac.Item.from_dict(mlm_data)
117122
pystac.validation.validate(mlm_item, validator=mlm_validator)
118123

@@ -130,7 +135,7 @@ def test_mlm_missing_bands_invalid_if_mlm_input_lists_bands(
130135
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid
131136

132137
mlm_bands_bad_data = copy.deepcopy(mlm_example)
133-
mlm_bands_bad_data["assets"]["weights"].pop("raster:bands") # type: ignore # no 'None' to raise in case modified
138+
mlm_bands_bad_data["assets"]["weights"].pop("raster:bands") # no 'None' to raise in case missing
134139
with pytest.raises(pystac.errors.STACValidationError):
135140
mlm_bands_bad_item = pystac.Item.from_dict(mlm_bands_bad_data)
136141
pystac.validation.validate(mlm_bands_bad_item, validator=mlm_validator)
@@ -149,7 +154,7 @@ def test_mlm_eo_bands_invalid_only_in_item_properties(
149154
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid
150155

151156
mlm_eo_bands_bad_data = copy.deepcopy(mlm_example)
152-
mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands") # type: ignore # no 'None' to raise in case modified
157+
mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands") # no 'None' to raise in case missing
153158
with pytest.raises(pystac.errors.STACValidationError):
154159
mlm_eo_bands_bad_item = pystac.Item.from_dict(mlm_eo_bands_bad_data)
155160
pystac.validation.validate(mlm_eo_bands_bad_item, validator=mlm_validator)
@@ -165,12 +170,12 @@ def test_mlm_no_input_allowed_but_explicit_empty_array_required(
165170
mlm_example: Dict[str, JSON],
166171
) -> None:
167172
mlm_data = copy.deepcopy(mlm_example)
168-
mlm_data["properties"]["mlm:input"] = [] # type: ignore
173+
mlm_data["properties"]["mlm:input"] = []
169174
mlm_item = pystac.Item.from_dict(mlm_data)
170175
pystac.validation.validate(mlm_item, validator=mlm_validator)
171176

172177
with pytest.raises(pystac.errors.STACValidationError):
173-
mlm_data["properties"].pop("mlm:input") # type: ignore # no 'None' to raise in case modified
178+
mlm_data["properties"].pop("mlm:input") # no 'None' to raise in case missing
174179
mlm_item = pystac.Item.from_dict(mlm_data)
175180
pystac.validation.validate(mlm_item, validator=mlm_validator)
176181

@@ -230,13 +235,13 @@ def test_mlm_other_non_mlm_assets_allowed(
230235
mlm_item = pystac.Item.from_dict(mlm_data)
231236
pystac.validation.validate(mlm_item, validator=mlm_validator) # self-check valid beforehand
232237

233-
mlm_data["assets"]["sample"] = { # type: ignore
238+
mlm_data["assets"]["sample"] = {
234239
"type": "image/jpeg",
235240
"href": "https://example.com/sample/output.jpg",
236241
"roles": ["preview"],
237242
"title": "Model Output Predictions Sample",
238243
}
239-
mlm_data["assets"]["model-cart"] = { # type: ignore
244+
mlm_data["assets"]["model-cart"] = {
240245
"type": "text/markdown",
241246
"href": "https://example.com/sample/model.md",
242247
"roles": ["metadata"],
@@ -285,7 +290,8 @@ def test_mlm_at_least_one_asset_model(
285290
else:
286291
with pytest.raises(pystac.errors.STACValidationError) as exc:
287292
pystac.validation.validate(mlm_item, validator=mlm_validator)
288-
assert exc.value.source[0].schema["$comment"] in [ # type: ignore
293+
errors = cast(list[ValidationError], exc.value.source)
294+
assert errors[0].schema["$comment"] in [
289295
"At least one Asset must provide the model definition indicated by the 'mlm:model' role.",
290296
"Used to check the artifact type property that is required by a Model Asset annotated by 'mlm:model' role."
291297
]

0 commit comments

Comments
 (0)