Skip to content

Commit cdb1adc

Browse files
committed
refactor: normalize import style
#1259
1 parent 59d1868 commit cdb1adc

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

tests/extensions/test_version.py

+38-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77

88
import pytest
99

10-
import pystac
10+
from pystac import (
11+
Collection,
12+
ExtensionNotImplemented,
13+
Extent,
14+
Item,
15+
SpatialExtent,
16+
STACValidationError,
17+
TemporalExtent,
18+
)
1119
from pystac.errors import DeprecatedWarning, ExtensionTypeError
1220
from pystac.extensions import version
1321
from pystac.extensions.version import (
@@ -22,14 +30,12 @@
2230
URL_TEMPLATE: str = "http://example.com/catalog/%s.json"
2331

2432

25-
def make_item(year: int) -> pystac.Item:
33+
def make_item(year: int) -> Item:
2634
"""Create basic test items that are only slightly different."""
2735
asset_id = f"USGS/GAP/CONUS/{year}"
2836
start = datetime(year, 1, 2)
2937

30-
item = pystac.Item(
31-
id=asset_id, geometry=None, bbox=None, datetime=start, properties={}
32-
)
38+
item = Item(id=asset_id, geometry=None, bbox=None, datetime=start, properties={})
3339
item.set_self_href(URL_TEMPLATE % year)
3440

3541
VersionExtension.add_to(item)
@@ -135,7 +141,7 @@ def test_successor(self) -> None:
135141

136142
@pytest.mark.vcr()
137143
def test_fail_validate(self) -> None:
138-
with self.assertRaises(pystac.STACValidationError):
144+
with self.assertRaises(STACValidationError):
139145
self.item.validate()
140146

141147
@pytest.mark.vcr()
@@ -247,14 +253,14 @@ def test_multiple_link_setting(self) -> None:
247253

248254
def test_extension_not_implemented(self) -> None:
249255
# Should raise exception if Item does not include extension URI
250-
item = pystac.Item.from_file(self.example_item_uri)
256+
item = Item.from_file(self.example_item_uri)
251257
item.stac_extensions.remove(VersionExtension.get_schema_uri())
252258

253-
with self.assertRaises(pystac.ExtensionNotImplemented):
259+
with self.assertRaises(ExtensionNotImplemented):
254260
_ = VersionExtension.ext(item)
255261

256262
def test_ext_add_to(self) -> None:
257-
item = pystac.Item.from_file(self.example_item_uri)
263+
item = Item.from_file(self.example_item_uri)
258264
item.stac_extensions.remove(VersionExtension.get_schema_uri())
259265
self.assertNotIn(VersionExtension.get_schema_uri(), item.stac_extensions)
260266

@@ -263,17 +269,17 @@ def test_ext_add_to(self) -> None:
263269
self.assertIn(VersionExtension.get_schema_uri(), item.stac_extensions)
264270

265271

266-
def make_collection(year: int) -> pystac.Collection:
272+
def make_collection(year: int) -> Collection:
267273
asset_id = f"my/collection/of/things/{year}"
268274
start = datetime(2014, 8, 10)
269275
end = datetime(year, 1, 3, 4, 5)
270276
bboxes = [[-180.0, -90.0, 180.0, 90.0]]
271-
spatial_extent = pystac.SpatialExtent(bboxes)
277+
spatial_extent = SpatialExtent(bboxes)
272278
intervals: list[list[Optional[datetime]]] = [[start, end]]
273-
temporal_extent = pystac.TemporalExtent(intervals)
274-
extent = pystac.Extent(spatial_extent, temporal_extent)
279+
temporal_extent = TemporalExtent(intervals)
280+
extent = Extent(spatial_extent, temporal_extent)
275281

276-
collection = pystac.Collection(asset_id, "desc", extent)
282+
collection = Collection(asset_id, "desc", extent)
277283
collection.set_self_href(URL_TEMPLATE % year)
278284

279285
VersionExtension.add_to(collection)
@@ -366,7 +372,7 @@ def test_successor(self) -> None:
366372

367373
@pytest.mark.vcr()
368374
def test_fail_validate(self) -> None:
369-
with self.assertRaises(pystac.STACValidationError):
375+
with self.assertRaises(STACValidationError):
370376
self.collection.validate()
371377

372378
@pytest.mark.vcr()
@@ -385,9 +391,9 @@ def test_full_copy(self) -> None:
385391

386392
# Fetch two collections from the catalog
387393
col1 = cat.get_child("area-1-1", recursive=True)
388-
assert isinstance(col1, pystac.Collection)
394+
assert isinstance(col1, Collection)
389395
col2 = cat.get_child("area-2-2", recursive=True)
390-
assert isinstance(col2, pystac.Collection)
396+
assert isinstance(col2, Collection)
391397

392398
# Enable the version extension on each, and link them
393399
# as if they are different versions of the same Collection
@@ -482,15 +488,15 @@ def test_multiple_link_setting(self) -> None:
482488
def test_extension_not_implemented(self) -> None:
483489
# Should raise exception if Collection does not include extension URI
484490
with ignore_deprecated():
485-
collection = pystac.Collection.from_file(self.example_collection_uri)
491+
collection = Collection.from_file(self.example_collection_uri)
486492
collection.stac_extensions.remove(VersionExtension.get_schema_uri())
487493

488-
with self.assertRaises(pystac.ExtensionNotImplemented):
494+
with self.assertRaises(ExtensionNotImplemented):
489495
_ = VersionExtension.ext(collection)
490496

491497
def test_ext_add_to(self) -> None:
492498
with ignore_deprecated():
493-
collection = pystac.Collection.from_file(self.example_collection_uri)
499+
collection = Collection.from_file(self.example_collection_uri)
494500
collection.stac_extensions.remove(VersionExtension.get_schema_uri())
495501
self.assertNotIn(VersionExtension.get_schema_uri(), collection.stac_extensions)
496502

@@ -500,32 +506,32 @@ def test_ext_add_to(self) -> None:
500506

501507

502508
def test_item_deprecation_warning(
503-
item: pystac.Item, recwarn: Generator[pytest.WarningsRecorder, None, None]
509+
item: Item, recwarn: Generator[pytest.WarningsRecorder, None, None]
504510
) -> None:
505511
version = ItemVersionExtension.ext(item, add_if_missing=True)
506512
version.deprecated = True
507513
item_dict = item.to_dict()
508514
with pytest.warns(DeprecatedWarning, match="The item 'test-item' is deprecated."):
509-
_ = pystac.Item.from_dict(item_dict)
515+
_ = Item.from_dict(item_dict)
510516

511517
version.deprecated = False
512518
item_dict = item.to_dict()
513-
_ = pystac.Item.from_dict(item_dict)
519+
_ = Item.from_dict(item_dict)
514520
assert len(list(recwarn)) == 0
515521

516522
version.deprecated = None
517523
item_dict = item.to_dict()
518-
_ = pystac.Item.from_dict(item_dict)
524+
_ = Item.from_dict(item_dict)
519525
assert len(list(recwarn)) == 0
520526

521527
ItemVersionExtension.remove_from(item)
522528
item_dict = item.to_dict()
523-
_ = pystac.Item.from_dict(item_dict)
529+
_ = Item.from_dict(item_dict)
524530
assert len(list(recwarn)) == 0
525531

526532

527533
def test_collection_deprecation_warning(
528-
collection: pystac.Collection,
534+
collection: Collection,
529535
recwarn: Generator[pytest.WarningsRecorder, None, None],
530536
) -> None:
531537
version = CollectionVersionExtension.ext(collection, add_if_missing=True)
@@ -534,31 +540,31 @@ def test_collection_deprecation_warning(
534540
with pytest.warns(
535541
DeprecatedWarning, match="The collection 'test-collection' is deprecated."
536542
):
537-
_ = pystac.Collection.from_dict(collection_dict)
543+
_ = Collection.from_dict(collection_dict)
538544

539545
version.deprecated = False
540546
collection.extra_fields["deprecated"] = False
541547
collection_dict = collection.to_dict()
542-
_ = pystac.Collection.from_dict(collection_dict)
548+
_ = Collection.from_dict(collection_dict)
543549
assert len(list(recwarn)) == 0
544550

545551
version.deprecated = None
546552
collection_dict = collection.to_dict()
547-
_ = pystac.Collection.from_dict(collection_dict)
553+
_ = Collection.from_dict(collection_dict)
548554
assert len(list(recwarn)) == 0
549555

550556
CollectionVersionExtension.remove_from(collection)
551557
collection_dict = collection.to_dict()
552-
_ = pystac.Collection.from_dict(collection_dict)
558+
_ = Collection.from_dict(collection_dict)
553559
assert len(list(recwarn)) == 0
554560

555561

556562
def test_ignore_deprecated_context_manager(
557-
item: pystac.Item, recwarn: Generator[pytest.WarningsRecorder, None, None]
563+
item: Item, recwarn: Generator[pytest.WarningsRecorder, None, None]
558564
) -> None:
559565
version = VersionExtension.ext(item, add_if_missing=True)
560566
version.deprecated = True
561567
item_dict = item.to_dict()
562568
with ignore_deprecated():
563-
_ = pystac.Item.from_dict(item_dict)
569+
_ = Item.from_dict(item_dict)
564570
assert len(list(recwarn)) == 0

0 commit comments

Comments
 (0)