aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-10-30 22:54:27 +0100
committerGravatar Sebastiaan Zeeff <[email protected]>2019-10-30 22:54:27 +0100
commit586ae18842de0dd92e93945c63ed5e6cd158c1f7 (patch)
tree97976780852d0acfc94c4e4cc7824881b1743558 /tests
parentEnhance custom mock helpers (diff)
Update docstring and remove redundant attribute
I accidentally forgot to update the docstring of `CustomMockMixin`, which changed quite dramatically in scope with the last commit. This commit remedies that. In addition, I inadvertently forgot to remove the `child_mock_type` class attribute from `MockRole`. Since it uses the default value, it is no longer necessary to specify it in the child class as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 673beae3f..8496ba031 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -50,7 +50,15 @@ class ColourMixin:
class CustomMockMixin:
- """Ensures attributes of our mock types will be instantiated with the correct mock type."""
+ """
+ Provides common functionality for our custom Mock types.
+
+ The cooperative `__init__` automatically creates `AsyncMock` attributes for every coroutine
+ function `inspect` detects in the `spec` instance we provide. In addition, this mixin takes care
+ of making sure child mocks are instantiated with the correct class. By default, the mock of the
+ children will be `unittest.mock.MagicMock`, but this can be overwritten by setting the attribute
+ `child_mock_type` on the custom mock inheriting from this mixin.
+ """
child_mock_type = unittest.mock.MagicMock
@@ -179,9 +187,6 @@ class MockRole(CustomMockMixin, unittest.mock.Mock, ColourMixin, HashableMixin):
Instances of this class will follow the specifications of `discord.Role` instances. For more
information, see the `MockGuild` docstring.
"""
-
- child_mock_type = unittest.mock.MagicMock
-
def __init__(self, name: str = "role", role_id: int = 1, position: int = 1, **kwargs) -> None:
super().__init__(spec=role_instance, **kwargs)