Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
"Typing :: Typed",
]
version = "0.5.0"
dependencies = ["pydantic>=2.3,<3"]
dependencies = ["pydantic>=2.3,<3", "typing-extensions>=4.12.2"]

[project.optional-dependencies]
test = ["pytest", "pytest-cov"]
Expand Down
5 changes: 3 additions & 2 deletions src/edr_pydantic/extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from typing import Optional
from typing import Union

from annotated_types import Len
from pydantic import AwareDatetime
from typing_extensions import Annotated

from .base_model import EdrBaseModel

Expand All @@ -13,8 +15,7 @@ class Spatial(EdrBaseModel):


class Temporal(EdrBaseModel):
# TODO: Validate this list has two items (C.7. Temporal Object)
interval: List[List[AwareDatetime]]
interval: List[Annotated[List[AwareDatetime], Len(min_length=2, max_length=2)]]
# TODO: Validate this is a list of ISO 8601 single time, ISO 8601 time duration or ISO 8601 interval
values: List[str]
trs: str
Expand Down
11 changes: 11 additions & 0 deletions tests/test_data/temporal-interval-length1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"interval": [
[
"2020-04-19T11:00:00Z"
]
],
"values": [
"2020-04-19T11:00:00Z/2020-06-30T09:00:00Z"
],
"trs": "TIMECRS[\"DateTime\",TDATUM[\"Gregorian Calendar\"],CS[TemporalDateTime,1],AXIS[\"Time (T)\",future]]"
}
13 changes: 13 additions & 0 deletions tests/test_data/temporal-interval-length3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"interval": [
[
"2020-04-19T11:00:00Z",
"2020-04-19T12:00:00Z",
"2020-04-19T13:00:00Z"
]
],
"values": [
"2020-04-19T11:00:00Z/2020-06-30T09:00:00Z"
],
"trs": "TIMECRS[\"DateTime\",TDATUM[\"Gregorian Calendar\"],CS[TemporalDateTime,1],AXIS[\"Time (T)\",future]]"
}
7 changes: 6 additions & 1 deletion tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from edr_pydantic.collections import Collections
from edr_pydantic.collections import Instance
from edr_pydantic.extent import Extent
from edr_pydantic.extent import Temporal
from edr_pydantic.parameter import Parameter
from edr_pydantic.unit import Unit
from pydantic import RootModel
Expand Down Expand Up @@ -35,7 +36,11 @@ def test_happy_cases(file_name, object_type):
assert object_type.model_validate_json(json_string).model_dump_json(exclude_none=True) == json_string


error_cases = [("label-or-symbol-unit.json", Unit, r"Either 'label' or 'symbol' should be set")]
error_cases = [
("label-or-symbol-unit.json", Unit, r"Either 'label' or 'symbol' should be set"),
("temporal-interval-length1.json", Temporal, r"List should have at least 2 items after validation"),
("temporal-interval-length3.json", Temporal, r"List should have at most 2 items after validation, not 3"),
]


@pytest.mark.parametrize("file_name, object_type, error_message", error_cases)
Expand Down