Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong TypeError at instantiating MockAbstractEnum #332

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions tests/utils/test_abc_enum_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,24 @@ def test_inheritance(self) -> None:
def test_mock_abstract_enum_is_abstract(self) -> None:
"""Test case for MockAbstractEnum class to check if it's an abstract class."""
assert MockAbstractEnum.__abstractmethods__ == frozenset({"test_method"})
with pytest.raises(TypeError):
_ = MockAbstractEnum("a") # type: ignore[abstract]

def test_abstract_enum_with_memebers_raises_type_error(self) -> None:
"""Test case for MockAbstractEnumWithMembers class to check if it raises a TypeError."""
with pytest.raises(TypeError) as error_info:

class MockAbstractEnumWithMembers(Enum, metaclass=ABCEnumMeta):
"""Mock class with members for testing the ABCEnumMeta class."""

A = "a"

@abstractmethod
def test_method(self) -> int:
"""Test method for the MockAbstractEnum class."""

assert (
str(error_info.value)
== "Can't instantiate abstract class 'MockAbstractEnumWithMembers' without an implementation for abstract method 'test_method'"
)

def test_mock_concrete_enum(self) -> None:
"""Test case for MockConcreteEnum class."""
Expand All @@ -57,7 +73,10 @@ class InvalidMockConcreteEnum(MockAbstractEnum):
A = "a"
B = "b"

assert str(error_info.value).endswith("without an implementation for abstract method 'test_method'")
assert (
str(error_info.value)
== "Can't instantiate abstract class 'InvalidMockConcreteEnum' without an implementation for abstract method 'test_method'"
)

def test_abc_enum_meta_attribute_error(self) -> None:
"""Test instantiation of class with ABCEnumMeta where no abstract methods attribute is present."""
Expand Down