Skip to content

Commit

Permalink
chore: Simplify dev workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Feb 2, 2024
1 parent 90eba6b commit c73de92
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 58 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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]
Expand Down
35 changes: 16 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords = [
"http",
"httpmethod",
]
license = "MIT"
license.file = "LICENSE"
authors = [
{ name = "Edgar Ramírez-Mondragón", email = "edgarrmondragon@hey.com" },
]
Expand All @@ -30,21 +30,15 @@ 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",
]
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"
Expand All @@ -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]
Expand Down Expand Up @@ -148,8 +140,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"]
Expand All @@ -161,7 +158,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:",
Expand Down
7 changes: 6 additions & 1 deletion src/backports/httpmethod/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
58 changes: 34 additions & 24 deletions tests/test_httpmethod.py
Original file line number Diff line number Diff line change
@@ -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.assertDictEqual(HTTPMethod.__members__, PyHTTPMethod.__members__)

0 comments on commit c73de92

Please sign in to comment.