Skip to content

Commit 10e1efe

Browse files
committed
Use root StacIO in Catalog.set_root
1 parent cafa5ab commit 10e1efe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pystac/catalog.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ def __repr__(self) -> str:
180180
return "<Catalog id={}>".format(self.id)
181181

182182
def set_root(self, root: Optional["Catalog"]) -> None:
183-
STACObject.set_root(self, root)
183+
super().set_root(root)
184184
if root is not None:
185185
root._resolved_objects = ResolvedObjectCache.merge(
186186
root._resolved_objects, self._resolved_objects
187187
)
188+
if root._stac_io is not None:
189+
self._stac_io = root._stac_io
188190

189191
def is_relative(self) -> bool:
190192
return self.catalog_type in [

tests/test_catalog.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
HIERARCHICAL_LINKS,
1919
)
2020
from pystac.extensions.label import LabelClasses, LabelExtension, LabelType
21+
from pystac.stac_io import DefaultStacIO
2122
from pystac.utils import is_absolute_href, join_path_or_url, JoinType
2223
from tests.utils import (
2324
TestCases,
@@ -107,6 +108,19 @@ def test_from_dict_set_root(self) -> None:
107108
collection = Catalog.from_dict(cat_dict, root=root_cat)
108109
self.assertIs(collection.get_root(), root_cat)
109110

111+
def test_from_dict_uses_root_stac_io(self) -> None:
112+
class CustomStacIO(DefaultStacIO):
113+
pass
114+
115+
path = TestCases.get_path("data-files/catalogs/test-case-1/catalog.json")
116+
with open(path) as f:
117+
cat_dict = json.load(f)
118+
root_cat = pystac.Catalog(id="test", description="test desc")
119+
root_cat._stac_io = CustomStacIO()
120+
121+
collection = Catalog.from_dict(cat_dict, root=root_cat)
122+
self.assertIsInstance(collection._stac_io, CustomStacIO)
123+
110124
def test_read_remote(self) -> None:
111125
# TODO: Move this URL to the main stac-spec repo once the example JSON is fixed.
112126
catalog_url = (

0 commit comments

Comments
 (0)