Skip to content

Commit 8ddf718

Browse files
authored
Special-case Alt Linux in tests (#88)
* Run tests on ALT Linux via GitHub Actions * Split asyncio test into altlinux and the rest. * Lint * De-duplicate code in test_import_tools.py
1 parent 174bcc0 commit 8ddf718

18 files changed

+352
-11
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This file is managed by 'repo_helper'. Don't edit it directly.
2+
---
3+
name: ALT Linux
4+
5+
on:
6+
push:
7+
branches-ignore:
8+
- 'repo-helper-update'
9+
- 'pre-commit-ci-update-config'
10+
- 'imgbot'
11+
tags:
12+
- '*'
13+
pull_request:
14+
15+
permissions:
16+
actions: write
17+
issues: write
18+
contents: read
19+
20+
jobs:
21+
tests:
22+
name: "alt-linux / Python ${{ matrix.config.python-version }}"
23+
runs-on: "ubuntu-20.04"
24+
container:
25+
image: ghcr.io/domdfcoding/alt-linux-python:latest
26+
continue-on-error: ${{ matrix.config.experimental }}
27+
env:
28+
USING_COVERAGE: '3.10'
29+
30+
strategy:
31+
fail-fast: False
32+
matrix:
33+
config:
34+
- {python-version: "3.10", testenvs: "py310,build", experimental: False}
35+
36+
steps:
37+
- name: Checkout πŸ›ŽοΈ
38+
uses: "actions/checkout@v3"
39+
40+
- name: "Configure"
41+
run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
42+
43+
- name: Check for changed files
44+
if: startsWith(github.ref, 'refs/tags/') != true
45+
uses: dorny/paths-filter@v2
46+
id: changes
47+
with:
48+
list-files: "json"
49+
filters: |
50+
code:
51+
- '!(doc-source/**|CONTRIBUTING.rst|.imgbotconfig|.pre-commit-config.yaml|.pylintrc|.readthedocs.yml)'
52+
53+
- name: Install dependencies πŸ”§
54+
id: setup-python
55+
if: ${{ steps.changes.outputs.code == 'true' || steps.changes.outcome == 'skipped' }}
56+
run: |
57+
python3 -VV
58+
python3 -m site
59+
python3 -m pip install --upgrade pip setuptools wheel
60+
python3 -m pip install --upgrade tox virtualenv!=20.16.0
61+
python3 -m pip install --upgrade coverage_pyver_pragma
62+
63+
- name: "Run Tests for Python ${{ matrix.config.python-version }}"
64+
if: steps.setup-python.outcome == 'success'
65+
run: python3 -m tox -e "${{ matrix.config.testenvs }}" -s false

β€Žtests/test_import_tools.py

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# stdlib
22
import inspect
3+
import platform
4+
import re
35
import sys
46
from contextlib import contextmanager
57

@@ -124,7 +126,7 @@ def test_discover_entry_points_by_name_name_match_func(advanced_data_regression:
124126
advanced_data_regression.check({k: v.__name__ for k, v in entry_points.items()})
125127

126128

127-
@pytest.mark.parametrize(
129+
iter_submodules_versions = pytest.mark.parametrize(
128130
"version",
129131
[
130132
pytest.param(3.6, marks=only_version(3.6, reason="Output differs on Python 3.6")),
@@ -173,18 +175,78 @@ def test_discover_entry_points_by_name_name_match_func(advanced_data_regression:
173175
pytest.param("3.10", marks=only_version("3.10", reason="Output differs on Python 3.10")),
174176
]
175177
)
178+
179+
180+
@iter_submodules_versions
176181
@pytest.mark.parametrize(
177182
"module",
178-
[
179-
"collections",
180-
"importlib",
181-
"domdf_python_tools",
182-
"consolekit",
183-
"asyncio",
184-
"json",
185-
"cRQefleMvm",
186-
"reprlib"
187-
],
183+
["collections", "importlib", "domdf_python_tools", "consolekit", "json", "cRQefleMvm", "reprlib"],
188184
)
189185
def test_iter_submodules(version, module: str, advanced_data_regression: AdvancedDataRegressionFixture):
190186
advanced_data_regression.check(list(iter_submodules(module)))
187+
188+
189+
if sys.version_info < (3, 10):
190+
# From https://github.com/python/cpython/blob/main/Lib/platform.py#L1319
191+
# License: https://github.com/python/cpython/blob/main/LICENSE
192+
193+
### freedesktop.org os-release standard
194+
# https://www.freedesktop.org/software/systemd/man/os-release.html
195+
196+
# NAME=value with optional quotes (' or "). The regular expression is less
197+
# strict than shell lexer, but that's ok.
198+
_os_release_line = re.compile("^(?P<name>[a-zA-Z0-9_]+)=(?P<quote>[\"']?)(?P<value>.*)(?P=quote)$")
199+
# unescape five special characters mentioned in the standard
200+
_os_release_unescape = re.compile(r"\\([\\\$\"\'`])")
201+
# /etc takes precedence over /usr/lib
202+
_os_release_candidates = ("/etc/os-release", "/usr/lib/os-release")
203+
204+
def freedesktop_os_release():
205+
"""
206+
Return operation system identification from freedesktop.org os-release
207+
"""
208+
209+
errno = None
210+
for candidate in _os_release_candidates:
211+
try:
212+
with open(candidate, encoding="utf-8") as f:
213+
info = {"ID": "linux"}
214+
215+
for line in f:
216+
mo = _os_release_line.match(line)
217+
if mo is not None:
218+
info[mo.group("name")] = _os_release_unescape.sub(r"\1", mo.group("value"))
219+
220+
return info
221+
222+
except OSError as e:
223+
errno = e.errno
224+
225+
raise OSError(errno, f"Unable to read files {', '.join(_os_release_candidates)}")
226+
227+
else:
228+
freedesktop_os_release = platform.freedesktop_os_release
229+
230+
on_alt_linux = False
231+
232+
if platform.system() == "Linux":
233+
try:
234+
on_alt_linux = freedesktop_os_release()["ID"] == "altlinux"
235+
except OSError:
236+
pass
237+
238+
239+
@iter_submodules_versions
240+
@pytest.mark.parametrize(
241+
"platform",
242+
[
243+
pytest.param('', marks=pytest.mark.skipif(on_alt_linux, reason="Not for ALT Linux")),
244+
pytest.param("altlinux", marks=pytest.mark.skipif(not on_alt_linux, reason="Only for ALT Linux")),
245+
]
246+
)
247+
def test_iter_submodules_asyncio(
248+
platform,
249+
version,
250+
advanced_data_regression: AdvancedDataRegressionFixture,
251+
):
252+
advanced_data_regression.check(list(iter_submodules("asyncio")))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
Β (0)