Skip to content

Commit 41e40a4

Browse files
committed
993 convert Collection subclass tests to pytest
1 parent 5d8e0df commit 41e40a4

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

tests/test_collection.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def test_extent_to_from_dict() -> None:
510510
assert extent_dict == extent.to_dict()
511511

512512

513-
class CollectionSubClassTest(unittest.TestCase):
513+
class TestCollectionSubClass:
514514
"""This tests cases related to creating classes inheriting from pystac.Catalog to
515515
ensure that inheritance, class methods, etc. function as expected."""
516516

@@ -523,11 +523,9 @@ def get_items(self) -> Iterator[Item]: # type: ignore
523523
# backwards compatibility of inherited classes
524524
return super().get_items()
525525

526-
def setUp(self) -> None:
527-
self.stac_io = pystac.StacIO.default()
528-
529526
def test_from_dict_returns_subclass(self) -> None:
530-
collection_dict = self.stac_io.read_json(self.MULTI_EXTENT)
527+
stac_io = pystac.StacIO.default()
528+
collection_dict = stac_io.read_json(self.MULTI_EXTENT)
531529
custom_collection = self.BasicCustomCollection.from_dict(collection_dict)
532530

533531
assert isinstance(custom_collection, self.BasicCustomCollection)
@@ -553,22 +551,21 @@ def test_collection_get_item_works(self) -> None:
553551
collection.get_item("area-1-1-imagery")
554552

555553

556-
class CollectionPartialSubClassTest(unittest.TestCase):
554+
def test_collection_get_item_raises_type_error() -> None:
557555
class BasicCustomCollection(pystac.Collection):
558556
def get_items( # type: ignore
559557
self, *, recursive: bool = False
560558
) -> Iterator[Item]:
561559
# This get_items does not allow ids as args.
562560
return super().get_items(recursive=recursive)
563561

564-
def test_collection_get_item_raises_type_error(self) -> None:
565-
path = TestCases.get_path(
566-
"data-files/catalogs/test-case-1/country-1/area-1-1/collection.json"
567-
)
568-
custom_collection = self.BasicCustomCollection.from_file(path)
569-
collection = custom_collection.clone()
570-
with pytest.raises(TypeError, match="takes 1 positional argument"):
571-
collection.get_item("area-1-1-imagery")
562+
path = TestCases.get_path(
563+
"data-files/catalogs/test-case-1/country-1/area-1-1/collection.json"
564+
)
565+
custom_collection = BasicCustomCollection.from_file(path)
566+
collection = custom_collection.clone()
567+
with pytest.raises(TypeError, match="takes 1 positional argument"):
568+
collection.get_item("area-1-1-imagery")
572569

573570

574571
def test_custom_collection_from_dict(collection: Collection) -> None:

0 commit comments

Comments
 (0)