aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-01-29 17:09:43 -0800
committerGravatar MarkKoz <[email protected]>2020-02-12 10:07:55 -0800
commitbd5980728bd7bfd5bba53369934698c43f12fa05 (patch)
tree10605dffaf4d4a307545a9d142abedd8aebc3bd1
parentSync tests: use mock.patch for sync_guild (diff)
Sync tests: fix Syncer mocks not having async methods
While on 3.7, the CustomMockMixin needs to be leveraged so that coroutine members are replace with AsyncMocks instead.
-rw-r--r--tests/bot/cogs/sync/test_cog.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/bot/cogs/sync/test_cog.py b/tests/bot/cogs/sync/test_cog.py
index 118782db3..ec66c795d 100644
--- a/tests/bot/cogs/sync/test_cog.py
+++ b/tests/bot/cogs/sync/test_cog.py
@@ -2,9 +2,21 @@ import unittest
from unittest import mock
from bot.cogs import sync
+from bot.cogs.sync.syncers import Syncer
from tests import helpers
+class MockSyncer(helpers.CustomMockMixin, mock.MagicMock):
+ """
+ A MagicMock subclass to mock Syncer objects.
+
+ Instances of this class will follow the specifications of `bot.cogs.sync.syncers.Syncer`
+ instances. For more information, see the `MockGuild` docstring.
+ """
+ def __init__(self, **kwargs) -> None:
+ super().__init__(spec_set=Syncer, **kwargs)
+
+
class SyncExtensionTests(unittest.TestCase):
"""Tests for the sync extension."""
@@ -22,8 +34,17 @@ class SyncCogTests(unittest.TestCase):
def setUp(self):
self.bot = helpers.MockBot()
- self.role_syncer_patcher = mock.patch("bot.cogs.sync.syncers.RoleSyncer", autospec=True)
- self.user_syncer_patcher = mock.patch("bot.cogs.sync.syncers.UserSyncer", autospec=True)
+ # These patch the type. When the type is called, a MockSyncer instanced is returned.
+ # MockSyncer is needed so that our custom AsyncMock is used.
+ # TODO: Use autospec instead in 3.8, which will automatically use AsyncMock when needed.
+ self.role_syncer_patcher = mock.patch(
+ "bot.cogs.sync.syncers.RoleSyncer",
+ new=mock.MagicMock(return_value=MockSyncer())
+ )
+ self.user_syncer_patcher = mock.patch(
+ "bot.cogs.sync.syncers.UserSyncer",
+ new=mock.MagicMock(return_value=MockSyncer())
+ )
self.RoleSyncer = self.role_syncer_patcher.start()
self.UserSyncer = self.user_syncer_patcher.start()