@@ -363,152 +363,151 @@ def test_to_dict_no_self_href() -> None:
363363 Collection .from_dict (d )
364364
365365
366- class ExtentTest (unittest .TestCase ):
367- def test_temporal_extent_init_typing () -> None :
368- # This test exists purely to test the typing of the intervals argument to
369- # TemporalExtent
370- start_datetime = str_to_datetime ("2022-01-01T00:00:00Z" )
371- end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
366+ def test_temporal_extent_init_typing () -> None :
367+ # This test exists purely to test the typing of the intervals argument to
368+ # TemporalExtent
369+ start_datetime = str_to_datetime ("2022-01-01T00:00:00Z" )
370+ end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
372371
373- _ = TemporalExtent ([[start_datetime , end_datetime ]])
372+ _ = TemporalExtent ([[start_datetime , end_datetime ]])
374373
375- @pytest .mark .block_network ()
376- def test_temporal_extent_allows_single_interval () -> None :
377- start_datetime = str_to_datetime ("2022-01-01T00:00:00Z" )
378- end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
374+ @pytest .mark .block_network ()
375+ def test_temporal_extent_allows_single_interval () -> None :
376+ start_datetime = str_to_datetime ("2022-01-01T00:00:00Z" )
377+ end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
379378
380- interval = [start_datetime , end_datetime ]
381- temporal_extent = TemporalExtent (intervals = interval ) # type: ignore
379+ interval = [start_datetime , end_datetime ]
380+ temporal_extent = TemporalExtent (intervals = interval ) # type: ignore
382381
383- assert temporal_extent .intervals == [interval ]
382+ assert temporal_extent .intervals == [interval ]
384383
385- @pytest .mark .block_network ()
386- def test_temporal_extent_allows_single_interval_open_start () -> None :
387- end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
384+ @pytest .mark .block_network ()
385+ def test_temporal_extent_allows_single_interval_open_start () -> None :
386+ end_datetime = str_to_datetime ("2022-01-31T23:59:59Z" )
388387
389- interval = [None , end_datetime ]
390- temporal_extent = TemporalExtent (intervals = interval )
388+ interval = [None , end_datetime ]
389+ temporal_extent = TemporalExtent (intervals = interval )
391390
392- assert temporal_extent .intervals == [interval ]
391+ assert temporal_extent .intervals == [interval ]
393392
394- @pytest .mark .block_network ()
395- def test_temporal_extent_non_list_intervals_fails () -> None :
396- with pytest .raises (TypeError ):
397- # Pass in non-list intervals
398- _ = TemporalExtent (intervals = 1 ) # type: ignore
393+ @pytest .mark .block_network ()
394+ def test_temporal_extent_non_list_intervals_fails () -> None :
395+ with pytest .raises (TypeError ):
396+ # Pass in non-list intervals
397+ _ = TemporalExtent (intervals = 1 ) # type: ignore
399398
400- @pytest .mark .block_network ()
401- def test_spatial_allows_single_bbox () -> None :
402- temporal_extent = TemporalExtent (intervals = [[TEST_DATETIME , None ]])
399+ @pytest .mark .block_network ()
400+ def test_spatial_allows_single_bbox () -> None :
401+ temporal_extent = TemporalExtent (intervals = [[TEST_DATETIME , None ]])
403402
404- # Pass in a single BBOX
405- spatial_extent = SpatialExtent (bboxes = ARBITRARY_BBOX )
403+ # Pass in a single BBOX
404+ spatial_extent = SpatialExtent (bboxes = ARBITRARY_BBOX )
406405
407- collection_extent = Extent (spatial = spatial_extent , temporal = temporal_extent )
406+ collection_extent = Extent (spatial = spatial_extent , temporal = temporal_extent )
408407
409- collection = Collection (
410- id = "test" , description = "test desc" , extent = collection_extent
411- )
408+ collection = Collection (
409+ id = "test" , description = "test desc" , extent = collection_extent
410+ )
412411
413- # HREF required by validation
414- collection .set_self_href ("https://example.com/collection.json" )
412+ # HREF required by validation
413+ collection .set_self_href ("https://example.com/collection.json" )
415414
416- collection .validate ()
415+ collection .validate ()
417416
418- @pytest .mark .block_network ()
419- def test_spatial_extent_non_list_bboxes_fails () -> None :
420- with pytest .raises (TypeError ):
421- # Pass in non-list bboxes
422- _ = SpatialExtent (bboxes = 1 ) # type: ignore
417+ @pytest .mark .block_network ()
418+ def test_spatial_extent_non_list_bboxes_fails () -> None :
419+ with pytest .raises (TypeError ):
420+ # Pass in non-list bboxes
421+ _ = SpatialExtent (bboxes = 1 ) # type: ignore
423422
424- def test_extent_from_items () -> None :
425- item1 = Item (
426- id = "test-item-1" ,
427- geometry = ARBITRARY_GEOM ,
428- bbox = [- 10 , - 20 , 0 , - 10 ],
429- datetime = datetime (2000 , 2 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC ),
430- properties = {},
431- )
423+ def test_extent_from_items () -> None :
424+ item1 = Item (
425+ id = "test-item-1" ,
426+ geometry = ARBITRARY_GEOM ,
427+ bbox = [- 10 , - 20 , 0 , - 10 ],
428+ datetime = datetime (2000 , 2 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC ),
429+ properties = {},
430+ )
432431
433- item2 = Item (
434- id = "test-item-2" ,
435- geometry = ARBITRARY_GEOM ,
436- bbox = [0 , - 9 , 10 , 1 ],
437- datetime = None ,
438- properties = {
439- "start_datetime" : datetime_to_str (
440- datetime (2000 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
441- ),
442- "end_datetime" : datetime_to_str (
443- datetime (2000 , 7 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
444- ),
445- },
446- )
432+ item2 = Item (
433+ id = "test-item-2" ,
434+ geometry = ARBITRARY_GEOM ,
435+ bbox = [0 , - 9 , 10 , 1 ],
436+ datetime = None ,
437+ properties = {
438+ "start_datetime" : datetime_to_str (
439+ datetime (2000 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
440+ ),
441+ "end_datetime" : datetime_to_str (
442+ datetime (2000 , 7 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
443+ ),
444+ },
445+ )
447446
448- item3 = Item (
449- id = "test-item-2" ,
450- geometry = ARBITRARY_GEOM ,
451- bbox = [- 5 , - 20 , 5 , 0 ],
452- datetime = None ,
453- properties = {
454- "start_datetime" : datetime_to_str (
455- datetime (2000 , 12 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
456- ),
457- "end_datetime" : datetime_to_str (
458- datetime (2001 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC ),
459- ),
460- },
461- )
447+ item3 = Item (
448+ id = "test-item-2" ,
449+ geometry = ARBITRARY_GEOM ,
450+ bbox = [- 5 , - 20 , 5 , 0 ],
451+ datetime = None ,
452+ properties = {
453+ "start_datetime" : datetime_to_str (
454+ datetime (2000 , 12 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
455+ ),
456+ "end_datetime" : datetime_to_str (
457+ datetime (2001 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC ),
458+ ),
459+ },
460+ )
461+
462+ extent = Extent .from_items ([item1 , item2 , item3 ])
463+ assert len (extent .spatial .bboxes ) == 1
464+ assert extent .spatial .bboxes [0 ] == [- 10 , - 20 , 10 , 1 ]
465+ assert len (extent .temporal .intervals ) == 1
466+
467+ interval = extent .temporal .intervals [0 ]
468+ assert interval [0 ] == datetime (2000 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
469+ assert interval [1 ] == datetime (2001 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
470+
471+ def test_extent_to_from_dict () -> None :
472+ spatial_dict = {
473+ "bbox" : [
474+ [
475+ 172.91173669923782 ,
476+ 1.3438851951615003 ,
477+ 172.95469614953714 ,
478+ 1.3690476620161975 ,
479+ ]
480+ ],
481+ "extension:field" : "spatial value" ,
482+ }
483+ temporal_dict = {
484+ "interval" : [
485+ ["2020-12-11T22:38:32.125000Z" , "2020-12-14T18:02:31.437000Z" ]
486+ ],
487+ "extension:field" : "temporal value" ,
488+ }
489+ extent_dict = {
490+ "spatial" : spatial_dict ,
491+ "temporal" : temporal_dict ,
492+ "extension:field" : "extent value" ,
493+ }
494+ expected_extent_extra_fields = {
495+ "extension:field" : extent_dict ["extension:field" ],
496+ }
497+ expected_spatial_extra_fields = {
498+ "extension:field" : spatial_dict ["extension:field" ],
499+ }
500+ expected_temporal_extra_fields = {
501+ "extension:field" : temporal_dict ["extension:field" ],
502+ }
503+
504+ extent = Extent .from_dict (extent_dict )
505+
506+ assert expected_extent_extra_fields == extent .extra_fields
507+ assert expected_spatial_extra_fields == extent .spatial .extra_fields
508+ assert expected_temporal_extra_fields == extent .temporal .extra_fields
462509
463- extent = Extent .from_items ([item1 , item2 , item3 ])
464- assert len (extent .spatial .bboxes ) == 1
465- assert extent .spatial .bboxes [0 ] == [- 10 , - 20 , 10 , 1 ]
466- assert len (extent .temporal .intervals ) == 1
467-
468- interval = extent .temporal .intervals [0 ]
469- assert interval [0 ] == datetime (2000 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
470- assert interval [1 ] == datetime (2001 , 1 , 1 , 12 , 0 , 0 , 0 , tzinfo = tz .UTC )
471-
472- def test_extent_to_from_dict () -> None :
473- spatial_dict = {
474- "bbox" : [
475- [
476- 172.91173669923782 ,
477- 1.3438851951615003 ,
478- 172.95469614953714 ,
479- 1.3690476620161975 ,
480- ]
481- ],
482- "extension:field" : "spatial value" ,
483- }
484- temporal_dict = {
485- "interval" : [
486- ["2020-12-11T22:38:32.125000Z" , "2020-12-14T18:02:31.437000Z" ]
487- ],
488- "extension:field" : "temporal value" ,
489- }
490- extent_dict = {
491- "spatial" : spatial_dict ,
492- "temporal" : temporal_dict ,
493- "extension:field" : "extent value" ,
494- }
495- expected_extent_extra_fields = {
496- "extension:field" : extent_dict ["extension:field" ],
497- }
498- expected_spatial_extra_fields = {
499- "extension:field" : spatial_dict ["extension:field" ],
500- }
501- expected_temporal_extra_fields = {
502- "extension:field" : temporal_dict ["extension:field" ],
503- }
504-
505- extent = Extent .from_dict (extent_dict )
506-
507- assert expected_extent_extra_fields == extent .extra_fields
508- assert expected_spatial_extra_fields == extent .spatial .extra_fields
509- assert expected_temporal_extra_fields == extent .temporal .extra_fields
510-
511- assert extent_dict == extent .to_dict ()
510+ assert extent_dict == extent .to_dict ()
512511
513512
514513class CollectionSubClassTest (unittest .TestCase ):
0 commit comments