Skip to content

Commit 8f2290b

Browse files
authored
993 progress: Convert test_catalog.py, test_layout.py and test_link.py to pytest (#1527)
* 993 convert CatalogTypeTest to pytest * 993 convert FullCopyTest to pytest * 993 finish converting test_catalog.py: by converting CatalogSubClassTest to pytest * 993 convert asserts to pytest in test_layout.py * 993 finish basic conversion of test_layout.py to pytest * 993 ruff's opinions on test_layout.py * 993 mypy found incorrect assertion revisions * 993 convert test_link.py to pytest * 993 won't pass ruff & mypy without these changes
1 parent b3dfa27 commit 8f2290b

File tree

3 files changed

+406
-434
lines changed

3 files changed

+406
-434
lines changed

tests/test_catalog.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
import posixpath
66
import tempfile
7-
import unittest
87
from collections import defaultdict
98
from collections.abc import Iterator
109
from copy import deepcopy
@@ -46,7 +45,7 @@
4645
)
4746

4847

49-
class CatalogTypeTest(unittest.TestCase):
48+
class TestCatalogType:
5049
def test_determine_type_for_absolute_published(self) -> None:
5150
cat = TestCases.case_1()
5251
with tempfile.TemporaryDirectory() as tmp_dir:
@@ -56,7 +55,7 @@ def test_determine_type_for_absolute_published(self) -> None:
5655
)
5756

5857
catalog_type = CatalogType.determine_type(cat_json)
59-
self.assertEqual(catalog_type, CatalogType.ABSOLUTE_PUBLISHED)
58+
assert catalog_type == CatalogType.ABSOLUTE_PUBLISHED
6059

6160
def test_determine_type_for_relative_published(self) -> None:
6261
cat = TestCases.case_2()
@@ -67,14 +66,14 @@ def test_determine_type_for_relative_published(self) -> None:
6766
)
6867

6968
catalog_type = CatalogType.determine_type(cat_json)
70-
self.assertEqual(catalog_type, CatalogType.RELATIVE_PUBLISHED)
69+
assert catalog_type == CatalogType.RELATIVE_PUBLISHED
7170

7271
def test_determine_type_for_self_contained(self) -> None:
7372
cat_json = pystac.StacIO.default().read_json(
7473
TestCases.get_path("data-files/catalogs/test-case-1/catalog.json")
7574
)
7675
catalog_type = CatalogType.determine_type(cat_json)
77-
self.assertEqual(catalog_type, CatalogType.SELF_CONTAINED)
76+
assert catalog_type == CatalogType.SELF_CONTAINED
7877

7978
def test_determine_type_for_unknown(self) -> None:
8079
catalog = Catalog(id="test", description="test desc")
@@ -83,7 +82,7 @@ def test_determine_type_for_unknown(self) -> None:
8382
catalog.normalize_hrefs("http://example.com")
8483
d = catalog.to_dict(include_self_link=False)
8584

86-
self.assertIsNone(CatalogType.determine_type(d))
85+
assert CatalogType.determine_type(d) is None
8786

8887

8988
class TestCatalog:
@@ -1423,7 +1422,7 @@ def test_to_dict_no_self_href(self) -> None:
14231422
Catalog.from_dict(d)
14241423

14251424

1426-
class FullCopyTest(unittest.TestCase):
1425+
class TestFullCopy:
14271426
def check_link(self, link: pystac.Link, tag: str) -> None:
14281427
if link.is_resolved():
14291428
target_href: str = cast(pystac.STACObject, link.target).self_href
@@ -1438,7 +1437,7 @@ def check_item(self, item: Item, tag: str) -> None:
14381437
self.check_link(link, tag)
14391438

14401439
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}"
14421441

14431442
for link in c.links:
14441443
self.check_link(link, tag)
@@ -1540,7 +1539,7 @@ def test_full_copy_4(self) -> None:
15401539
assert os.path.exists(href)
15411540

15421541

1543-
class CatalogSubClassTest(unittest.TestCase):
1542+
class TestCatalogSubClass:
15441543
"""This tests cases related to creating classes inheriting from pystac.Catalog to
15451544
ensure that inheritance, class methods, etc. function as expected."""
15461545

@@ -1553,25 +1552,20 @@ def get_items(self) -> Iterator[Item]: # type: ignore
15531552
# backwards compatibility of inherited classes
15541553
return super().get_items()
15551554

1556-
def setUp(self) -> None:
1557-
self.stac_io = pystac.StacIO.default()
1558-
15591555
def test_from_dict_returns_subclass(self) -> None:
1556+
self.stac_io = pystac.StacIO.default()
15601557
catalog_dict = self.stac_io.read_json(self.case_1)
15611558
custom_catalog = self.BasicCustomCatalog.from_dict(catalog_dict)
1562-
1563-
self.assertIsInstance(custom_catalog, self.BasicCustomCatalog)
1559+
assert isinstance(custom_catalog, self.BasicCustomCatalog)
15641560

15651561
def test_from_file_returns_subclass(self) -> None:
15661562
custom_catalog = self.BasicCustomCatalog.from_file(self.case_1)
1567-
1568-
self.assertIsInstance(custom_catalog, self.BasicCustomCatalog)
1563+
assert isinstance(custom_catalog, self.BasicCustomCatalog)
15691564

15701565
def test_clone(self) -> None:
15711566
custom_catalog = self.BasicCustomCatalog.from_file(self.case_1)
15721567
cloned_catalog = custom_catalog.clone()
1573-
1574-
self.assertIsInstance(cloned_catalog, self.BasicCustomCatalog)
1568+
assert isinstance(cloned_catalog, self.BasicCustomCatalog)
15751569

15761570
def test_get_all_items_works(self) -> None:
15771571
custom_catalog = self.BasicCustomCatalog.from_file(self.case_1)

0 commit comments

Comments
 (0)