diff options
author | 2021-06-05 17:47:45 +0800 | |
---|---|---|
committer | 2021-06-05 17:47:45 +0800 | |
commit | c290ef91d436d21c913daed63a6df14fc80f3737 (patch) | |
tree | a2dfb1b04dc68cb8a1a2b956c88dfcac17ecff2e /tests | |
parent | Updates Shh Command To Mirror Silence (diff) | |
parent | Merge pull request #1587 from RohanJnr/voice_ver_dm (diff) |
Merge branch 'main' into voicechannel-mute
Diffstat (limited to 'tests')
-rw-r--r-- | tests/README.md | 10 | ||||
-rw-r--r-- | tests/bot/exts/moderation/infraction/test_infractions.py | 4 | ||||
-rw-r--r-- | tests/bot/utils/test_time.py | 13 |
3 files changed, 7 insertions, 20 deletions
diff --git a/tests/README.md b/tests/README.md index 092324123..1a17c09bd 100644 --- a/tests/README.md +++ b/tests/README.md @@ -12,13 +12,13 @@ We are using the following modules and packages for our unit tests: - [unittest.mock](https://docs.python.org/3/library/unittest.mock.html) (standard library) - [coverage.py](https://coverage.readthedocs.io/en/stable/) -To ensure the results you obtain on your personal machine are comparable to those generated in the Azure pipeline, please make sure to run your tests with the virtual environment defined by our [Pipfile](/Pipfile). To run your tests with `pipenv`, we've provided two "scripts" shortcuts: +To ensure the results you obtain on your personal machine are comparable to those generated in the CI, please make sure to run your tests with the virtual environment defined by our [Poetry Project](/pyproject.toml). To run your tests with `poetry`, we've provided two "scripts" shortcuts: -- `pipenv run test` will run `unittest` with `coverage.py` -- `pipenv run test path/to/test.py` will run a specific test. -- `pipenv run report` will generate a coverage report of the tests you've run with `pipenv run test`. If you append the `-m` flag to this command, the report will include the lines and branches not covered by tests in addition to the test coverage report. +- `poetry run task test` will run `unittest` with `coverage.py` +- `poetry run task test path/to/test.py` will run a specific test. +- `poetry run task report` will generate a coverage report of the tests you've run with `poetry run task test`. If you append the `-m` flag to this command, the report will include the lines and branches not covered by tests in addition to the test coverage report. -If you want a coverage report, make sure to run the tests with `pipenv run test` *first*. +If you want a coverage report, make sure to run the tests with `poetry run task test` *first*. ## Writing tests diff --git a/tests/bot/exts/moderation/infraction/test_infractions.py b/tests/bot/exts/moderation/infraction/test_infractions.py index 08f39cd50..b9d527770 100644 --- a/tests/bot/exts/moderation/infraction/test_infractions.py +++ b/tests/bot/exts/moderation/infraction/test_infractions.py @@ -74,7 +74,7 @@ class VoiceBanTests(unittest.IsolatedAsyncioTestCase): """Should call voice ban applying function without expiry.""" self.cog.apply_voice_ban = AsyncMock() self.assertIsNone(await self.cog.voiceban(self.cog, self.ctx, self.user, reason="foobar")) - self.cog.apply_voice_ban.assert_awaited_once_with(self.ctx, self.user, "foobar") + self.cog.apply_voice_ban.assert_awaited_once_with(self.ctx, self.user, "foobar", expires_at=None) async def test_temporary_voice_ban(self): """Should call voice ban applying function with expiry.""" @@ -184,7 +184,7 @@ class VoiceBanTests(unittest.IsolatedAsyncioTestCase): user = MockUser() await self.cog.voiceban(self.cog, self.ctx, user, reason=None) - post_infraction_mock.assert_called_once_with(self.ctx, user, "voice_ban", None, active=True) + post_infraction_mock.assert_called_once_with(self.ctx, user, "voice_ban", None, active=True, expires_at=None) apply_infraction_mock.assert_called_once_with(self.cog, self.ctx, infraction, user, ANY) # Test action diff --git a/tests/bot/utils/test_time.py b/tests/bot/utils/test_time.py index 694d3a40f..115ddfb0d 100644 --- a/tests/bot/utils/test_time.py +++ b/tests/bot/utils/test_time.py @@ -1,7 +1,5 @@ -import asyncio import unittest from datetime import datetime, timezone -from unittest.mock import AsyncMock, patch from dateutil.relativedelta import relativedelta @@ -56,17 +54,6 @@ class TimeTests(unittest.TestCase): """Testing format_infraction.""" self.assertEqual(time.format_infraction('2019-12-12T00:01:00Z'), '2019-12-12 00:01') - @patch('asyncio.sleep', new_callable=AsyncMock) - def test_wait_until(self, mock): - """Testing wait_until.""" - start = datetime(2019, 1, 1, 0, 0) - then = datetime(2019, 1, 1, 0, 10) - - # No return value - self.assertIs(asyncio.run(time.wait_until(then, start)), None) - - mock.assert_called_once_with(10 * 60) - def test_format_infraction_with_duration_none_expiry(self): """format_infraction_with_duration should work for None expiry.""" test_cases = ( |