Skip to content

Commit 31f072d

Browse files
authored
Merge branch 'main' into issue-789
2 parents d38f3ba + 1261e60 commit 31f072d

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

mypy.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ ignore_missing_imports = True
1010

1111
[mypy-setuptools.*]
1212
ignore_missing_imports = True
13-
14-
[mypy-sphinx.util]
15-
ignore_missing_imports = True

pystac/asset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def get_absolute_href(self) -> Optional[str]:
9292
"""Gets the absolute href for this asset, if possible.
9393
9494
If this Asset has no associated Item, and the asset HREF is a relative path,
95-
this method will return None.
95+
this method will return ``None``. If the Item that owns the Asset has no
96+
self HREF, this will also return ``None``.
9697
9798
Returns:
9899
str: The absolute HREF of this asset, or None if an absolute HREF could not
@@ -102,9 +103,10 @@ def get_absolute_href(self) -> Optional[str]:
102103
return self.href
103104
else:
104105
if self.owner is not None:
105-
return utils.make_absolute_href(self.href, self.owner.get_self_href())
106-
else:
107-
return None
106+
item_self = self.owner.get_self_href()
107+
if item_self is not None:
108+
return utils.make_absolute_href(self.href, item_self)
109+
return None
108110

109111
def to_dict(self) -> Dict[str, Any]:
110112
"""Generate a dictionary representing the JSON of this Asset.

tests/test_item.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,28 @@ def test_set_self_href_none_ignores_relative_asset_hrefs(self) -> None:
7272
self.assertFalse(is_absolute_href(asset.href))
7373

7474
def test_asset_absolute_href(self) -> None:
75+
item_path = TestCases.get_path("data-files/item/sample-item.json")
7576
item_dict = self.get_example_item_dict()
7677
item = Item.from_dict(item_dict)
78+
item.set_self_href(item_path)
7779
rel_asset = Asset("./data.geojson")
7880
rel_asset.set_owner(item)
79-
expected_href = os.path.abspath("./data.geojson")
81+
expected_href = os.path.abspath(
82+
os.path.join(os.path.dirname(item_path), "./data.geojson")
83+
)
8084
actual_href = rel_asset.get_absolute_href()
8185
self.assertEqual(expected_href, actual_href)
8286

87+
def test_asset_absolute_href_no_item_self(self) -> None:
88+
item_dict = self.get_example_item_dict()
89+
item = Item.from_dict(item_dict)
90+
assert item.get_self_href() is None
91+
92+
rel_asset = Asset("./data.geojson")
93+
rel_asset.set_owner(item)
94+
actual_href = rel_asset.get_absolute_href()
95+
self.assertEqual(None, actual_href)
96+
8397
def test_extra_fields(self) -> None:
8498
item = pystac.Item.from_file(
8599
TestCases.get_path("data-files/item/sample-item.json")

0 commit comments

Comments
 (0)