From 809a03a8b5254f416732423523a9dc7515284e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= <16805946+edgarrmondragon@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:48:14 -0600 Subject: [PATCH] chore: Remove dev dependency on pytest and use backports.strenum only on < 3.11 (#18) --- .github/workflows/test.yaml | 20 ++++------ .pre-commit-config.yaml | 4 +- pyproject.toml | 36 ++++++++--------- src/backports/httpmethod/__init__.py | 7 +++- tests/test_httpmethod.py | 58 ++++++++++++++++------------ 5 files changed, 66 insertions(+), 59 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3e7be69..6a8de9f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,14 +35,15 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + id: setup-python with: cache: pip - python-version: "3.10" + python-version: "3.12" - name: Install dependencies env: PIP_CONSTRAINT: .github/workflows/constraints.txt run: | - pipx install hatch + pipx install --python '${{ steps.setup-python.outputs.python-path }}' hatch - name: Run lint env: HATCH_ENV: lint @@ -52,7 +53,7 @@ jobs: test: name: Pytest (Python ${{ matrix.python-version }}, ${{ matrix.os }}) runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.python-version == '3.12' }} + continue-on-error: ${{ matrix.python-version == '3.13' }} strategy: fail-fast: false matrix: @@ -66,18 +67,11 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + id: setup-python with: cache: pip python-version: ${{ matrix.python-version }} allow-prereleases: true architecture: x64 - - name: Install dependencies - env: - PIP_CONSTRAINT: .github/workflows/constraints.txt - run: | - pipx install hatch - - name: Run tests - env: - HATCH_ENV: "test.py${{ matrix.python-version }}" - run: | - hatch run test + - run: pip install . + - run: python -Im unittest -v diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca0da71..be5ef03 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,10 +18,10 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.2.0 hooks: - id: ruff - args: [--fix, --preview, --exit-non-zero-on-fix, --show-fixes] + args: [--fix, --exit-non-zero-on-fix, --show-fixes] - id: ruff entry: ruff format diff --git a/pyproject.toml b/pyproject.toml index 28f430f..94fcd1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ keywords = [ "http", "httpmethod", ] -license = "MIT" +license.file = "LICENSE" authors = [ { name = "Edgar Ramírez-Mondragón", email = "edgarrmondragon@hey.com" }, ] @@ -30,6 +30,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] @@ -37,14 +38,7 @@ dynamic = [ "version", ] dependencies = [ - "backports.strenum", -] -optional-dependencies.dev = [ - "backports.httpmethod[test]", -] -optional-dependencies.test = [ - "coverage[toml]", - "pytest", + 'backports.strenum; python_version < "3.11"', ] urls.Documentation = "https://github.com/edgarrmondragon/backports.httpmethod#readme" urls.Issues = "https://github.com/edgarrmondragon/backports.httpmethod/issues" @@ -56,18 +50,16 @@ packages = ["src/backports"] [tool.hatch.version] source = "vcs" -[tool.hatch.envs.test] -features = ["test"] -[tool.hatch.envs.test.overrides] +[tool.hatch.envs.default] +[tool.hatch.envs.default.overrides] env.GITHUB_ACTIONS.dev-mode = { value = false, if = ["true"] } matrix.python.env-vars = [ { key = "COVERAGE_CORE", value = "sysmon", if = ["3.12", "3.13"] } ] -[tool.hatch.envs.test.scripts] -test = "pytest {args:tests}" -cov = "coverage run -m pytest {args:tests}" +[tool.hatch.envs.default.scripts] +test = "python -Im unittest {args}" -[[tool.hatch.envs.test.matrix]] +[[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] [tool.hatch.envs.lint] @@ -93,6 +85,7 @@ all = [ [tool.ruff] line-length = 120 +preview = true target-version = "py37" [tool.ruff.lint] @@ -148,8 +141,13 @@ known-first-party = ["backports_httpmethod"] ban-relative-imports = "all" [tool.ruff.lint.per-file-ignores] -# Tests can use magic values, assertions, and relative imports -"tests/**/*" = ["PLR2004", "S101", "TID252"] +# Tests can use magic values, and relative imports +"tests/**/*" = ["PLR2004", "TID252"] + +[tool.pyproject-fmt] +indent = 2 +keep_full_version = true +max_supported_python = "3.13" [tool.coverage.run] source_pkgs = ["backports", "tests"] @@ -161,7 +159,7 @@ backports_httpmethod = ["src/backports/httpmethod", "*/backports.httpmethod/src/ tests = ["tests", "*/backports.httpmethod/tests"] [tool.coverage.report] -exclude_lines = [ +exclude_also = [ "no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:", diff --git a/src/backports/httpmethod/__init__.py b/src/backports/httpmethod/__init__.py index 7c890dd..2432bb3 100644 --- a/src/backports/httpmethod/__init__.py +++ b/src/backports/httpmethod/__init__.py @@ -1,4 +1,9 @@ -from backports.strenum import StrEnum +import sys + +if sys.version_info < (3, 11): + from backports.strenum import StrEnum +else: + from enum import StrEnum __all__ = ["HTTPMethod"] diff --git a/tests/test_httpmethod.py b/tests/test_httpmethod.py index 93366eb..67d6938 100644 --- a/tests/test_httpmethod.py +++ b/tests/test_httpmethod.py @@ -1,27 +1,37 @@ -from backports.httpmethod import HTTPMethod - - -def test_equals_string(): - assert HTTPMethod.GET == "GET" - +import sys +import unittest -def test_value(): - assert HTTPMethod.GET.value == "GET" - - -def test_description(): - assert HTTPMethod.GET.description == "Retrieve the target." +from backports.httpmethod import HTTPMethod -def test_available_methods(): - assert list(HTTPMethod) == [ - HTTPMethod.CONNECT, - HTTPMethod.DELETE, - HTTPMethod.GET, - HTTPMethod.HEAD, - HTTPMethod.OPTIONS, - HTTPMethod.PATCH, - HTTPMethod.POST, - HTTPMethod.PUT, - HTTPMethod.TRACE, - ] +class TestHTTPMethod(unittest.TestCase): + def test_equals_string(self): + self.assertEqual(HTTPMethod.GET, "GET") + + def test_value(self): + self.assertEqual(HTTPMethod.GET.value, "GET") + + def test_description(self): + self.assertEqual(HTTPMethod.GET.description, "Retrieve the target.") + + def test_available_methods(self): + self.assertListEqual( + list(HTTPMethod), + [ + HTTPMethod.CONNECT, + HTTPMethod.DELETE, + HTTPMethod.GET, + HTTPMethod.HEAD, + HTTPMethod.OPTIONS, + HTTPMethod.PATCH, + HTTPMethod.POST, + HTTPMethod.PUT, + HTTPMethod.TRACE, + ], + ) + + @unittest.skipIf(sys.version_info < (3, 11), "requires Python 3.11+") + def test_equality(self): + from http import HTTPMethod as PyHTTPMethod # noqa: PLC0415 + + self.assertEqual(HTTPMethod.__members__, PyHTTPMethod.__members__)