Skip to content

Commit 7f2214c

Browse files
committed
feat: more v1 tests
1 parent 3ce03ed commit 7f2214c

File tree

90 files changed

+18339
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+18339
-119
lines changed

docs/api/general.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
::: pystac.read_file
66
::: pystac.read_dict
77
::: pystac.write_file
8-
::: pystac.PystacError
9-
::: pystac.StacError
10-
::: pystac.PystacWarning
11-
::: pystac.StacWarning
8+
::: pystac.PySTACError
9+
::: pystac.STACError
10+
::: pystac.PySTACWarning
11+
::: pystac.STACWarning

src/pystac/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from .constants import DEFAULT_STAC_VERSION
77
from .container import Container
88
from .errors import (
9-
PystacError,
10-
PystacWarning,
11-
StacError,
12-
StacWarning,
9+
PySTACError,
10+
PySTACWarning,
11+
STACError,
12+
STACWarning,
1313
)
1414
from .extent import Extent, SpatialExtent, TemporalExtent
1515
from .functions import get_stac_version, read_dict, set_stac_version
@@ -37,10 +37,10 @@ def __getattr__(name: str) -> Any:
3737
"Collection",
3838
"DEFAULT_STAC_VERSION",
3939
"Container",
40-
"PystacError",
41-
"PystacWarning",
42-
"StacError",
43-
"StacWarning",
40+
"PySTACError",
41+
"PySTACWarning",
42+
"STACError",
43+
"STACWarning",
4444
"Extent",
4545
"SpatialExtent",
4646
"TemporalExtent",

src/pystac/asset.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from __future__ import annotations
22

33
import copy
4-
from typing import Any, Protocol, runtime_checkable
4+
from typing import TYPE_CHECKING, Any
55

66
from typing_extensions import Self
77

8+
from . import deprecate, utils
9+
10+
if TYPE_CHECKING:
11+
from .stac_object import STACObject
12+
813

914
class ItemAsset:
1015
"""An asset without a href.
@@ -70,15 +75,23 @@ def __init__(
7075
title=title, description=description, type=type, roles=roles, **kwargs
7176
)
7277

78+
@deprecate.function(
79+
"assets aren't owned anymore, all this method does is make the asset's "
80+
"relative href absolute using the 'owner's href"
81+
)
82+
def set_owner(self, owner: STACObject) -> None:
83+
if owner.href:
84+
self.href = utils.make_absolute_href(self.href, owner.href)
85+
86+
@deprecate.function("prefer to use `STACObject.render()` then `asset.href`")
87+
def get_absolute_href(self) -> str | None:
88+
if utils.is_absolute_href(self.href):
89+
return self.href
90+
else:
91+
return None
92+
7393
def to_dict(self) -> dict[str, Any]:
7494
"""Converts this asset to a dictionary."""
7595
d = {"href": self.href}
7696
d.update(super().to_dict())
7797
return d
78-
79-
80-
@runtime_checkable
81-
class Assets(Protocol):
82-
"""A protocol for things that have assets (Collections and Items)"""
83-
84-
assets: dict[str, Asset]

src/pystac/collection.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ def __init__(
5656
else:
5757
self.extent = Extent.from_dict(extent)
5858

59-
if assets is None:
60-
self.assets = None
61-
else:
62-
self.assets = dict(
63-
(key, asset if isinstance(asset, Asset) else Asset.from_dict(asset))
64-
for key, asset in assets.items()
65-
)
66-
6759
if item_assets is None:
6860
self.item_assets = None
6961
else:
@@ -77,7 +69,14 @@ def __init__(
7769
for key, item_asset in item_assets.items()
7870
)
7971

80-
super().__init__(id, stac_version, stac_extensions, links, **kwargs)
72+
super().__init__(
73+
id=id,
74+
stac_version=stac_version,
75+
stac_extensions=stac_extensions,
76+
links=links,
77+
assets=assets,
78+
**kwargs,
79+
)
8180

8281
def _to_dict(self) -> dict[str, Any]:
8382
"""Converts this collection to a dictionary."""
@@ -100,7 +99,7 @@ def _to_dict(self) -> dict[str, Any]:
10099
if self.summaries is not None:
101100
d["summaries"] = self.summaries
102101
d["links"] = [link.to_dict() for link in self.iter_links()]
103-
if self.assets is not None:
102+
if self.assets:
104103
d["assets"] = dict(
105104
(key, asset.to_dict()) for key, asset in self.assets.items()
106105
)

src/pystac/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
"""The root relation type, for links."""
2828
SELF = "self"
2929
"""The self relation type, for links."""
30+
COLLECTION = "collection"
31+
"""The collection relation type, for links."""

src/pystac/container.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ def add_child(self, child: Container) -> None:
8484
"""Adds a child to this container."""
8585
self.add_link(Link.child(child))
8686

87+
def get_child(
88+
self, id: str, recursive: bool = False, sort_links_by_id: bool = True
89+
) -> Container | None:
90+
# TODO handle sort links by id
91+
for child in self.get_children(recursive=recursive):
92+
if child.id == id:
93+
return child
94+
return None
95+
8796
def get_children(self, recursive: bool = False) -> Iterator[Container]:
8897
"""Iterates over all children in this container.
8998

src/pystac/errors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
class PystacError(Exception):
1+
class PySTACError(Exception):
22
"""A custom error class for this library."""
33

44

5-
class StacError(PystacError):
6-
"""A subclass of [PystacError][pystac.PystacError] for errors related to the
5+
class STACError(PySTACError):
6+
"""A subclass of [PySTACError][pystac.PySTACError] for errors related to the
77
STAC specification itself."""
88

99

10-
class PystacWarning(Warning):
10+
class PySTACWarning(Warning):
1111
"""A custom warning class for this library."""
1212

1313

14-
class StacWarning(PystacWarning):
14+
class STACWarning(PySTACWarning):
1515
"""A warning about something incorrect per the STAC specification."""

src/pystac/extensions/extension.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing_extensions import Self
66

7-
from ..errors import PystacWarning
7+
from ..errors import PySTACWarning
88
from .protocols import Extendable
99

1010

@@ -87,11 +87,11 @@ def version(self) -> str | None:
8787
return parts[1][1:]
8888
else:
8989
warnings.warn(
90-
f"Invalid extension version: {parts[1]}", PystacWarning
90+
f"Invalid extension version: {parts[1]}", PySTACWarning
9191
)
9292
return None
9393
else:
94-
warnings.warn(f"Invalid extension url: {url}", PystacWarning)
94+
warnings.warn(f"Invalid extension url: {url}", PySTACWarning)
9595
return None
9696
else:
9797
return None

src/pystac/extent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from . import deprecate
1111
from .constants import DEFAULT_BBOX, DEFAULT_INTERVAL
12-
from .errors import StacWarning
12+
from .errors import STACWarning
1313
from .types import PermissiveBbox, PermissiveInterval
1414

1515

@@ -115,7 +115,7 @@ def __init__(
115115
warnings.warn(
116116
"Invalid temporal interval (trailing single values), "
117117
"discarding",
118-
StacWarning,
118+
STACWarning,
119119
)
120120
else:
121121
self.interval.append(_create_interval(interval)) # type: ignore
@@ -133,7 +133,7 @@ def datetime_str(value: datetime.datetime | str | None) -> str | None:
133133
return value
134134
else:
135135
warnings.warn(
136-
f"Invalid interval value ({type(value)}), converting to None", StacWarning
136+
f"Invalid interval value ({type(value)}), converting to None", STACWarning
137137
)
138138
return None
139139

@@ -142,15 +142,15 @@ def _create_interval(
142142
interval: list[str | datetime.datetime | None],
143143
) -> list[str | None]:
144144
if len(interval) == 0:
145-
warnings.warn("Invalid interval value (empty list)", StacWarning)
145+
warnings.warn("Invalid interval value (empty list)", STACWarning)
146146
interval = [None, None]
147147
elif len(interval) == 1:
148-
warnings.warn("Invalid interval value (single entry list)", StacWarning)
148+
warnings.warn("Invalid interval value (single entry list)", STACWarning)
149149
interval.append(None)
150150
elif len(interval) > 2:
151151
warnings.warn(
152152
f"Invalid interval value ({len(interval)} values), truncating",
153-
StacWarning,
153+
STACWarning,
154154
)
155155
interval = interval[0:2]
156156
return [datetime_str(v) for v in interval]

src/pystac/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from typing import Any, Protocol
2727

2828
from . import deprecate
29-
from .errors import PystacError
29+
from .errors import PySTACError
3030
from .stac_object import STACObject
3131

3232

@@ -78,7 +78,7 @@ def write_file(
7878
if dest_href is None:
7979
dest_href = obj.href
8080
if dest_href is None:
81-
raise PystacError(f"cannot write {obj} without an href")
81+
raise PySTACError(f"cannot write {obj} without an href")
8282
d = obj.to_dict()
8383
if isinstance(dest_href, Path):
8484
writer.write_json_to_path(d, dest_href)

0 commit comments

Comments
 (0)