Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95e7cf5

Browse files
committed
Don't just ignore core tests when re2 is not importable
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
1 parent 9e667cb commit 95e7cf5

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ jobs:
1919
fail-fast: false
2020
steps:
2121
- name: Checkout working copy
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323
- name: ruff check
2424
uses: chartboost/ruff-action@v1
2525
- name: ruff format
2626
uses: chartboost/ruff-action@v1
2727
with:
2828
args: format --diff
2929
- name: Set up Python
30-
uses: actions/setup-python@v4
30+
uses: actions/setup-python@v5
3131
with:
32-
python-version: "3.11"
32+
python-version: "3.x"
3333
- name: Install mypy
3434
run: |
3535
python -mpip install --upgrade pip
@@ -44,13 +44,13 @@ jobs:
4444

4545
steps:
4646
- name: Checkout working copy
47-
uses: actions/checkout@v3
47+
uses: actions/checkout@v4
4848
with:
4949
submodules: true
5050
- name: Set up Python
51-
uses: actions/setup-python@v4
51+
uses: actions/setup-python@v5
5252
with:
53-
python-version: "3.11"
53+
python-version: "3.x"
5454
- name: Install dependency
5555
run: |
5656
python -mpip install --upgrade pip
@@ -59,14 +59,14 @@ jobs:
5959
run: |
6060
python -mbuild
6161
- name: Upload sdist
62-
uses: actions/upload-artifact@v3
62+
uses: actions/upload-artifact@v4
6363
with:
6464
name: sdist
6565
path: dist/*.tar.gz
6666
retention-days: 1
6767

6868
- name: Upload wheel
69-
uses: actions/upload-artifact@v3
69+
uses: actions/upload-artifact@v4
7070
with:
7171
name: wheel
7272
path: dist/*.whl
@@ -94,40 +94,48 @@ jobs:
9494
- "pypy-3.9"
9595
- "pypy-3.10"
9696
# - "pypy-3.11"
97+
- "graalpy-23"
9798
include:
9899
- source: sdist
99100
artifact: dist/*.tar.gz
100101
- source: wheel
101102
artifact: dist/*.whl
102103
steps:
103104
- name: Checkout working copy
104-
uses: actions/checkout@v3
105+
uses: actions/checkout@v4
105106
with:
106107
submodules: true
107108
- name: Set up Python ${{ matrix.python-version }}
108-
uses: actions/setup-python@v4
109+
uses: actions/setup-python@v5
109110
with:
110111
python-version: ${{ matrix.python-version }}
111112
allow-prereleases: true
112113
- name: Install test dependencies
113114
run: |
114115
python -mpip install --upgrade pip
115-
# if binary wheels are not available for the current package install libyaml
116-
# NB: cyaml is outright broken on pypy so exclude that
116+
# cyaml is outright broken on pypy
117117
if ! ${{ startsWith(matrix.python-version, 'pypy-') }}; then
118+
# if binary wheels are not available for the current
119+
# package install libyaml-dev so we can install pyyaml
120+
# from source
118121
if ! pip download --only-binary pyyaml -rrequirements_dev.txt > /dev/null 2>&1; then
119122
sudo apt install libyaml-dev
120123
fi
121124
fi
122125
python -mpip install pytest pyyaml
126+
127+
if ! python -mpip download --only-binary google-re2; then
128+
sudo apt install libre2-dev pybind11-dev
129+
fi
130+
python -mpip install google-re2 || true
123131
- name: download ${{ matrix.source }} artifact
124132
if: matrix.artifact
125-
uses: actions/download-artifact@v3
133+
uses: actions/download-artifact@v4
126134
with:
127135
name: ${{ matrix.source }}
128136
path: dist/
129137
- name: install package in environment
130138
run: |
131139
pip install ${{ matrix.artifact || '.' }}
132140
- name: run tests
133-
run: pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst"
141+
run: pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst" -ra

tests/test_core.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Tests UAP-Python using the UAP-core test suite
22
"""
33

4-
import contextlib
54
import dataclasses
65
import logging
76
import pathlib
@@ -63,9 +62,15 @@
6362
id="lru",
6463
),
6564
]
66-
with contextlib.suppress(ImportError):
65+
try:
6766
from ua_parser import re2
68-
67+
except ImportError:
68+
PARSERS.append(
69+
pytest.param(
70+
None, id="re2", marks=pytest.mark.skip(reason="re2 parser not available")
71+
)
72+
)
73+
else:
6974
PARSERS.append(pytest.param(Parser(re2.Resolver(load_builtins())), id="re2"))
7075

7176
UA_FIELDS = {f.name for f in dataclasses.fields(UserAgent)}

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ deps =
2323
commands =
2424
pytest -Werror --doctest-glob="*.rst" {posargs}
2525

26-
[testenv:pypy3.{8,9,10},py312]
26+
[testenv:pypy3.{8,9,10}]
2727
deps =
2828
pytest
2929
pyyaml

0 commit comments

Comments
 (0)