7
7
8
8
import pytest
9
9
10
- import pystac
10
+ from pystac import (
11
+ Collection ,
12
+ ExtensionNotImplemented ,
13
+ Extent ,
14
+ Item ,
15
+ SpatialExtent ,
16
+ STACValidationError ,
17
+ TemporalExtent ,
18
+ )
11
19
from pystac .errors import DeprecatedWarning , ExtensionTypeError
12
20
from pystac .extensions import version
13
21
from pystac .extensions .version import (
22
30
URL_TEMPLATE : str = "http://example.com/catalog/%s.json"
23
31
24
32
25
- def make_item (year : int ) -> pystac . Item :
33
+ def make_item (year : int ) -> Item :
26
34
"""Create basic test items that are only slightly different."""
27
35
asset_id = f"USGS/GAP/CONUS/{ year } "
28
36
start = datetime (year , 1 , 2 )
29
37
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 = {})
33
39
item .set_self_href (URL_TEMPLATE % year )
34
40
35
41
VersionExtension .add_to (item )
@@ -135,7 +141,7 @@ def test_successor(self) -> None:
135
141
136
142
@pytest .mark .vcr ()
137
143
def test_fail_validate (self ) -> None :
138
- with self .assertRaises (pystac . STACValidationError ):
144
+ with self .assertRaises (STACValidationError ):
139
145
self .item .validate ()
140
146
141
147
@pytest .mark .vcr ()
@@ -247,14 +253,14 @@ def test_multiple_link_setting(self) -> None:
247
253
248
254
def test_extension_not_implemented (self ) -> None :
249
255
# 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 )
251
257
item .stac_extensions .remove (VersionExtension .get_schema_uri ())
252
258
253
- with self .assertRaises (pystac . ExtensionNotImplemented ):
259
+ with self .assertRaises (ExtensionNotImplemented ):
254
260
_ = VersionExtension .ext (item )
255
261
256
262
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 )
258
264
item .stac_extensions .remove (VersionExtension .get_schema_uri ())
259
265
self .assertNotIn (VersionExtension .get_schema_uri (), item .stac_extensions )
260
266
@@ -263,17 +269,17 @@ def test_ext_add_to(self) -> None:
263
269
self .assertIn (VersionExtension .get_schema_uri (), item .stac_extensions )
264
270
265
271
266
- def make_collection (year : int ) -> pystac . Collection :
272
+ def make_collection (year : int ) -> Collection :
267
273
asset_id = f"my/collection/of/things/{ year } "
268
274
start = datetime (2014 , 8 , 10 )
269
275
end = datetime (year , 1 , 3 , 4 , 5 )
270
276
bboxes = [[- 180.0 , - 90.0 , 180.0 , 90.0 ]]
271
- spatial_extent = pystac . SpatialExtent (bboxes )
277
+ spatial_extent = SpatialExtent (bboxes )
272
278
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 )
275
281
276
- collection = pystac . Collection (asset_id , "desc" , extent )
282
+ collection = Collection (asset_id , "desc" , extent )
277
283
collection .set_self_href (URL_TEMPLATE % year )
278
284
279
285
VersionExtension .add_to (collection )
@@ -366,7 +372,7 @@ def test_successor(self) -> None:
366
372
367
373
@pytest .mark .vcr ()
368
374
def test_fail_validate (self ) -> None :
369
- with self .assertRaises (pystac . STACValidationError ):
375
+ with self .assertRaises (STACValidationError ):
370
376
self .collection .validate ()
371
377
372
378
@pytest .mark .vcr ()
@@ -385,9 +391,9 @@ def test_full_copy(self) -> None:
385
391
386
392
# Fetch two collections from the catalog
387
393
col1 = cat .get_child ("area-1-1" , recursive = True )
388
- assert isinstance (col1 , pystac . Collection )
394
+ assert isinstance (col1 , Collection )
389
395
col2 = cat .get_child ("area-2-2" , recursive = True )
390
- assert isinstance (col2 , pystac . Collection )
396
+ assert isinstance (col2 , Collection )
391
397
392
398
# Enable the version extension on each, and link them
393
399
# as if they are different versions of the same Collection
@@ -482,15 +488,15 @@ def test_multiple_link_setting(self) -> None:
482
488
def test_extension_not_implemented (self ) -> None :
483
489
# Should raise exception if Collection does not include extension URI
484
490
with ignore_deprecated ():
485
- collection = pystac . Collection .from_file (self .example_collection_uri )
491
+ collection = Collection .from_file (self .example_collection_uri )
486
492
collection .stac_extensions .remove (VersionExtension .get_schema_uri ())
487
493
488
- with self .assertRaises (pystac . ExtensionNotImplemented ):
494
+ with self .assertRaises (ExtensionNotImplemented ):
489
495
_ = VersionExtension .ext (collection )
490
496
491
497
def test_ext_add_to (self ) -> None :
492
498
with ignore_deprecated ():
493
- collection = pystac . Collection .from_file (self .example_collection_uri )
499
+ collection = Collection .from_file (self .example_collection_uri )
494
500
collection .stac_extensions .remove (VersionExtension .get_schema_uri ())
495
501
self .assertNotIn (VersionExtension .get_schema_uri (), collection .stac_extensions )
496
502
@@ -500,32 +506,32 @@ def test_ext_add_to(self) -> None:
500
506
501
507
502
508
def test_item_deprecation_warning (
503
- item : pystac . Item , recwarn : Generator [pytest .WarningsRecorder , None , None ]
509
+ item : Item , recwarn : Generator [pytest .WarningsRecorder , None , None ]
504
510
) -> None :
505
511
version = ItemVersionExtension .ext (item , add_if_missing = True )
506
512
version .deprecated = True
507
513
item_dict = item .to_dict ()
508
514
with pytest .warns (DeprecatedWarning , match = "The item 'test-item' is deprecated." ):
509
- _ = pystac . Item .from_dict (item_dict )
515
+ _ = Item .from_dict (item_dict )
510
516
511
517
version .deprecated = False
512
518
item_dict = item .to_dict ()
513
- _ = pystac . Item .from_dict (item_dict )
519
+ _ = Item .from_dict (item_dict )
514
520
assert len (list (recwarn )) == 0
515
521
516
522
version .deprecated = None
517
523
item_dict = item .to_dict ()
518
- _ = pystac . Item .from_dict (item_dict )
524
+ _ = Item .from_dict (item_dict )
519
525
assert len (list (recwarn )) == 0
520
526
521
527
ItemVersionExtension .remove_from (item )
522
528
item_dict = item .to_dict ()
523
- _ = pystac . Item .from_dict (item_dict )
529
+ _ = Item .from_dict (item_dict )
524
530
assert len (list (recwarn )) == 0
525
531
526
532
527
533
def test_collection_deprecation_warning (
528
- collection : pystac . Collection ,
534
+ collection : Collection ,
529
535
recwarn : Generator [pytest .WarningsRecorder , None , None ],
530
536
) -> None :
531
537
version = CollectionVersionExtension .ext (collection , add_if_missing = True )
@@ -534,31 +540,31 @@ def test_collection_deprecation_warning(
534
540
with pytest .warns (
535
541
DeprecatedWarning , match = "The collection 'test-collection' is deprecated."
536
542
):
537
- _ = pystac . Collection .from_dict (collection_dict )
543
+ _ = Collection .from_dict (collection_dict )
538
544
539
545
version .deprecated = False
540
546
collection .extra_fields ["deprecated" ] = False
541
547
collection_dict = collection .to_dict ()
542
- _ = pystac . Collection .from_dict (collection_dict )
548
+ _ = Collection .from_dict (collection_dict )
543
549
assert len (list (recwarn )) == 0
544
550
545
551
version .deprecated = None
546
552
collection_dict = collection .to_dict ()
547
- _ = pystac . Collection .from_dict (collection_dict )
553
+ _ = Collection .from_dict (collection_dict )
548
554
assert len (list (recwarn )) == 0
549
555
550
556
CollectionVersionExtension .remove_from (collection )
551
557
collection_dict = collection .to_dict ()
552
- _ = pystac . Collection .from_dict (collection_dict )
558
+ _ = Collection .from_dict (collection_dict )
553
559
assert len (list (recwarn )) == 0
554
560
555
561
556
562
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 ]
558
564
) -> None :
559
565
version = VersionExtension .ext (item , add_if_missing = True )
560
566
version .deprecated = True
561
567
item_dict = item .to_dict ()
562
568
with ignore_deprecated ():
563
- _ = pystac . Item .from_dict (item_dict )
569
+ _ = Item .from_dict (item_dict )
564
570
assert len (list (recwarn )) == 0
0 commit comments