Skip to content

Commit a7c0e43

Browse files
committed
tests: Make tests runnable from anywhere
By using the current file rather than the root of the project as the reference, the tests are now runnable for example in an IDE which uses the "tests" directory as the root.
1 parent f9573f8 commit a7c0e43

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

tests/test_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def test_collections_cache_correctly(self) -> None:
939939

940940
def test_reading_iterating_and_writing_works_as_expected(self) -> None:
941941
"""Test case to cover issue #88"""
942-
stac_uri = "tests/data-files/catalogs/test-case-6/catalog.json"
942+
stac_uri = TestCases.get_path("data-files/catalogs/test-case-6/catalog.json")
943943
cat = Catalog.from_file(stac_uri)
944944

945945
# Iterate over the items. This was causing failure in

tests/test_item_collection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import json
33
from pystac.item_collection import ItemCollection
44
import unittest
5+
from os.path import relpath
6+
57
import pystac
68

79
from tests.utils import TestCases
@@ -101,7 +103,11 @@ def test_raise_error_for_invalid_object(self) -> None:
101103

102104
def test_from_relative_path(self) -> None:
103105
_ = pystac.ItemCollection.from_file(
104-
"./tests/data-files/item-collection/sample-item-collection.json"
106+
relpath(
107+
TestCases.get_path(
108+
"data-files/item-collection/sample-item-collection.json"
109+
)
110+
)
105111
)
106112

107113
def test_from_list_of_dicts(self) -> None:

tests/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pystac import utils
99

1010
from pystac.utils import make_relative_href, make_absolute_href, is_absolute_href
11+
from tests.utils import TestCases
1112

1213

1314
class UtilsTest(unittest.TestCase):
@@ -273,7 +274,9 @@ def test_datetime_to_str(self) -> None:
273274

274275
def test_geojson_bbox(self) -> None:
275276
# Use sample Geojson from https://en.wikipedia.org/wiki/GeoJSON
276-
with open("tests/data-files/geojson/sample.geojson") as sample_geojson:
277+
with open(
278+
TestCases.get_path("data-files/geojson/sample.geojson")
279+
) as sample_geojson:
277280
all_features = json.load(sample_geojson)
278281
geom_dicts = [f["geometry"] for f in all_features["features"]]
279282
for geom in geom_dicts:

0 commit comments

Comments
 (0)