diff options
| -rw-r--r-- | tests/bot/exts/backend/sync/test_base.py | 8 | ||||
| -rw-r--r-- | tests/bot/exts/backend/sync/test_cog.py | 18 | ||||
| -rw-r--r-- | tests/bot/exts/backend/test_error_handler.py | 45 | ||||
| -rw-r--r-- | tests/bot/exts/filtering/test_settings_entries.py | 4 | ||||
| -rw-r--r-- | tests/bot/exts/info/test_information.py | 8 | ||||
| -rw-r--r-- | tests/bot/exts/moderation/infraction/test_utils.py | 22 | ||||
| -rw-r--r-- | tests/bot/exts/moderation/test_silence.py | 32 | ||||
| -rw-r--r-- | tests/bot/exts/recruitment/talentpool/test_review.py | 4 | ||||
| -rw-r--r-- | tests/bot/test_converters.py | 4 | ||||
| -rw-r--r-- | tests/bot/utils/test_message_cache.py | 8 | ||||
| -rw-r--r-- | tests/bot/utils/test_time.py | 24 | ||||
| -rw-r--r-- | tests/test_helpers.py | 28 |
12 files changed, 111 insertions, 94 deletions
diff --git a/tests/bot/exts/backend/sync/test_base.py b/tests/bot/exts/backend/sync/test_base.py index 4dacfda17..a98b6251f 100644 --- a/tests/bot/exts/backend/sync/test_base.py +++ b/tests/bot/exts/backend/sync/test_base.py @@ -39,8 +39,8 @@ class SyncerSyncTests(unittest.IsolatedAsyncioTestCase): (helpers.MockMessage(), ResponseCodeError(mock.MagicMock()), True), ) - for message, side_effect, should_edit in subtests: - with self.subTest(message=message, side_effect=side_effect, should_edit=should_edit): + for i, (message, side_effect, should_edit) in enumerate(subtests): + with self.subTest(test_case=i, has_message=message is not None, should_edit=should_edit): TestSyncer._sync.side_effect = side_effect ctx = helpers.MockContext() ctx.send.return_value = message @@ -58,8 +58,8 @@ class SyncerSyncTests(unittest.IsolatedAsyncioTestCase): (helpers.MockContext(), helpers.MockMessage()), ) - for ctx, message in subtests: - with self.subTest(ctx=ctx, message=message): + for i, (ctx, _message) in enumerate(subtests): + with self.subTest(test_case=i, has_ctx=ctx is not None): await TestSyncer.sync(self.guild, ctx) if ctx is not None: diff --git a/tests/bot/exts/backend/sync/test_cog.py b/tests/bot/exts/backend/sync/test_cog.py index 6d7356bf2..d67e709c8 100644 --- a/tests/bot/exts/backend/sync/test_cog.py +++ b/tests/bot/exts/backend/sync/test_cog.py @@ -65,8 +65,8 @@ class SyncCogTests(SyncCogTestCase): @unittest.mock.patch("bot.exts.backend.sync._cog.create_task", new_callable=unittest.mock.MagicMock) async def test_sync_cog_sync_on_load(self, mock_create_task: unittest.mock.MagicMock): """Sync function should be synced on cog load only if guild is found.""" - for guild in (helpers.MockGuild(), None): - with self.subTest(guild=guild): + for i, guild in enumerate((helpers.MockGuild(), None)): + with self.subTest(test_case=i, has_guild=guild is not None): mock_create_task.reset_mock() self.bot.reset_mock() self.RoleSyncer.reset_mock() @@ -126,8 +126,8 @@ class SyncCogTests(SyncCogTestCase): async def test_sync_cog_patch_user(self): """A PATCH request should be sent and 404 errors ignored.""" - for side_effect in (None, self.response_error(404)): - with self.subTest(side_effect=side_effect): + for i, side_effect in enumerate((None, self.response_error(404))): + with self.subTest(test_case=i, has_error=side_effect is not None): await self.patch_user_helper(side_effect) async def test_sync_cog_patch_user_non_404(self): @@ -207,7 +207,7 @@ class SyncCogListenerTests(SyncCogTestCase): for should_put, attributes in subtests: for attribute in attributes: - with self.subTest(should_put=should_put, changed_attribute=attribute): + with self.subTest(should_put=should_put, attribute=attribute): self.bot.api_client.put.reset_mock() after_role_data = role_data.copy() @@ -372,8 +372,8 @@ class SyncCogListenerTests(SyncCogTestCase): async def test_sync_cog_on_member_join(self): """Should PUT user's data or POST it if the user doesn't exist.""" - for side_effect in (None, self.response_error(404)): - with self.subTest(side_effect=side_effect): + for i, side_effect in enumerate((None, self.response_error(404))): + with self.subTest(test_case=i, has_error=side_effect is not None): self.bot.api_client.post.reset_mock() data = await self.on_member_join_helper(side_effect) @@ -422,6 +422,6 @@ class SyncCogCommandTests(SyncCogTestCase, CommandTestCase): self.cog.sync_users_command, ) - for cmd in cmds: - with self.subTest(cmd=cmd): + for i, cmd in enumerate(cmds): + with self.subTest(test_case=i): await self.assertHasPermissionsCheck(cmd, {"administrator": True}) diff --git a/tests/bot/exts/backend/test_error_handler.py b/tests/bot/exts/backend/test_error_handler.py index 85dc33999..de12443dd 100644 --- a/tests/bot/exts/backend/test_error_handler.py +++ b/tests/bot/exts/backend/test_error_handler.py @@ -135,8 +135,9 @@ class ErrorHandlerTests(unittest.IsolatedAsyncioTestCase): } ) - for case in test_cases: - with self.subTest(args=case["args"], expect_mock_call=case["expect_mock_call"]): + for i, case in enumerate(test_cases): + mock_type = "send" if case["expect_mock_call"] == "send" else "mock_function" + with self.subTest(test_case=i, expect_mock_call=mock_type): self.ctx.send.reset_mock() self.assertIsNone(await self.cog.on_command_error(*case["args"])) if case["expect_mock_call"] == "send": @@ -161,8 +162,8 @@ class ErrorHandlerTests(unittest.IsolatedAsyncioTestCase): } ) - for case in cases: - with self.subTest(**case): + for i, case in enumerate(cases): + with self.subTest(test_case=i): self.assertIsNone(await self.cog.on_command_error(self.ctx, case["error"])) case["mock_function_to_call"].assert_awaited_once_with(self.ctx, case["error"].original) @@ -173,8 +174,8 @@ class ErrorHandlerTests(unittest.IsolatedAsyncioTestCase): errors.ExtensionError(name="foo"), ) - for err in errs: - with self.subTest(error=err): + for i, err in enumerate(errs): + with self.subTest(test_case=i): self.cog.handle_unexpected_error.reset_mock() self.assertIsNone(await self.cog.on_command_error(self.ctx, err)) self.cog.handle_unexpected_error.assert_awaited_once_with(self.ctx, err) @@ -251,8 +252,8 @@ class TrySilenceTests(unittest.IsolatedAsyncioTestCase): (MockTextChannel(), True) ) - for channel, kick in test_cases: - with self.subTest(kick=kick, channel=channel): + for i, (channel, kick) in enumerate(test_cases): + with self.subTest(test_case=i, kick=kick): self.ctx.reset_mock() self.ctx.invoked_with = "shh" @@ -291,8 +292,8 @@ class TrySilenceTests(unittest.IsolatedAsyncioTestCase): ("unshh", MockTextChannel()) ) - for invoke, channel in test_cases: - with self.subTest(message=invoke, channel=channel): + for i, (invoke, channel) in enumerate(test_cases): + with self.subTest(test_case=i, message=invoke, has_channel=channel is not None): self.bot.get_command.side_effect = (self.silence.silence, self.silence.unsilence) self.ctx.reset_mock() @@ -386,33 +387,39 @@ class IndividualErrorHandlerTests(unittest.IsolatedAsyncioTestCase): """Should handle each error probably.""" test_cases = ( { + "error_type": "MissingRequiredArgument", "error": errors.MissingRequiredArgument(MagicMock()), "call_prepared": True }, { + "error_type": "TooManyArguments", "error": errors.TooManyArguments(), "call_prepared": True }, { + "error_type": "BadArgument", "error": errors.BadArgument(), "call_prepared": True }, { + "error_type": "BadUnionArgument", "error": errors.BadUnionArgument(MagicMock(), MagicMock(), MagicMock()), "call_prepared": True }, { + "error_type": "ArgumentParsingError", "error": errors.ArgumentParsingError(), "call_prepared": False }, { + "error_type": "UserInputError", "error": errors.UserInputError(), "call_prepared": True } ) for case in test_cases: - with self.subTest(error=case["error"], call_prepared=case["call_prepared"]): + with self.subTest(error_type=case["error_type"], call_prepared=case["call_prepared"]): self.ctx.reset_mock() self.cog.send_error_with_help = AsyncMock() self.assertIsNone(await self.cog.handle_user_input_error(self.ctx, case["error"])) @@ -426,33 +433,39 @@ class IndividualErrorHandlerTests(unittest.IsolatedAsyncioTestCase): """Should await `ctx.send` when error is check failure.""" test_cases = ( { + "error_type": "BotMissingPermissions", "error": errors.BotMissingPermissions(MagicMock()), "call_ctx_send": True }, { + "error_type": "BotMissingRole", "error": errors.BotMissingRole(MagicMock()), "call_ctx_send": True }, { + "error_type": "BotMissingAnyRole", "error": errors.BotMissingAnyRole(MagicMock()), "call_ctx_send": True }, { + "error_type": "NoPrivateMessage", "error": errors.NoPrivateMessage(), "call_ctx_send": True }, { + "error_type": "InWhitelistCheckFailure", "error": InWhitelistCheckFailure(1234), "call_ctx_send": True }, { + "error_type": "ResponseCodeError", "error": ResponseCodeError(MagicMock()), "call_ctx_send": False } ) for case in test_cases: - with self.subTest(error=case["error"], call_ctx_send=case["call_ctx_send"]): + with self.subTest(error_type=case["error_type"], call_ctx_send=case["call_ctx_send"]): self.ctx.reset_mock() await self.cog.handle_check_failure(self.ctx, case["error"]) if case["call_ctx_send"]: @@ -465,25 +478,29 @@ class IndividualErrorHandlerTests(unittest.IsolatedAsyncioTestCase): """Should `ctx.send` on HTTP error codes, and log at correct level.""" test_cases = ( { + "status": 400, "error": ResponseCodeError(AsyncMock(status=400)), "log_level": "error" }, { + "status": 404, "error": ResponseCodeError(AsyncMock(status=404)), "log_level": "debug" }, { + "status": 550, "error": ResponseCodeError(AsyncMock(status=550)), "log_level": "warning" }, { + "status": 1000, "error": ResponseCodeError(AsyncMock(status=1000)), "log_level": "warning" } ) for case in test_cases: - with self.subTest(error=case["error"], log_level=case["log_level"]): + with self.subTest(status=case["status"], log_level=case["log_level"]): self.ctx.reset_mock() log_mock.reset_mock() await self.cog.handle_api_error(self.ctx, case["error"]) @@ -500,7 +517,7 @@ class IndividualErrorHandlerTests(unittest.IsolatedAsyncioTestCase): async def test_handle_unexpected_error(self, log_mock, new_scope_mock): """Should `ctx.send` this error, error log this and sent to Sentry.""" for case in (None, MockGuild()): - with self.subTest(guild=case): + with self.subTest(has_guild=case is not None): self.ctx.reset_mock() log_mock.reset_mock() new_scope_mock.reset_mock() diff --git a/tests/bot/exts/filtering/test_settings_entries.py b/tests/bot/exts/filtering/test_settings_entries.py index f12b2caa5..1e9536c9e 100644 --- a/tests/bot/exts/filtering/test_settings_entries.py +++ b/tests/bot/exts/filtering/test_settings_entries.py @@ -144,8 +144,8 @@ class FilterTests(unittest.TestCase): (False, MockTextChannel(), True) ) - for apply_in_dms, channel, expected in cases: - with self.subTest(apply_in_dms=apply_in_dms, channel=channel): + for i, (apply_in_dms, channel, expected) in enumerate(cases): + with self.subTest(test_case=i, apply_in_dms=apply_in_dms): filter_dms = FilterDM(filter_dm=apply_in_dms) self.ctx.channel = channel diff --git a/tests/bot/exts/info/test_information.py b/tests/bot/exts/info/test_information.py index 13a82f9b8..6f9799ce0 100644 --- a/tests/bot/exts/info/test_information.py +++ b/tests/bot/exts/info/test_information.py @@ -122,22 +122,22 @@ class UserInfractionHelperMethodTests(unittest.IsolatedAsyncioTestCase): }, ) - for test_value in test_values: + for i, test_value in enumerate(test_values): helper_method = test_value["helper_method"] endpoint, params = test_value["expected_args"] - with self.subTest(method=helper_method, endpoint=endpoint, params=params): + with self.subTest(test_case=i, endpoint=endpoint): await helper_method(self.member) self.bot.api_client.get.assert_called_once_with(endpoint, params=params) self.bot.api_client.get.reset_mock() async def _method_subtests(self, method, test_values, default_header): """Helper method that runs the subtests for the different helper methods.""" - for test_value in test_values: + for i, test_value in enumerate(test_values): api_response = test_value["api response"] expected_lines = test_value["expected_lines"] - with self.subTest(method=method, api_response=api_response, expected_lines=expected_lines): + with self.subTest(test_case=i): self.bot.api_client.get.return_value = api_response expected_output = "\n".join(expected_lines) diff --git a/tests/bot/exts/moderation/infraction/test_utils.py b/tests/bot/exts/moderation/infraction/test_utils.py index e2a7bad9f..c18a937ab 100644 --- a/tests/bot/exts/moderation/infraction/test_utils.py +++ b/tests/bot/exts/moderation/infraction/test_utils.py @@ -66,13 +66,13 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase): } ] - for case in test_cases: + for i, case in enumerate(test_cases): user = case["user"] post_result = case["post_result"] raise_error = case["raise_error"] payload = case["payload"] - with self.subTest(user=user, post_result=post_result, raise_error=raise_error, payload=payload): + with self.subTest(test_case=i, has_error=raise_error is not None): self.bot.api_client.post.reset_mock(side_effect=True) self.ctx.bot.api_client.post.return_value = post_result @@ -235,8 +235,8 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase): } ] - for case in test_cases: - with self.subTest(args=case["args"], expected=case["expected_output"], send=case["send_result"]): + for i, case in enumerate(test_cases): + with self.subTest(test_case=i, send=case["send_result"]): send_private_embed_mock.reset_mock() send_private_embed_mock.return_value = case["send_result"] @@ -259,7 +259,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase): test_case((self.user, "Test title", "Example content", Icons.user_update), Icons.user_update, False) ] - for case in test_cases: + for i, case in enumerate(test_cases): expected = Embed( description="Example content", colour=Colours.soft_green @@ -268,7 +268,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase): icon_url=case.icon ) - with self.subTest(args=case.args, expected=expected): + with self.subTest(test_case=i): send_private_embed_mock.reset_mock() send_private_embed_mock.return_value = case.send_result @@ -288,13 +288,13 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase): test_case = namedtuple("test_case", ["expected_output", "raised_exception"]) test_cases = [ test_case(True, None), - test_case(False, HTTPException(AsyncMock(), AsyncMock())), - test_case(False, Forbidden(AsyncMock(), AsyncMock())), - test_case(False, NotFound(AsyncMock(), AsyncMock())) + test_case(False, HTTPException(AsyncMock(), "test error")), + test_case(False, Forbidden(AsyncMock(), "test error")), + test_case(False, NotFound(AsyncMock(), "test error")) ] - for case in test_cases: - with self.subTest(expected=case.expected_output, raised=case.raised_exception): + for i, case in enumerate(test_cases): + with self.subTest(test_case=i, expected=case.expected_output): self.user.send.reset_mock(side_effect=True) self.user.send.side_effect = case.raised_exception diff --git a/tests/bot/exts/moderation/test_silence.py b/tests/bot/exts/moderation/test_silence.py index 86d396afd..019a0634c 100644 --- a/tests/bot/exts/moderation/test_silence.py +++ b/tests/bot/exts/moderation/test_silence.py @@ -260,8 +260,8 @@ class SilenceArgumentParserTests(unittest.IsolatedAsyncioTestCase): ctx = MockContext() parser_mock.return_value = (ctx.channel, 10) - for case in test_cases: - with self.subTest("Test command converters", args=case): + for i, case in enumerate(test_cases): + with self.subTest(msg="Test command converters", test_case=i): await cog.silence.callback(cog, ctx, *case) try: @@ -433,10 +433,10 @@ class SilenceTests(SilenceTest): targets = (MockTextChannel(), MockVoiceChannel(), None) - for (duration, message, was_silenced), target in itertools.product(test_cases, targets): + for i, ((duration, message, was_silenced), target) in enumerate(itertools.product(test_cases, targets)): with ( mock.patch.object(self.cog, "_set_silence_overwrites", return_value=was_silenced), - self.subTest(was_silenced=was_silenced, target=target, message=message), + self.subTest(test_case=i, was_silenced=was_silenced, has_target=target is not None), mock.patch.object(self.cog, "send_message") as send_message ): ctx = MockContext() @@ -525,8 +525,8 @@ class SilenceTests(SilenceTest): (True, MockVoiceChannel(), PermissionOverwrite(connect=False, speak=False)), ) - for contains, channel, overwrite in subtests: - with self.subTest(contains=contains, is_text=isinstance(channel, MockTextChannel), overwrite=overwrite): + for i, (contains, channel, overwrite) in enumerate(subtests): + with self.subTest(test_case=i, contains=contains, is_text=isinstance(channel, MockTextChannel)): self.cog.scheduler.__contains__.return_value = contains channel.overwrites_for.return_value = overwrite @@ -702,7 +702,7 @@ class UnsilenceTests(SilenceTest): targets = (None, MockTextChannel()) - for (was_unsilenced, message, overwrite), target in itertools.product(test_cases, targets): + for i, ((was_unsilenced, message, overwrite), target) in enumerate(itertools.product(test_cases, targets)): ctx = MockContext() ctx.channel.overwrites_for.return_value = overwrite if target: @@ -711,7 +711,7 @@ class UnsilenceTests(SilenceTest): with ( mock.patch.object(self.cog, "_unsilence", return_value=was_unsilenced), mock.patch.object(self.cog, "send_message") as send_message, - self.subTest(was_unsilenced=was_unsilenced, overwrite=overwrite, target=target), + self.subTest(test_case=i, was_unsilenced=was_unsilenced, has_target=target is not None), ): await self.cog.unsilence.callback(self.cog, ctx, channel=target) @@ -722,8 +722,8 @@ class UnsilenceTests(SilenceTest): """Permissions were not set and `False` was returned for an already unsilenced channel.""" self.cog.scheduler.__contains__.return_value = False - for channel in (MockVoiceChannel(), MockTextChannel()): - with self.subTest(channel=channel): + for i, channel in enumerate((MockVoiceChannel(), MockTextChannel())): + with self.subTest(test_case=i): self.assertFalse(await self.cog._unsilence(channel)) channel.set_permissions.assert_not_called() @@ -811,8 +811,8 @@ class UnsilenceTests(SilenceTest): async def test_preserved_other_overwrites_text(self): """Text channel's other unrelated overwrites were not changed, including cache misses.""" - for overwrite_json in ('{"send_messages": true, "add_reactions": null}', None): - with self.subTest(overwrite_json=overwrite_json): + for i, overwrite_json in enumerate(('{"send_messages": true, "add_reactions": null}', None)): + with self.subTest(test_case=i, has_overwrite=overwrite_json is not None): if overwrite_json is None: await self.cog.previous_overwrites.delete(self.text_channel.id) else: @@ -832,8 +832,8 @@ class UnsilenceTests(SilenceTest): async def test_preserved_other_overwrites_voice(self): """Voice channel's other unrelated overwrites were not changed, including cache misses.""" - for overwrite_json in ('{"connect": true, "speak": true}', None): - with self.subTest(overwrite_json=overwrite_json): + for i, overwrite_json in enumerate(('{"connect": true, "speak": true}', None)): + with self.subTest(test_case=i, has_overwrite=overwrite_json is not None): if overwrite_json is None: await self.cog.previous_overwrites.delete(self.voice_channel.id) else: @@ -858,8 +858,8 @@ class UnsilenceTests(SilenceTest): (MockVoiceChannel(), self.cog.bot.get_guild(Guild.id).get_role(Roles.voice_verified)) ) - for channel, role in test_cases: - with self.subTest(channel=channel, role=role): + for i, (channel, role) in enumerate(test_cases): + with self.subTest(test_case=i): await self.cog._unsilence_wrapper(channel, MockContext()) channel.overwrites_for.assert_called_with(role) diff --git a/tests/bot/exts/recruitment/talentpool/test_review.py b/tests/bot/exts/recruitment/talentpool/test_review.py index 8ec384bb2..195fb71c1 100644 --- a/tests/bot/exts/recruitment/talentpool/test_review.py +++ b/tests/bot/exts/recruitment/talentpool/test_review.py @@ -141,8 +141,8 @@ class ReviewerTests(unittest.IsolatedAsyncioTestCase): ([], None, True), ) - for messages, last_review_timestamp, expected in cases: - with self.subTest(messages=messages, expected=expected): + for i, (messages, last_review_timestamp, expected) in enumerate(cases): + with self.subTest(test_case=i, expected=expected): self.voting_channel.history = AsyncIterator(messages) cache_get_mock = AsyncMock(return_value=last_review_timestamp) diff --git a/tests/bot/test_converters.py b/tests/bot/test_converters.py index e5ccf27f7..ffe9b9125 100644 --- a/tests/bot/test_converters.py +++ b/tests/bot/test_converters.py @@ -191,8 +191,8 @@ class ConverterTests(unittest.IsolatedAsyncioTestCase): converter = ISODateTime() - for datetime_string, expected_dt in test_values: - with self.subTest(datetime_string=datetime_string, expected_dt=expected_dt): + for i, (datetime_string, expected_dt) in enumerate(test_values): + with self.subTest(test_case=i, datetime_string=datetime_string): converted_dt = await converter.convert(self.context, datetime_string) self.assertEqual(converted_dt, expected_dt) diff --git a/tests/bot/utils/test_message_cache.py b/tests/bot/utils/test_message_cache.py index ad3f4e8b6..da6dad859 100644 --- a/tests/bot/utils/test_message_cache.py +++ b/tests/bot/utils/test_message_cache.py @@ -177,8 +177,8 @@ class TestMessageCache(unittest.TestCase): for msg in messages: cache.append(msg) - for slice_ in slices: - with self.subTest(current_loop=(size, slice_)): + for i, slice_ in enumerate(slices): + with self.subTest(size=size, slice_index=i): self.assertListEqual(cache[slice_], messages[slice_]) def test_slicing_with_overfilled_cache(self): @@ -199,8 +199,8 @@ class TestMessageCache(unittest.TestCase): cache.append(msg) messages = messages[size // 2:] - for slice_ in slices: - with self.subTest(current_loop=(size, slice_)): + for i, slice_ in enumerate(slices): + with self.subTest(size=size, slice_index=i): self.assertListEqual(cache[slice_], messages[slice_]) def test_length(self): diff --git a/tests/bot/utils/test_time.py b/tests/bot/utils/test_time.py index 6244a3548..d6f7b923e 100644 --- a/tests/bot/utils/test_time.py +++ b/tests/bot/utils/test_time.py @@ -32,8 +32,8 @@ class TimeTests(unittest.TestCase): (relativedelta(days=2, hours=2), "days", 2, "2 days"), ) - for delta, precision, max_units, expected in test_cases: - with self.subTest(delta=delta, precision=precision, max_units=max_units, expected=expected): + for i, (delta, precision, max_units, expected) in enumerate(test_cases): + with self.subTest(test_case=i, precision=precision, max_units=max_units, expected=expected): actual = time.humanize_delta(delta, precision=precision, max_units=max_units) self.assertEqual(actual, expected) @@ -57,8 +57,8 @@ class TimeTests(unittest.TestCase): (None, "Why hello there!", float("inf"), None), ) - for expiry, date_from, max_units, expected in test_cases: - with self.subTest(expiry=expiry, date_from=date_from, max_units=max_units, expected=expected): + for i, (expiry, date_from, max_units, expected) in enumerate(test_cases): + with self.subTest(test_case=i, expiry=expiry, max_units=max_units, expected=expected): self.assertEqual(time.format_with_duration(expiry, date_from, max_units), expected) def test_format_with_duration_custom_units(self): @@ -70,8 +70,8 @@ class TimeTests(unittest.TestCase): "<t:32531918940:f> (6 months, 28 days, 23 hours and 54 minutes)") ) - for expiry, date_from, max_units, expected in test_cases: - with self.subTest(expiry=expiry, date_from=date_from, max_units=max_units, expected=expected): + for i, (expiry, date_from, max_units, expected) in enumerate(test_cases): + with self.subTest(test_case=i, max_units=max_units, expected=expected): self.assertEqual(time.format_with_duration(expiry, date_from, max_units), expected) def test_format_with_duration_normal_usage(self): @@ -94,8 +94,8 @@ class TimeTests(unittest.TestCase): (None, datetime(2019, 11, 23, 23, 49, 5, tzinfo=UTC), 2, None), ) - for expiry, date_from, max_units, expected in test_cases: - with self.subTest(expiry=expiry, date_from=date_from, max_units=max_units, expected=expected): + for i, (expiry, date_from, max_units, expected) in enumerate(test_cases): + with self.subTest(test_case=i, max_units=max_units, expected=expected): self.assertEqual(time.format_with_duration(expiry, date_from, max_units), expected) def test_until_expiration_with_duration_none_expiry(self): @@ -109,8 +109,8 @@ class TimeTests(unittest.TestCase): ("3000-11-23T20:09:00Z", "<t:32531918940:R>") ) - for expiry, expected in test_cases: - with self.subTest(expiry=expiry, expected=expected): + for i, (expiry, expected) in enumerate(test_cases): + with self.subTest(test_case=i, expiry=expiry, expected=expected): self.assertEqual(time.until_expiration(expiry,), expected) def test_until_expiration_normal_usage(self): @@ -123,6 +123,6 @@ class TimeTests(unittest.TestCase): ("3000-11-23T20:09:00Z", "<t:32531918940:R>"), ) - for expiry, expected in test_cases: - with self.subTest(expiry=expiry, expected=expected): + for i, (expiry, expected) in enumerate(test_cases): + with self.subTest(test_case=i, expiry=expiry, expected=expected): self.assertEqual(time.until_expiration(expiry), expected) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 3d4cb09e7..75351e5e4 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -153,8 +153,8 @@ class DiscordMocksTests(unittest.TestCase): (helpers.MockMessage(), "mention_everyone"), ) - for mock, valid_attribute in mocks: - with self.subTest(mock=mock): + for i, (mock, valid_attribute) in enumerate(mocks): + with self.subTest(test_case=i, attribute=valid_attribute): try: getattr(mock, valid_attribute) except AttributeError: @@ -183,8 +183,8 @@ class DiscordMocksTests(unittest.TestCase): helpers.MockMessage(), ) - for mock in mocks: - with self.subTest(mock=mock), self.assertRaises(AttributeError): + for i, mock in enumerate(mocks): + with self.subTest(test_case=i), self.assertRaises(AttributeError): mock.the_cake_is_a_lie # noqa: B018 def test_mocks_use_mention_when_provided_as_kwarg(self): @@ -195,8 +195,8 @@ class DiscordMocksTests(unittest.TestCase): (helpers.MockTextChannel, "channel mention"), ) - for mock_type, mention in test_cases: - with self.subTest(mock_type=mock_type, mention=mention): + for i, (mock_type, mention) in enumerate(test_cases): + with self.subTest(test_case=i, mention=mention): mock = mock_type(mention=mention) self.assertEqual(mock.mention, mention) @@ -276,15 +276,15 @@ class MockObjectTests(unittest.TestCase): def test_mock_class_with_hashable_mixin_uses_id_for_hashing(self): """Test if the MagicMock subclasses that implement the HashableMixin use id for hash.""" - for mock in self.hashable_mocks: - with self.subTest(mock_class=mock): + for i, _mock in enumerate(self.hashable_mocks): + with self.subTest(test_case=i): instance = helpers.MockRole(id=100) self.assertEqual(hash(instance), instance.id) def test_mock_class_with_hashable_mixin_uses_id_for_equality(self): """Test if MagicMocks that implement the HashableMixin use id for equality comparisons.""" - for mock_class in self.hashable_mocks: - with self.subTest(mock_class=mock_class): + for i, mock_class in enumerate(self.hashable_mocks): + with self.subTest(test_case=i): instance_one = mock_class() instance_two = mock_class() instance_three = mock_class() @@ -298,8 +298,8 @@ class MockObjectTests(unittest.TestCase): def test_mock_class_with_hashable_mixin_uses_id_for_nonequality(self): """Test if MagicMocks that implement HashableMixin use id for nonequality comparisons.""" - for mock_class in self.hashable_mocks: - with self.subTest(mock_class=mock_class): + for i, mock_class in enumerate(self.hashable_mocks): + with self.subTest(test_case=i): instance_one = mock_class() instance_two = mock_class() instance_three = mock_class() @@ -336,8 +336,8 @@ class MockObjectTests(unittest.TestCase): (helpers.MockReaction, "me"), ) - for mock_type, valid_attribute in test_values: - with self.subTest(mock_type=mock_type, attribute=valid_attribute): + for i, (mock_type, valid_attribute) in enumerate(test_values): + with self.subTest(test_case=i, attribute=valid_attribute): mock = mock_type() self.assertTrue(isinstance(mock, mock_type)) attribute = getattr(mock, valid_attribute) |