Skip to content

Commit

Permalink
Don't just ignore core tests when re2 is not importable
Browse files Browse the repository at this point in the history
This makes the import failure (and possibly test failures) completely
invisible in "misconfigured" environments, which is exactly what
happened in the github action where I forgot to add the dependency.

Fixes #191
  • Loading branch information
masklinn committed Feb 27, 2024
1 parent 9e667cb commit 0e70294
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
40 changes: 26 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ jobs:
fail-fast: false
steps:
- name: Checkout working copy
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: ruff check
uses: chartboost/ruff-action@v1
- name: ruff format
uses: chartboost/ruff-action@v1
with:
args: format --diff
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.x"
- name: Install mypy
run: |
python -mpip install --upgrade pip
Expand All @@ -44,13 +44,13 @@ jobs:

steps:
- name: Checkout working copy
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.x"
- name: Install dependency
run: |
python -mpip install --upgrade pip
Expand All @@ -59,14 +59,14 @@ jobs:
run: |
python -mbuild
- name: Upload sdist
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
retention-days: 1

- name: Upload wheel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/*.whl
Expand Down Expand Up @@ -94,40 +94,52 @@ jobs:
- "pypy-3.9"
- "pypy-3.10"
# - "pypy-3.11"
# don't enable graal because it's slower than even pypy and
# fails because oracle/graalpython#385
# - "graalpy-23"
include:
- source: sdist
artifact: dist/*.tar.gz
- source: wheel
artifact: dist/*.whl
steps:
- name: Checkout working copy
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install test dependencies
run: |
python -mpip install --upgrade pip
# if binary wheels are not available for the current package install libyaml
# NB: cyaml is outright broken on pypy so exclude that
# cyaml is outright broken on pypy
if ! ${{ startsWith(matrix.python-version, 'pypy-') }}; then
# if binary wheels are not available for the current
# package install libyaml-dev so we can install pyyaml
# from source
if ! pip download --only-binary pyyaml -rrequirements_dev.txt > /dev/null 2>&1; then
sudo apt install libyaml-dev
fi
fi
python -mpip install pytest pyyaml
# re2 is basically impossible to install from source so don't
# bother, and suppress installation failure so the test does
# not fail (re2 tests will just be skipped for versions /
# implementations for which google does not provide a binary
# wheel)
python -mpip install --only-binary :all: google-re2 || true
- name: download ${{ matrix.source }} artifact
if: matrix.artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ matrix.source }}
path: dist/
- name: install package in environment
run: |
pip install ${{ matrix.artifact || '.' }}
- name: run tests
run: pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst"
run: pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst" -ra
11 changes: 8 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests UAP-Python using the UAP-core test suite
"""

import contextlib
import dataclasses
import logging
import pathlib
Expand Down Expand Up @@ -63,9 +62,15 @@
id="lru",
),
]
with contextlib.suppress(ImportError):
try:
from ua_parser import re2

except ImportError:
PARSERS.append(
pytest.param(
None, id="re2", marks=pytest.mark.skip(reason="re2 parser not available")
)
)
else:
PARSERS.append(pytest.param(Parser(re2.Resolver(load_builtins())), id="re2"))

UA_FIELDS = {f.name for f in dataclasses.fields(UserAgent)}
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ deps =
commands =
pytest -Werror --doctest-glob="*.rst" {posargs}

[testenv:pypy3.{8,9,10},py312]
[testenv:pypy3.{8,9,10}]
deps =
pytest
pyyaml
Expand Down

0 comments on commit 0e70294

Please sign in to comment.