Skip to content

Commit 25274c0

Browse files
Copilotjb3
andcommitted
Fix remaining DumpError issues in all test files
Co-authored-by: jb3 <20439493+jb3@users.noreply.github.com>
1 parent 99cc6d7 commit 25274c0

7 files changed

Lines changed: 46 additions & 46 deletions

File tree

tests/bot/exts/backend/sync/test_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ async def test_sync_message_edited(self):
3939
(helpers.MockMessage(), ResponseCodeError(mock.MagicMock()), True),
4040
)
4141

42-
for message, side_effect, should_edit in subtests:
43-
with self.subTest(message=message, side_effect=side_effect, should_edit=should_edit):
42+
for i, (message, side_effect, should_edit) in enumerate(subtests):
43+
with self.subTest(test_case=i, has_message=message is not None, should_edit=should_edit):
4444
TestSyncer._sync.side_effect = side_effect
4545
ctx = helpers.MockContext()
4646
ctx.send.return_value = message
@@ -58,8 +58,8 @@ async def test_sync_message_sent(self):
5858
(helpers.MockContext(), helpers.MockMessage()),
5959
)
6060

61-
for ctx, message in subtests:
62-
with self.subTest(ctx=ctx, message=message):
61+
for i, (ctx, message) in enumerate(subtests):
62+
with self.subTest(test_case=i, has_ctx=ctx is not None):
6363
await TestSyncer.sync(self.guild, ctx)
6464

6565
if ctx is not None:

tests/bot/exts/backend/sync/test_cog.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class SyncCogTests(SyncCogTestCase):
6565
@unittest.mock.patch("bot.exts.backend.sync._cog.create_task", new_callable=unittest.mock.MagicMock)
6666
async def test_sync_cog_sync_on_load(self, mock_create_task: unittest.mock.MagicMock):
6767
"""Sync function should be synced on cog load only if guild is found."""
68-
for guild in (helpers.MockGuild(), None):
69-
with self.subTest(guild=guild):
68+
for i, guild in enumerate((helpers.MockGuild(), None)):
69+
with self.subTest(test_case=i, has_guild=guild is not None):
7070
mock_create_task.reset_mock()
7171
self.bot.reset_mock()
7272
self.RoleSyncer.reset_mock()
@@ -126,8 +126,8 @@ async def patch_user_helper(self, side_effect: BaseException) -> None:
126126

127127
async def test_sync_cog_patch_user(self):
128128
"""A PATCH request should be sent and 404 errors ignored."""
129-
for side_effect in (None, self.response_error(404)):
130-
with self.subTest(side_effect=side_effect):
129+
for i, side_effect in enumerate((None, self.response_error(404))):
130+
with self.subTest(test_case=i, has_error=side_effect is not None):
131131
await self.patch_user_helper(side_effect)
132132

133133
async def test_sync_cog_patch_user_non_404(self):
@@ -207,7 +207,7 @@ async def test_sync_cog_on_guild_role_update(self):
207207

208208
for should_put, attributes in subtests:
209209
for attribute in attributes:
210-
with self.subTest(should_put=should_put, changed_attribute=attribute):
210+
with self.subTest(should_put=should_put, attribute=attribute):
211211
self.bot.api_client.put.reset_mock()
212212

213213
after_role_data = role_data.copy()
@@ -372,8 +372,8 @@ async def on_member_join_helper(self, side_effect: Exception) -> dict:
372372

373373
async def test_sync_cog_on_member_join(self):
374374
"""Should PUT user's data or POST it if the user doesn't exist."""
375-
for side_effect in (None, self.response_error(404)):
376-
with self.subTest(side_effect=side_effect):
375+
for i, side_effect in enumerate((None, self.response_error(404))):
376+
with self.subTest(test_case=i, has_error=side_effect is not None):
377377
self.bot.api_client.post.reset_mock()
378378
data = await self.on_member_join_helper(side_effect)
379379

@@ -422,6 +422,6 @@ async def test_commands_require_admin(self):
422422
self.cog.sync_users_command,
423423
)
424424

425-
for cmd in cmds:
426-
with self.subTest(cmd=cmd):
425+
for i, cmd in enumerate(cmds):
426+
with self.subTest(test_case=i):
427427
await self.assertHasPermissionsCheck(cmd, {"administrator": True})

tests/bot/exts/filtering/test_settings_entries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def test_filtering_dms_when_necessary(self):
144144
(False, MockTextChannel(), True)
145145
)
146146

147-
for apply_in_dms, channel, expected in cases:
148-
with self.subTest(apply_in_dms=apply_in_dms, channel=channel):
147+
for i, (apply_in_dms, channel, expected) in enumerate(cases):
148+
with self.subTest(test_case=i, apply_in_dms=apply_in_dms):
149149
filter_dms = FilterDM(filter_dm=apply_in_dms)
150150
self.ctx.channel = channel
151151

tests/bot/exts/info/test_information.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@ async def test_user_command_helper_method_get_requests(self):
122122
},
123123
)
124124

125-
for test_value in test_values:
125+
for i, test_value in enumerate(test_values):
126126
helper_method = test_value["helper_method"]
127127
endpoint, params = test_value["expected_args"]
128128

129-
with self.subTest(method=helper_method, endpoint=endpoint, params=params):
129+
with self.subTest(test_case=i, endpoint=endpoint):
130130
await helper_method(self.member)
131131
self.bot.api_client.get.assert_called_once_with(endpoint, params=params)
132132
self.bot.api_client.get.reset_mock()
133133

134134
async def _method_subtests(self, method, test_values, default_header):
135135
"""Helper method that runs the subtests for the different helper methods."""
136-
for test_value in test_values:
136+
for i, test_value in enumerate(test_values):
137137
api_response = test_value["api response"]
138138
expected_lines = test_value["expected_lines"]
139139

140-
with self.subTest(method=method, api_response=api_response, expected_lines=expected_lines):
140+
with self.subTest(test_case=i):
141141
self.bot.api_client.get.return_value = api_response
142142

143143
expected_output = "\n".join(expected_lines)

tests/bot/exts/moderation/infraction/test_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ async def test_send_infraction_embed(self, send_private_embed_mock):
235235
}
236236
]
237237

238-
for case in test_cases:
239-
with self.subTest(args=case["args"], expected=case["expected_output"], send=case["send_result"]):
238+
for i, case in enumerate(test_cases):
239+
with self.subTest(test_case=i, send=case["send_result"]):
240240
send_private_embed_mock.reset_mock()
241241

242242
send_private_embed_mock.return_value = case["send_result"]
@@ -259,7 +259,7 @@ async def test_notify_pardon(self, send_private_embed_mock):
259259
test_case((self.user, "Test title", "Example content", Icons.user_update), Icons.user_update, False)
260260
]
261261

262-
for case in test_cases:
262+
for i, case in enumerate(test_cases):
263263
expected = Embed(
264264
description="Example content",
265265
colour=Colours.soft_green
@@ -268,7 +268,7 @@ async def test_notify_pardon(self, send_private_embed_mock):
268268
icon_url=case.icon
269269
)
270270

271-
with self.subTest(args=case.args, expected=expected):
271+
with self.subTest(test_case=i):
272272
send_private_embed_mock.reset_mock()
273273

274274
send_private_embed_mock.return_value = case.send_result
@@ -288,13 +288,13 @@ async def test_send_private_embed(self):
288288
test_case = namedtuple("test_case", ["expected_output", "raised_exception"])
289289
test_cases = [
290290
test_case(True, None),
291-
test_case(False, HTTPException(AsyncMock(), AsyncMock())),
292-
test_case(False, Forbidden(AsyncMock(), AsyncMock())),
293-
test_case(False, NotFound(AsyncMock(), AsyncMock()))
291+
test_case(False, HTTPException(AsyncMock(), "test error")),
292+
test_case(False, Forbidden(AsyncMock(), "test error")),
293+
test_case(False, NotFound(AsyncMock(), "test error"))
294294
]
295295

296-
for case in test_cases:
297-
with self.subTest(expected=case.expected_output, raised=case.raised_exception):
296+
for i, case in enumerate(test_cases):
297+
with self.subTest(test_case=i, expected=case.expected_output):
298298
self.user.send.reset_mock(side_effect=True)
299299
self.user.send.side_effect = case.raised_exception
300300

tests/bot/exts/moderation/test_silence.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ async def test_command(self, parser_mock):
260260
ctx = MockContext()
261261
parser_mock.return_value = (ctx.channel, 10)
262262

263-
for case in test_cases:
264-
with self.subTest("Test command converters", args=case):
263+
for i, case in enumerate(test_cases):
264+
with self.subTest(msg="Test command converters", test_case=i):
265265
await cog.silence.callback(cog, ctx, *case)
266266

267267
try:
@@ -433,10 +433,10 @@ async def test_sent_correct_message(self):
433433

434434
targets = (MockTextChannel(), MockVoiceChannel(), None)
435435

436-
for (duration, message, was_silenced), target in itertools.product(test_cases, targets):
436+
for i, ((duration, message, was_silenced), target) in enumerate(itertools.product(test_cases, targets)):
437437
with (
438438
mock.patch.object(self.cog, "_set_silence_overwrites", return_value=was_silenced),
439-
self.subTest(was_silenced=was_silenced, target=target, message=message),
439+
self.subTest(test_case=i, was_silenced=was_silenced, has_target=target is not None),
440440
mock.patch.object(self.cog, "send_message") as send_message
441441
):
442442
ctx = MockContext()
@@ -525,8 +525,8 @@ async def test_skipped_already_silenced(self):
525525
(True, MockVoiceChannel(), PermissionOverwrite(connect=False, speak=False)),
526526
)
527527

528-
for contains, channel, overwrite in subtests:
529-
with self.subTest(contains=contains, is_text=isinstance(channel, MockTextChannel), overwrite=overwrite):
528+
for i, (contains, channel, overwrite) in enumerate(subtests):
529+
with self.subTest(test_case=i, contains=contains, is_text=isinstance(channel, MockTextChannel)):
530530
self.cog.scheduler.__contains__.return_value = contains
531531
channel.overwrites_for.return_value = overwrite
532532

@@ -702,7 +702,7 @@ async def test_sent_correct_message(self):
702702

703703
targets = (None, MockTextChannel())
704704

705-
for (was_unsilenced, message, overwrite), target in itertools.product(test_cases, targets):
705+
for i, ((was_unsilenced, message, overwrite), target) in enumerate(itertools.product(test_cases, targets)):
706706
ctx = MockContext()
707707
ctx.channel.overwrites_for.return_value = overwrite
708708
if target:
@@ -711,7 +711,7 @@ async def test_sent_correct_message(self):
711711
with (
712712
mock.patch.object(self.cog, "_unsilence", return_value=was_unsilenced),
713713
mock.patch.object(self.cog, "send_message") as send_message,
714-
self.subTest(was_unsilenced=was_unsilenced, overwrite=overwrite, target=target),
714+
self.subTest(test_case=i, was_unsilenced=was_unsilenced, has_target=target is not None),
715715
):
716716
await self.cog.unsilence.callback(self.cog, ctx, channel=target)
717717

@@ -722,8 +722,8 @@ async def test_skipped_already_unsilenced(self):
722722
"""Permissions were not set and `False` was returned for an already unsilenced channel."""
723723
self.cog.scheduler.__contains__.return_value = False
724724

725-
for channel in (MockVoiceChannel(), MockTextChannel()):
726-
with self.subTest(channel=channel):
725+
for i, channel in enumerate((MockVoiceChannel(), MockTextChannel())):
726+
with self.subTest(test_case=i):
727727
self.assertFalse(await self.cog._unsilence(channel))
728728
channel.set_permissions.assert_not_called()
729729

@@ -811,8 +811,8 @@ async def test_cancelled_task(self):
811811

812812
async def test_preserved_other_overwrites_text(self):
813813
"""Text channel's other unrelated overwrites were not changed, including cache misses."""
814-
for overwrite_json in ('{"send_messages": true, "add_reactions": null}', None):
815-
with self.subTest(overwrite_json=overwrite_json):
814+
for i, overwrite_json in enumerate(('{"send_messages": true, "add_reactions": null}', None)):
815+
with self.subTest(test_case=i, has_overwrite=overwrite_json is not None):
816816
if overwrite_json is None:
817817
await self.cog.previous_overwrites.delete(self.text_channel.id)
818818
else:
@@ -832,8 +832,8 @@ async def test_preserved_other_overwrites_text(self):
832832

833833
async def test_preserved_other_overwrites_voice(self):
834834
"""Voice channel's other unrelated overwrites were not changed, including cache misses."""
835-
for overwrite_json in ('{"connect": true, "speak": true}', None):
836-
with self.subTest(overwrite_json=overwrite_json):
835+
for i, overwrite_json in enumerate(('{"connect": true, "speak": true}', None)):
836+
with self.subTest(test_case=i, has_overwrite=overwrite_json is not None):
837837
if overwrite_json is None:
838838
await self.cog.previous_overwrites.delete(self.voice_channel.id)
839839
else:
@@ -858,8 +858,8 @@ async def test_unsilence_role(self):
858858
(MockVoiceChannel(), self.cog.bot.get_guild(Guild.id).get_role(Roles.voice_verified))
859859
)
860860

861-
for channel, role in test_cases:
862-
with self.subTest(channel=channel, role=role):
861+
for i, (channel, role) in enumerate(test_cases):
862+
with self.subTest(test_case=i):
863863
await self.cog._unsilence_wrapper(channel, MockContext())
864864
channel.overwrites_for.assert_called_with(role)
865865

tests/bot/exts/recruitment/talentpool/test_review.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ async def test_is_ready_for_review(self):
141141
([], None, True),
142142
)
143143

144-
for messages, last_review_timestamp, expected in cases:
145-
with self.subTest(messages=messages, expected=expected):
144+
for i, (messages, last_review_timestamp, expected) in enumerate(cases):
145+
with self.subTest(test_case=i, expected=expected):
146146
self.voting_channel.history = AsyncIterator(messages)
147147

148148
cache_get_mock = AsyncMock(return_value=last_review_timestamp)

0 commit comments

Comments
 (0)