Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Apr 25, 2024
1 parent 98b8da0 commit 4c52f6d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ format: codestyle
test:
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/

.PHONY: check
check: check-examples check-markdown check-lint check-mypy check-safety

.PHONY: check-all
check-all: check

.PHONY: mypy
mypy:
poetry run mypy --config-file pyproject.toml ./

.PHONY: check-mypy
check-mypy: mypy

.PHONY: check-safety
check-safety:
poetry check
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ select = [
"I",
]

[tool.ruff.lint.isort]
known-local-folder = ["tests", "conftest"]
known-first-party = ["stac_model"]

[tool.mypy]
# https://github.com/python/mypy
# https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file
Expand Down
2 changes: 1 addition & 1 deletion stac_model/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Literal, TypeAlias, TypedDict, Union
from typing import Any, Dict, List, Literal, TypeAlias, Union

from pydantic import BaseModel, ConfigDict, model_serializer

Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def mlm_validator(


@pytest.fixture
def mlm_example(request: "SubRequest") -> JSON:
def mlm_example(request: "SubRequest") -> Dict[str, JSON]:
with open(os.path.join(EXAMPLES_DIR, request.param)) as example_file:
data = json.load(example_file)
return cast(JSON, data)
return cast(Dict[str, JSON], data)


@pytest.fixture(name="eurosat_resnet")
Expand Down
18 changes: 9 additions & 9 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
def test_mlm_schema(
mlm_validator: STACValidator,
mlm_example: JSON,
mlm_example: Dict[str, JSON],
) -> None:
mlm_item = pystac.Item.from_dict(cast(Dict[str, Any], mlm_example))
validated = pystac.validation.validate(mlm_item, validator=mlm_validator)
Expand All @@ -34,13 +34,13 @@ def test_mlm_schema(
)
def test_mlm_eo_bands_invalid_only_in_item_properties(
mlm_validator: STACValidator,
mlm_example: JSON,
mlm_example: Dict[str, JSON],
) -> None:
mlm_item = pystac.Item.from_dict(mlm_example)
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid

mlm_eo_bands_bad_data: Dict[str, JSON] = copy.deepcopy(mlm_example)
mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands")
mlm_eo_bands_bad_data = copy.deepcopy(mlm_example)
mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands") # type: ignore
with pytest.raises(pystac.errors.STACValidationError):
mlm_eo_bands_bad_item = pystac.Item.from_dict(mlm_eo_bands_bad_data)
pystac.validation.validate(mlm_eo_bands_bad_item, validator=mlm_validator)
Expand All @@ -53,15 +53,15 @@ def test_mlm_eo_bands_invalid_only_in_item_properties(
)
def test_mlm_no_input_allowed_but_explicit_empty_array_required(
mlm_validator: STACValidator,
mlm_example: JSON,
mlm_example: Dict[str, JSON],
) -> None:
mlm_data = copy.deepcopy(mlm_example)
mlm_data["properties"]["mlm:input"] = []
mlm_data["properties"]["mlm:input"] = [] # type: ignore
mlm_item = pystac.Item.from_dict(mlm_data)
pystac.validation.validate(mlm_item, validator=mlm_validator)

with pytest.raises(pystac.errors.STACValidationError):
mlm_data["properties"].pop("mlm:input")
mlm_data["properties"].pop("mlm:input") # type: ignore
mlm_item = pystac.Item.from_dict(mlm_data)
pystac.validation.validate(mlm_item, validator=mlm_validator)

Expand All @@ -85,11 +85,11 @@ def test_validate_model_against_schema(eurosat_resnet, mlm_validator):
["collection.json"],
indirect=True,
)
def test_collection_include_all_items(mlm_example: JSON):
def test_collection_include_all_items(mlm_example):
"""
This is only for self-validation, to make sure all examples are contained in the example STAC collection.
"""
col_links: List[JSON] = mlm_example["links"]
col_links: List[Dict[str, str]] = mlm_example["links"]
col_items = {os.path.basename(link["href"]) for link in col_links if link["rel"] == "item"}
all_items = {os.path.basename(path) for path in get_all_stac_item_examples()}
assert all_items == col_items, "Missing STAC Item examples in the example STAC Collection links."

0 comments on commit 4c52f6d

Please sign in to comment.