4
4
import os
5
5
import posixpath
6
6
import tempfile
7
- import unittest
8
7
from collections import defaultdict
9
8
from collections .abc import Iterator
10
9
from copy import deepcopy
46
45
)
47
46
48
47
49
- class CatalogTypeTest ( unittest . TestCase ) :
48
+ class TestCatalogType :
50
49
def test_determine_type_for_absolute_published (self ) -> None :
51
50
cat = TestCases .case_1 ()
52
51
with tempfile .TemporaryDirectory () as tmp_dir :
@@ -56,7 +55,7 @@ def test_determine_type_for_absolute_published(self) -> None:
56
55
)
57
56
58
57
catalog_type = CatalogType .determine_type (cat_json )
59
- self . assertEqual ( catalog_type , CatalogType .ABSOLUTE_PUBLISHED )
58
+ assert catalog_type == CatalogType .ABSOLUTE_PUBLISHED
60
59
61
60
def test_determine_type_for_relative_published (self ) -> None :
62
61
cat = TestCases .case_2 ()
@@ -67,14 +66,14 @@ def test_determine_type_for_relative_published(self) -> None:
67
66
)
68
67
69
68
catalog_type = CatalogType .determine_type (cat_json )
70
- self . assertEqual ( catalog_type , CatalogType .RELATIVE_PUBLISHED )
69
+ assert catalog_type == CatalogType .RELATIVE_PUBLISHED
71
70
72
71
def test_determine_type_for_self_contained (self ) -> None :
73
72
cat_json = pystac .StacIO .default ().read_json (
74
73
TestCases .get_path ("data-files/catalogs/test-case-1/catalog.json" )
75
74
)
76
75
catalog_type = CatalogType .determine_type (cat_json )
77
- self . assertEqual ( catalog_type , CatalogType .SELF_CONTAINED )
76
+ assert catalog_type == CatalogType .SELF_CONTAINED
78
77
79
78
def test_determine_type_for_unknown (self ) -> None :
80
79
catalog = Catalog (id = "test" , description = "test desc" )
@@ -83,7 +82,7 @@ def test_determine_type_for_unknown(self) -> None:
83
82
catalog .normalize_hrefs ("http://example.com" )
84
83
d = catalog .to_dict (include_self_link = False )
85
84
86
- self . assertIsNone ( CatalogType .determine_type (d ))
85
+ assert CatalogType .determine_type (d ) is None
87
86
88
87
89
88
class TestCatalog :
@@ -1423,7 +1422,7 @@ def test_to_dict_no_self_href(self) -> None:
1423
1422
Catalog .from_dict (d )
1424
1423
1425
1424
1426
- class FullCopyTest ( unittest . TestCase ) :
1425
+ class TestFullCopy :
1427
1426
def check_link (self , link : pystac .Link , tag : str ) -> None :
1428
1427
if link .is_resolved ():
1429
1428
target_href : str = cast (pystac .STACObject , link .target ).self_href
@@ -1438,7 +1437,7 @@ def check_item(self, item: Item, tag: str) -> None:
1438
1437
self .check_link (link , tag )
1439
1438
1440
1439
def check_catalog (self , c : Catalog , tag : str ) -> None :
1441
- self . assertEqual ( len (c .get_links ("root" )), 1 , msg = f" { c } ")
1440
+ assert len (c .get_links ("root" )) == 1 , f"Failure for catalog: { c } "
1442
1441
1443
1442
for link in c .links :
1444
1443
self .check_link (link , tag )
@@ -1540,7 +1539,7 @@ def test_full_copy_4(self) -> None:
1540
1539
assert os .path .exists (href )
1541
1540
1542
1541
1543
- class CatalogSubClassTest ( unittest . TestCase ) :
1542
+ class TestCatalogSubClass :
1544
1543
"""This tests cases related to creating classes inheriting from pystac.Catalog to
1545
1544
ensure that inheritance, class methods, etc. function as expected."""
1546
1545
@@ -1553,25 +1552,20 @@ def get_items(self) -> Iterator[Item]: # type: ignore
1553
1552
# backwards compatibility of inherited classes
1554
1553
return super ().get_items ()
1555
1554
1556
- def setUp (self ) -> None :
1557
- self .stac_io = pystac .StacIO .default ()
1558
-
1559
1555
def test_from_dict_returns_subclass (self ) -> None :
1556
+ self .stac_io = pystac .StacIO .default ()
1560
1557
catalog_dict = self .stac_io .read_json (self .case_1 )
1561
1558
custom_catalog = self .BasicCustomCatalog .from_dict (catalog_dict )
1562
-
1563
- self .assertIsInstance (custom_catalog , self .BasicCustomCatalog )
1559
+ assert isinstance (custom_catalog , self .BasicCustomCatalog )
1564
1560
1565
1561
def test_from_file_returns_subclass (self ) -> None :
1566
1562
custom_catalog = self .BasicCustomCatalog .from_file (self .case_1 )
1567
-
1568
- self .assertIsInstance (custom_catalog , self .BasicCustomCatalog )
1563
+ assert isinstance (custom_catalog , self .BasicCustomCatalog )
1569
1564
1570
1565
def test_clone (self ) -> None :
1571
1566
custom_catalog = self .BasicCustomCatalog .from_file (self .case_1 )
1572
1567
cloned_catalog = custom_catalog .clone ()
1573
-
1574
- self .assertIsInstance (cloned_catalog , self .BasicCustomCatalog )
1568
+ assert isinstance (cloned_catalog , self .BasicCustomCatalog )
1575
1569
1576
1570
def test_get_all_items_works (self ) -> None :
1577
1571
custom_catalog = self .BasicCustomCatalog .from_file (self .case_1 )
0 commit comments