Skip to content

Commit

Permalink
Add type annotations to tests
Browse files Browse the repository at this point in the history
Also, switch from tmpdir to tmp_path, as the former uses a deprecated
path library.
  • Loading branch information
eltoder committed Mar 20, 2024
1 parent 7fe47c9 commit 5abb5e4
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 191 deletions.
30 changes: 15 additions & 15 deletions tests/src/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ChildOfBadClass(BadInheritAndOverlap):


class _RestrictiveMeta(type):
def __setattr__(self, name, value) -> None:
def __setattr__(self, name: str, value: object) -> None:
raise TypeError("BOOM!")


Expand Down Expand Up @@ -83,13 +83,13 @@ class TestHasSlots:
"klass",
[type, dict, date, float, Decimal, Element, array],
)
def test_not_purepython(self, klass):
def test_not_purepython(self, klass: type) -> None:
assert has_slots(klass)

def test_typeddict(self):
def test_typeddict(self) -> None:
assert has_slots(MyDict)

def test_typing_extensions_typeddict(self):
def test_typing_extensions_typeddict(self) -> None:
assert has_slots(MyTypingExtensionsTypedDict)

@pytest.mark.parametrize(
Expand All @@ -106,7 +106,7 @@ def test_typing_extensions_typeddict(self):
FooMeta,
],
)
def test_slots(self, klass):
def test_slots(self, klass: type) -> None:
assert has_slots(klass)

@pytest.mark.parametrize(
Expand All @@ -120,10 +120,10 @@ def test_slots(self, klass):
KeyboardInterrupt,
],
)
def test_no_slots(self, klass):
def test_no_slots(self, klass: type) -> None:
assert not has_slots(klass)

def test_immutable_class(self):
def test_immutable_class(self) -> None:
assert not has_slots(_UnsettableClass)


Expand All @@ -132,7 +132,7 @@ class TestSlotsOverlap:
"klass",
[type, dict, date, float, Decimal, AssertionError, RuntimeError],
)
def test_not_purepython(self, klass):
def test_not_purepython(self, klass: type) -> None:
assert not slots_overlap(klass)

@pytest.mark.parametrize(
Expand All @@ -148,17 +148,17 @@ def test_not_purepython(self, klass):
ArrayInherit,
],
)
def test_slots_ok(self, klass):
def test_slots_ok(self, klass: type) -> None:
assert not slots_overlap(klass)

@pytest.mark.parametrize("klass", [BadOverlaps, BadInheritAndOverlap])
def test_slots_not_ok(self, klass):
def test_slots_not_ok(self, klass: type) -> None:
assert slots_overlap(klass)

@pytest.mark.parametrize(
"klass", [Random, Enum, NoSlotsInherits, ChildOfBadClass]
)
def test_no_slots(self, klass):
def test_no_slots(self, klass: type) -> None:
assert not slots_overlap(klass)


Expand All @@ -167,22 +167,22 @@ class TestHasSlotlessBase:
"klass",
[type, dict, date, float, Decimal],
)
def test_not_purepython(self, klass):
def test_not_purepython(self, klass: type) -> None:
assert not has_slotless_base(klass)

@pytest.mark.parametrize(
"klass", [Fraction, HasSlots, GoodInherit, BadOverlaps, OneStringSlot]
)
def test_slots_ok(self, klass):
def test_slots_ok(self, klass: type) -> None:
assert not has_slotless_base(klass)

@pytest.mark.parametrize(
"klass",
[BadInherit, BadInheritAndOverlap, AssertionError, RuntimeError],
)
def test_slots_not_ok(self, klass):
def test_slots_not_ok(self, klass: type) -> None:
assert has_slotless_base(klass)

@pytest.mark.parametrize("klass", [Enum, NoSlotsInherits, ChildOfBadClass])
def test_no_slots(self, klass):
def test_no_slots(self, klass: type) -> None:
assert not has_slotless_base(klass)
Loading

0 comments on commit 5abb5e4

Please sign in to comment.