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

Skip to content

Commit 0e70294

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 0e70294

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

.github/workflows/ci.yml

Lines changed: 26 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,52 @@ jobs:
9494
- "pypy-3.9"
9595
- "pypy-3.10"
9696
# - "pypy-3.11"
97+
# don't enable graal because it's slower than even pypy and
98+
# fails because oracle/graalpython#385
99+
# - "graalpy-23"
97100
include:
98101
- source: sdist
99102
artifact: dist/*.tar.gz
100103
- source: wheel
101104
artifact: dist/*.whl
102105
steps:
103106
- name: Checkout working copy
104-
uses: actions/checkout@v3
107+
uses: actions/checkout@v4
105108
with:
106109
submodules: true
107110
- name: Set up Python ${{ matrix.python-version }}
108-
uses: actions/setup-python@v4
111+
uses: actions/setup-python@v5
109112
with:
110113
python-version: ${{ matrix.python-version }}
111114
allow-prereleases: true
112115
- name: Install test dependencies
113116
run: |
114117
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
118+
# cyaml is outright broken on pypy
117119
if ! ${{ startsWith(matrix.python-version, 'pypy-') }}; then
120+
# if binary wheels are not available for the current
121+
# package install libyaml-dev so we can install pyyaml
122+
# from source
118123
if ! pip download --only-binary pyyaml -rrequirements_dev.txt > /dev/null 2>&1; then
119124
sudo apt install libyaml-dev
120125
fi
121126
fi
122127
python -mpip install pytest pyyaml
128+
129+
# re2 is basically impossible to install from source so don't
130+
# bother, and suppress installation failure so the test does
131+
# not fail (re2 tests will just be skipped for versions /
132+
# implementations for which google does not provide a binary
133+
# wheel)
134+
python -mpip install --only-binary :all: google-re2 || true
123135
- name: download ${{ matrix.source }} artifact
124136
if: matrix.artifact
125-
uses: actions/download-artifact@v3
137+
uses: actions/download-artifact@v4
126138
with:
127139
name: ${{ matrix.source }}
128140
path: dist/
129141
- name: install package in environment
130142
run: |
131143
pip install ${{ matrix.artifact || '.' }}
132144
- name: run tests
133-
run: pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst"
145+
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)