You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classCustomMockMixin:
discord_id=itertools.count(0)
spec_set=Nonedef__init__(self, *args, **kwargs):
name=kwargs.pop('name', None) # `name` has special meaning for Mock classes, so we need to set it manually.super().__init__(*args, spec_set=self.spec_set, **kwargs)
ifname:
self.name=namedef_get_child_mock(self, *args, **kwargs):
"""This method by default returns an instance of the same class for any attribute or method of the class. This would cause MockBot, for instance, to return another instance of MockBot when using ``bot.get_guild``. This overwrites the original logic to return MagicMock objects by default, and CoroutineMocks for names defined in ``_spec_coroutines``"""_new_name=kwargs.get("_new_name")
if_new_nameinself.__dict__['_spec_coroutines']:
returnasynctest.CoroutineMock(*args, **kwargs)
_type=type(self)
ifissubclass(_type, asynctest.MagicMock) and_new_nameinasynctest.mock.async_magic_coroutines:
klass=asynctest.CoroutineMockelifissubclass(_type, asynctest.CoroutineMock):
klass=asynctest.MagicMockelifnotissubclass(_type, unittest.mock.CallableMixin):
# noinspection PyTypeHintsifissubclass(_type, unittest.mock.NonCallableMagicMock):
klass=asynctest.MagicMockelifissubclass(_type, asynctest.NonCallableMock):
klass=asynctest.Mockelse:
klass=asynctest.MagicMock# noinspection PyUnboundLocalVariablereturnklass(*args, **kwargs)
classHashableMixin(discord.mixins.EqualityComparable):
""" Mixin that provides similar hashing and equality functionality as discord.py's `Hashable` mixin. Note: discord.py`s `Hashable` mixin bit-shifts `self.id` (`>> 22`); to prevent hash-collisions for the relative small `id` integers we generally use in tests, this bit-shift is omitted. """def__hash__(self):
returnself.id
And this is the specific class I'm struggling with:
Needless to say, I'm over 100 test cases in with this, and I had already noticed that __str__ was not working as expected, but now I noticed that __hash__ isn't, and this affects my tests' equality checks.
If I call the methods explicitly stating the class, they work (even calling the parent's classes methods)
I have a series of Mock classes for my testing module, based on this:
https://github.com/python-discord/bot/blob/master/tests/helpers.py
But I'm using asynctest because I'm using Python 3.6
Base classes:
And this is the specific class I'm struggling with:
Needless to say, I'm over 100 test cases in with this, and I had already noticed that
__str__
was not working as expected, but now I noticed that__hash__
isn't, and this affects my tests' equality checks.If I call the methods explicitly stating the class, they work (even calling the parent's classes methods)
I'm not sure if this is part of my implementation or part of the library.
The text was updated successfully, but these errors were encountered: