Skip to content

Commit

Permalink
Add tox configuration and remove pre_push.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Feb 10, 2025
1 parent f721335 commit 94d7060
Show file tree
Hide file tree
Showing 8 changed files with 731 additions and 157 deletions.
48 changes: 40 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: CI
secrets: inherit
uses: praw-dev/.github/.github/workflows/ci.yml@main
with:
package: prawcore
test:
name: test with ${{ matrix.env }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
env:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
include:
- env: "3.9"
version: macos-latest
- env: "3.9"
version: windows-latest
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
- name: Install tox
run: uv tool install --python-preference only-managed --python ${{ matrix.env }} tox --with tox-uv
- name: Run test suite
run: |
tox run --skip-pkg-install -e ${{ fromJson('{ "3.9": "py39", "3.10": "py310", "3.11": "py311", "3.12": "py312", "3.13": "py313", }')[matrix.env] }}
- name: Run lint tests
if: matrix.env == '3.9'
run: tox run --skip-pkg-install --skip-env py

name: CI
on: [ pull_request, push ]
permissions: read-all
on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
100 changes: 0 additions & 100 deletions pre_push.py

This file was deleted.

82 changes: 64 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.4,<4"]

[dependency-groups]
dev = [
"tox-uv>=1.22.1"
]
lint = [
"pre-commit",
"ruff>=0.9.5"
]
test = [
"betamax >=0.8, <0.9",
"coverage>=7.6.10",
"pytest>=8.3.4",
"urllib3 ==1.*"
]
type = [
"pyright>=1.1.393",
"pytest>=8.3.4"
]

[project]
authors = [{name = "Bryce Boe", email = "[email protected]"}]
classifiers = [
Expand Down Expand Up @@ -31,23 +50,6 @@ name = "prawcore"
readme = "README.rst"
requires-python = "~=3.9"

[project.optional-dependencies]
dev = [
"prawcore[lint]",
"prawcore[test]"
]
lint = [
"pre-commit",
"ruff ==0.9.*"
]
test = [
"betamax >=0.8, <0.9",
"pyright",
"pytest ==7.*",
"types-requests",
"urllib3 ==1.*"
]

[project.urls]
"Issue Tracker" = "https://github.com/praw-dev/prawcore/issues"
"Source Code" = "https://github.com/praw-dev/prawcore"
Expand Down Expand Up @@ -117,6 +119,50 @@ suppress-dummy-args = true

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"pre_push.py" = ["T201"]
"examples/*.py" = ["ANN", "PLR2004", "T201"]
"tests/**.py" = ["ANN", "D", "PLR2004", "S101", "S105", "S106", "S301"]

[tool.tox]
envlist = ["py39", "py310", "py311", "py312", "py313", "pre-commit", "style", "type"]
minversion = "4.22"

[tool.tox.env.pre-commit]
commands = [
["pre-commit", "run", "--all-files"]
]
description = "run pre-commit on code base"
dependency_groups = ["lint"]
runner = "uv-venv-lock-runner"

[tool.tox.env.style]
commands = [
["ruff", "check"],
["ruff", "format", "--diff", "--target-version", "py39"]
]
description = "run lint check on code base"
dependency_groups = ["lint"]
runner = "uv-venv-lock-runner"

[tool.tox.env.stylefix]
commands = [
["ruff", "check", "--fix"],
["ruff", "format", "--target-version", "py39"]
]
description = "run lint check on code base"
dependency_groups = ["lint"]
runner = "uv-venv-lock-runner"

[tool.tox.env.type]
commands = [["pyright", "prawcore"]]
dependency_groups = ["type"]
description = "run type check on code base"
runner = "uv-venv-lock-runner"

[tool.tox.env_run_base]
commands = [
["coverage", "run", "-m", "pytest", "{posargs}"],
["coverage", "report", "-m", "--fail-under=100"]
]
description = "Run test under {base_python}"
dependency_groups = ["test"]
runner = "uv-venv-lock-runner"
24 changes: 4 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import socket
import time
from base64 import b64encode
from pathlib import Path
from sys import platform

import pytest
Expand All @@ -22,17 +21,6 @@ def _sleep(*_, **__):
monkeypatch.setattr(time, "sleep", value=_sleep)


@pytest.fixture
def image_path():
"""Return path to image."""

def _get_path(name):
"""Return path to image."""
return Path(__file__).parent / "integration" / "files" / name

return _get_path


@pytest.fixture
def requestor():
"""Return path to image."""
Expand Down Expand Up @@ -65,16 +53,10 @@ def env_default(key):

def pytest_configure(config):
pytest.placeholders = Placeholders(placeholders)
config.addinivalue_line("markers", "add_placeholder: Define an additional placeholder for the cassette.")
config.addinivalue_line("markers", "cassette_name: Name of cassette to use for test.")
config.addinivalue_line("markers", "recorder_kwargs: Arguments to pass to the recorder.")


def two_factor_callback():
"""Return an OTP code."""
return


class Placeholders:
def __init__(self, _dict):
self.__dict__ = _dict
Expand All @@ -88,13 +70,15 @@ def __init__(self, _dict):
).split()
}

if placeholders["client_id"] != "fake_client_id" and placeholders["client_secret"] == "fake_client_secret":
if (
placeholders["client_id"] != "fake_client_id" and placeholders["client_secret"] == "fake_client_secret"
): # pragma: no cover
placeholders["basic_auth"] = b64encode(f"{placeholders['client_id']}:".encode()).decode("utf-8")
else:
placeholders["basic_auth"] = b64encode(
f"{placeholders['client_id']}:{placeholders['client_secret']}".encode()
).decode("utf-8")


if platform == "darwin": # Work around issue with betamax on OS X
if platform == "darwin": # Work around issue with betamax on OS X # pragma: no cover
socket.gethostbyname = lambda _: "127.0.0.1"
7 changes: 1 addition & 6 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IntegrationTest:
"""Base class for prawcore integration tests."""

@pytest.fixture(autouse=True, scope="session")
def cassette_tracker(self):
def cassette_tracker(self): # pragma: no cover
"""Track cassettes to ensure unused cassettes are not uploaded."""
for cassette in os.listdir(CASSETTES_PATH):
existing_cassettes.add(cassette[: cassette.rindex(".")])
Expand All @@ -36,11 +36,6 @@ def cassette_tracker(self):
def cassette(self, request, recorder, cassette_name):
"""Wrap a test in a Betamax cassette."""
kwargs = {}
for marker in request.node.iter_markers("add_placeholder"):
for key, value in marker.kwargs.items():
recorder.config.default_cassette_options["placeholders"].append(
{"placeholder": f"<{key.upper()}>", "replace": value}
)
for marker in request.node.iter_markers("recorder_kwargs"):
for key, value in marker.kwargs.items():
# Don't overwrite existing values since function markers are provided
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_authorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


class InvalidAuthenticator(prawcore.auth.BaseAuthenticator):
def _auth(self):
pass
_auth = None


class TestAuthorizer(UnitTest):
Expand Down
6 changes: 3 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def ensure_integration_test(cassette):
if cassette.is_recording():
if cassette.is_recording(): # pragma: no cover
is_integration_test = bool(cassette.interactions)
action = "record"
else:
Expand All @@ -17,7 +17,7 @@ def ensure_integration_test(cassette):
assert is_integration_test, message


def filter_access_token(interaction, current_cassette):
def filter_access_token(interaction, current_cassette): # pragma: no cover
"""Add Betamax placeholder to filter access token."""
request_uri = interaction.data["request"]["uri"]
response = interaction.data["response"]
Expand All @@ -34,7 +34,7 @@ def filter_access_token(interaction, current_cassette):
)


class PrettyJSONSerializer(JSONSerializer):
class PrettyJSONSerializer(JSONSerializer): # pragma: no cover
name = "prettyjson"

def serialize(self, cassette_data):
Expand Down
Loading

0 comments on commit 94d7060

Please sign in to comment.