11import posixpath
2- import unittest
32from collections .abc import Callable
43from datetime import datetime , timedelta
54
2322)
2423
2524
26- class LayoutTemplateTest ( unittest . TestCase ) :
25+ class TestLayoutTemplate :
2726 def test_templates_item_datetime (self ) -> None :
2827 year = 2020
2928 month = 11
@@ -191,7 +190,7 @@ def test_docstring_examples(self) -> None:
191190 assert path3 == "landsat-8-l1/CC-BY-3.0"
192191
193192
194- class CustomLayoutStrategyTest ( unittest . TestCase ) :
193+ class TestCustomLayoutStrategy :
195194 def get_custom_catalog_func (self ) -> Callable [[pystac .Catalog , str , bool ], str ]:
196195 def fn (cat : pystac .Catalog , parent_dir : str , is_root : bool ) -> str :
197196 return posixpath .join (parent_dir , f"cat/{ is_root } /{ cat .id } .json" )
@@ -271,7 +270,7 @@ def test_produces_fallback_layout_for_item(self) -> None:
271270 assert href == expected
272271
273272
274- class TemplateLayoutStrategyTest ( unittest . TestCase ) :
273+ class TestTemplateLayoutStrategy :
275274 TEST_CATALOG_TEMPLATE = "cat/${id}/${description}"
276275 TEST_COLLECTION_TEMPLATE = "col/${id}/${license}"
277276 TEST_ITEM_TEMPLATE = "item/${collection}/${id}.json"
@@ -375,149 +374,164 @@ def test_produces_fallback_layout_for_item(self) -> None:
375374 assert href == expected
376375
377376
378- class BestPracticesLayoutStrategyTest (unittest .TestCase ):
379- def setUp (self ) -> None :
380- self .strategy = BestPracticesLayoutStrategy ()
381-
377+ class TestBestPracticesLayoutStrategy :
382378 def test_produces_layout_for_root_catalog (self ) -> None :
379+ strategy = BestPracticesLayoutStrategy ()
383380 cat = pystac .Catalog (id = "test" , description = "test desc" )
384- href = self . strategy .get_href (
381+ href = strategy .get_href (
385382 cat , parent_dir = "http://example.com" , is_root = True
386383 )
387384 assert href == "http://example.com/catalog.json"
388385
389386 def test_produces_layout_for_child_catalog (self ) -> None :
387+ strategy = BestPracticesLayoutStrategy ()
390388 cat = pystac .Catalog (id = "test" , description = "test desc" )
391- href = self . strategy .get_href (cat , parent_dir = "http://example.com" )
389+ href = strategy .get_href (cat , parent_dir = "http://example.com" )
392390 assert href == "http://example.com/test/catalog.json"
393391
394392 def test_produces_layout_for_root_collection (self ) -> None :
393+ strategy = BestPracticesLayoutStrategy ()
395394 collection = TestCases .case_8 ()
396- href = self . strategy .get_href (
395+ href = strategy .get_href (
397396 collection , parent_dir = "http://example.com" , is_root = True
398397 )
399398 assert href == "http://example.com/collection.json"
400399
401400 def test_produces_layout_for_child_collection (self ) -> None :
401+ strategy = BestPracticesLayoutStrategy ()
402402 collection = TestCases .case_8 ()
403- href = self . strategy .get_href (collection , parent_dir = "http://example.com" )
403+ href = strategy .get_href (collection , parent_dir = "http://example.com" )
404404 assert href == f"http://example.com/{ collection .id } /collection.json"
405405
406406 def test_produces_layout_for_item (self ) -> None :
407+ strategy = BestPracticesLayoutStrategy ()
407408 collection = TestCases .case_8 ()
408409 item = next (collection .get_items (recursive = True ))
409- href = self . strategy .get_href (item , parent_dir = "http://example.com" )
410+ href = strategy .get_href (item , parent_dir = "http://example.com" )
410411 expected = f"http://example.com/{ item .id } /{ item .id } .json"
411412 assert href == expected
412413
413414
414- class AsIsLayoutStrategyTest ( unittest . TestCase ) :
415- def setUp (self ) -> None :
416- self . strategy = AsIsLayoutStrategy ()
417- self . expected_local_href = (
415+ class TestAsIsLayoutStrategy :
416+ def test_catalog (self ) -> None :
417+ strategy = AsIsLayoutStrategy ()
418+ expected_local_href = (
418419 "/an/href" if not path_includes_drive_letter () else "D:/an/href"
419420 )
420-
421- def test_catalog (self ) -> None :
422421 cat = pystac .Catalog (id = "test" , description = "test desc" )
423422 with pytest .raises (ValueError ):
424- self . strategy .get_href (cat , parent_dir = "http://example.com" , is_root = True )
423+ strategy .get_href (cat , parent_dir = "http://example.com" , is_root = True )
425424 cat .set_self_href ("/an/href" )
426- href = self . strategy .get_href (
425+ href = strategy .get_href (
427426 cat , parent_dir = "https://example.com" , is_root = True
428427 )
429- assert href == self . expected_local_href
428+ assert href == expected_local_href
430429
431430 def test_collection (self ) -> None :
431+ strategy = AsIsLayoutStrategy ()
432+ expected_local_href = (
433+ "/an/href" if not path_includes_drive_letter () else "D:/an/href"
434+ )
432435 collection = TestCases .case_8 ()
433436 collection .set_self_href (None )
434437 with pytest .raises (ValueError ):
435- self . strategy .get_href (
438+ strategy .get_href (
436439 collection , parent_dir = "http://example.com" , is_root = True
437440 )
438441 collection .set_self_href ("/an/href" )
439- href = self . strategy .get_href (
442+ href = strategy .get_href (
440443 collection , parent_dir = "https://example.com" , is_root = True
441444 )
442- assert href == self . expected_local_href
445+ assert href == expected_local_href
443446
444447 def test_item (self ) -> None :
448+ strategy = AsIsLayoutStrategy ()
449+ expected_local_href = (
450+ "/an/href" if not path_includes_drive_letter () else "D:/an/href"
451+ )
445452 collection = TestCases .case_8 ()
446453 item = next (collection .get_items (recursive = True ))
447454 item .set_self_href (None )
448455 with pytest .raises (ValueError ):
449- self . strategy .get_href (item , parent_dir = "http://example.com" )
456+ strategy .get_href (item , parent_dir = "http://example.com" )
450457 item .set_self_href ("/an/href" )
451- href = self .strategy .get_href (item , parent_dir = "http://example.com" )
452- assert href == self .expected_local_href
453-
458+ href = strategy .get_href (item , parent_dir = "http://example.com" )
459+ assert href == expected_local_href
454460
455- class APILayoutStrategyTest (unittest .TestCase ):
456- def setUp (self ) -> None :
457- self .strategy = APILayoutStrategy ()
458461
462+ class TestAPILayoutStrategy :
459463 def test_produces_layout_for_root_catalog (self ) -> None :
464+ strategy = APILayoutStrategy ()
460465 cat = pystac .Catalog (id = "test" , description = "test desc" )
461- href = self . strategy .get_href (
466+ href = strategy .get_href (
462467 cat , parent_dir = "http://example.com" , is_root = True
463468 )
464469 assert href == "http://example.com"
465470
466471 def test_produces_layout_for_root_catalog_str (self ) -> None :
472+ strategy = APILayoutStrategy ()
467473 cat = pystac .Catalog (id = "test" , description = "test desc" )
468- href = self . strategy .get_catalog_href (
474+ href = strategy .get_catalog_href (
469475 cat .id , parent_dir = "http://example.com" , is_root = True
470476 )
471477 assert href == "http://example.com"
472478
473479 def test_produces_layout_for_child_catalog (self ) -> None :
480+ strategy = APILayoutStrategy ()
474481 cat = pystac .Catalog (id = "test" , description = "test desc" )
475- href = self . strategy .get_href (cat , parent_dir = "http://example.com" )
482+ href = strategy .get_href (cat , parent_dir = "http://example.com" )
476483 assert href == "http://example.com/test"
477484
478485 def test_produces_layout_for_child_catalog_str (self ) -> None :
486+ strategy = APILayoutStrategy ()
479487 cat = pystac .Catalog (id = "test" , description = "test desc" )
480- href = self . strategy .get_catalog_href (
488+ href = strategy .get_catalog_href (
481489 cat .id , parent_dir = "http://example.com" , is_root = False
482490 )
483491 assert href == "http://example.com/test"
484492
485493 def test_cannot_produce_layout_for_root_collection (self ) -> None :
494+ strategy = APILayoutStrategy ()
486495 collection = TestCases .case_8 ()
487496 with pytest .raises (ValueError ):
488- self . strategy .get_href (
497+ strategy .get_href (
489498 collection , parent_dir = "http://example.com" , is_root = True
490499 )
491500
492501 def test_produces_layout_for_child_collection (self ) -> None :
502+ strategy = APILayoutStrategy ()
493503 collection = TestCases .case_8 ()
494- href = self . strategy .get_href (collection , parent_dir = "http://example.com" )
504+ href = strategy .get_href (collection , parent_dir = "http://example.com" )
495505 assert href == f"http://example.com/collections/{ collection .id } "
496506
497507 def test_produces_layout_for_child_collection_str (self ) -> None :
508+ strategy = APILayoutStrategy ()
498509 collection = TestCases .case_8 ()
499- href = self . strategy .get_collection_href (
510+ href = strategy .get_collection_href (
500511 collection .id , parent_dir = "http://example.com" , is_root = False
501512 )
502513 assert href == f"http://example.com/collections/{ collection .id } "
503514
504515 def test_produces_layout_for_item (self ) -> None :
516+ strategy = APILayoutStrategy ()
505517 collection = TestCases .case_8 ()
506- col_href = self . strategy .get_href (collection , parent_dir = "http://example.com" )
518+ col_href = strategy .get_href (collection , parent_dir = "http://example.com" )
507519 item = next (collection .get_items (recursive = True ))
508- href = self . strategy .get_href (item , parent_dir = col_href )
520+ href = strategy .get_href (item , parent_dir = col_href )
509521 expected = f"http://example.com/collections/{ collection .id } /items/{ item .id } "
510522 assert href == expected
511523
512524 def test_produces_layout_for_item_str (self ) -> None :
525+ strategy = APILayoutStrategy ()
513526 collection = TestCases .case_8 ()
514- col_href = self . strategy .get_href (collection , parent_dir = "http://example.com" )
527+ col_href = strategy .get_href (collection , parent_dir = "http://example.com" )
515528 item = next (collection .get_items (recursive = True ))
516- href = self . strategy .get_item_href (item .id , parent_dir = col_href )
529+ href = strategy .get_item_href (item .id , parent_dir = col_href )
517530 expected = f"http://example.com/collections/{ collection .id } /items/{ item .id } "
518531 assert href == expected
519532
520533 def test_produces_normalized_layout (self ) -> None :
534+ strategy = APILayoutStrategy ()
521535 cat = pystac .Catalog (id = "test_catalog" , description = "Test Catalog" )
522536 col = pystac .Collection (
523537 id = "test_collection" ,
@@ -556,7 +570,7 @@ def test_produces_normalized_layout(self) -> None:
556570 )
557571 cat .add_child (col )
558572 col .add_item (item )
559- cat .normalize_hrefs ("http://example.com" , strategy = self . strategy )
573+ cat .normalize_hrefs ("http://example.com" , strategy = strategy )
560574
561575 assert cat .self_href == "http://example.com"
562576 assert col .self_href == "http://example.com/collections/test_collection"
@@ -566,17 +580,21 @@ def test_produces_normalized_layout(self) -> None:
566580 )
567581
568582 def test_produces_layout_for_search (self ) -> None :
569- href = self .strategy .get_search_href (parent_dir = "http://example.com" )
583+ strategy = APILayoutStrategy ()
584+ href = strategy .get_search_href (parent_dir = "http://example.com" )
570585 assert href == "http://example.com/search"
571586
572587 def test_produces_layout_for_conformance (self ) -> None :
573- href = self .strategy .get_conformance_href (parent_dir = "http://example.com" )
588+ strategy = APILayoutStrategy ()
589+ href = strategy .get_conformance_href (parent_dir = "http://example.com" )
574590 assert href == "http://example.com/conformance"
575591
576592 def test_produces_layout_for_service_description (self ) -> None :
577- href = self .strategy .get_service_desc_href (parent_dir = "http://example.com" )
593+ strategy = APILayoutStrategy ()
594+ href = strategy .get_service_desc_href (parent_dir = "http://example.com" )
578595 assert href == "http://example.com/api"
579596
580597 def test_produces_layout_for_service_doc (self ) -> None :
581- href = self .strategy .get_service_doc_href (parent_dir = "http://example.com" )
598+ strategy = APILayoutStrategy ()
599+ href = strategy .get_service_doc_href (parent_dir = "http://example.com" )
582600 assert href == "http://example.com/api.html"
0 commit comments