From ce1fd8e56286300803b6cb10e4e4d4f996733301 Mon Sep 17 00:00:00 2001 From: Shivansh Date: Fri, 7 May 2021 10:42:00 +0530 Subject: (infractions): Modify voice ban tests according to new changes in 3272605 --- tests/bot/exts/moderation/infraction/test_infractions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '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 -- cgit v1.2.3 From 714f8f8faeee8abc7e6f153cb8cbb64fea1c2eeb Mon Sep 17 00:00:00 2001 From: rohan Date: Mon, 10 May 2021 02:01:16 +0530 Subject: Remove test for un-available function. --- tests/bot/utils/test_time.py | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'tests') 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 = ( -- cgit v1.2.3 From 1db39d0c3cd1c3f4731f4c494a892d15a07f00fe Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Tue, 11 May 2021 20:58:45 +0300 Subject: Updates Usages Of Pipenv To Poetry Updates the Dockerfile, pre-commit, CI, and documentation to reflect the new dependency manager. Dockerfile is also updated to 3.9. Signed-off-by: Hassan Abouelela --- .github/workflows/lint-test.yml | 19 ++++++++----------- .pre-commit-config.yaml | 4 ++-- Dockerfile | 20 +++++++------------- tests/README.md | 10 +++++----- 4 files changed, 22 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 95bed2e14..d96f324ec 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -23,15 +23,12 @@ jobs: PIP_NO_CACHE_DIR: false PIP_USER: 1 - # Hide the graphical elements from pipenv's output - PIPENV_HIDE_EMOJIS: 1 - PIPENV_NOSPIN: 1 - - # Make sure pipenv does not try reuse an environment it's running in - PIPENV_IGNORE_VIRTUALENVS: 1 + # Make sure package manager does not use virtualenv + POETRY_VIRTUALENVS_CREATE: false # Specify explicit paths for python dependencies and the pre-commit # environment so we know which directories to cache + POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache @@ -46,7 +43,7 @@ jobs: id: python uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.9' # This step caches our Python dependencies. To make sure we # only restore a cache when the dependencies, the python version, @@ -61,14 +58,14 @@ jobs: path: ${{ env.PYTHONUSERBASE }} key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\ ${{ steps.python.outputs.python-version }}-\ - ${{ hashFiles('./Pipfile', './Pipfile.lock') }}" + ${{ hashFiles('./pyproject.toml', './poetry.lock') }}" # Install our dependencies if we did not restore a dependency cache - - name: Install dependencies using pipenv + - name: Install dependencies using poetry if: steps.python_cache.outputs.cache-hit != 'true' run: | - pip install pipenv - pipenv install --dev --deploy --system + pip install poetry + poetry install # This step caches our pre-commit environment. To make sure we # do create a new environment when our pre-commit setup changes, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52500a282..131ba9453 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: hooks: - id: flake8 name: Flake8 - description: This hook runs flake8 within our project's pipenv environment. - entry: pipenv run flake8 + description: This hook runs flake8 within our project's environment. + entry: poetry run task flake8 language: system types: [python] require_serial: true diff --git a/Dockerfile b/Dockerfile index 1a75e5669..91e9ce18e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,19 @@ -FROM python:3.8-slim +FROM python:3.9.5-slim -# Set pip to have cleaner logs and no saved cache +# Set pip to have no saved cache ENV PIP_NO_CACHE_DIR=false \ - PIPENV_HIDE_EMOJIS=1 \ - PIPENV_IGNORE_VIRTUALENVS=1 \ - PIPENV_NOSPIN=1 + POETRY_VIRTUALENVS_CREATE=false -RUN apt-get -y update \ - && apt-get install -y \ - git \ - && rm -rf /var/lib/apt/lists/* -# Install pipenv -RUN pip install -U pipenv +# Install poetry +RUN pip install -U poetry # Create the working directory WORKDIR /bot # Install project dependencies -COPY Pipfile* ./ -RUN pipenv install --system --deploy +COPY pyproject.toml poetry.lock ./ +RUN poetry install --prod # Define Git SHA build argument ARG git_sha="development" 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 -- cgit v1.2.3