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
+65
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

+73-11
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")))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- asyncio
2+
- asyncio.__main__
3+
- asyncio.base_events
4+
- asyncio.base_futures
5+
- asyncio.base_subprocess
6+
- asyncio.base_tasks
7+
- asyncio.constants
8+
- asyncio.coroutines
9+
- asyncio.events
10+
- asyncio.exceptions
11+
- asyncio.format_helpers
12+
- asyncio.futures
13+
- asyncio.locks
14+
- asyncio.log
15+
- asyncio.mixins
16+
- asyncio.proactor_events
17+
- asyncio.protocols
18+
- asyncio.queues
19+
- asyncio.runners
20+
- asyncio.selector_events
21+
- asyncio.sslproto
22+
- asyncio.staggered
23+
- asyncio.streams
24+
- asyncio.subprocess
25+
- asyncio.tasks
26+
- asyncio.threads
27+
- asyncio.transports
28+
- asyncio.trsock
29+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- asyncio
2+
- asyncio.base_events
3+
- asyncio.base_futures
4+
- asyncio.base_subprocess
5+
- asyncio.base_tasks
6+
- asyncio.compat
7+
- asyncio.constants
8+
- asyncio.coroutines
9+
- asyncio.events
10+
- asyncio.futures
11+
- asyncio.locks
12+
- asyncio.log
13+
- asyncio.proactor_events
14+
- asyncio.protocols
15+
- asyncio.queues
16+
- asyncio.selector_events
17+
- asyncio.sslproto
18+
- asyncio.streams
19+
- asyncio.subprocess
20+
- asyncio.tasks
21+
- asyncio.test_utils
22+
- asyncio.transports
23+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- asyncio
2+
- asyncio.base_events
3+
- asyncio.base_futures
4+
- asyncio.base_subprocess
5+
- asyncio.base_tasks
6+
- asyncio.constants
7+
- asyncio.coroutines
8+
- asyncio.events
9+
- asyncio.format_helpers
10+
- asyncio.futures
11+
- asyncio.locks
12+
- asyncio.log
13+
- asyncio.proactor_events
14+
- asyncio.protocols
15+
- asyncio.queues
16+
- asyncio.runners
17+
- asyncio.selector_events
18+
- asyncio.sslproto
19+
- asyncio.streams
20+
- asyncio.subprocess
21+
- asyncio.tasks
22+
- asyncio.transports
23+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- asyncio
2+
- asyncio.base_events
3+
- asyncio.base_futures
4+
- asyncio.base_subprocess
5+
- asyncio.base_tasks
6+
- asyncio.compat
7+
- asyncio.constants
8+
- asyncio.coroutines
9+
- asyncio.events
10+
- asyncio.format_helpers
11+
- asyncio.futures
12+
- asyncio.locks
13+
- asyncio.log
14+
- asyncio.proactor_events
15+
- asyncio.protocols
16+
- asyncio.queues
17+
- asyncio.runners
18+
- asyncio.selector_events
19+
- asyncio.sslproto
20+
- asyncio.streams
21+
- asyncio.subprocess
22+
- asyncio.tasks
23+
- asyncio.test_utils
24+
- asyncio.transports
25+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- asyncio
2+
- asyncio.__main__
3+
- asyncio.base_events
4+
- asyncio.base_futures
5+
- asyncio.base_subprocess
6+
- asyncio.base_tasks
7+
- asyncio.constants
8+
- asyncio.coroutines
9+
- asyncio.events
10+
- asyncio.exceptions
11+
- asyncio.format_helpers
12+
- asyncio.futures
13+
- asyncio.locks
14+
- asyncio.log
15+
- asyncio.proactor_events
16+
- asyncio.protocols
17+
- asyncio.queues
18+
- asyncio.runners
19+
- asyncio.selector_events
20+
- asyncio.sslproto
21+
- asyncio.staggered
22+
- asyncio.streams
23+
- asyncio.subprocess
24+
- asyncio.tasks
25+
- asyncio.transports
26+
- asyncio.trsock
27+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- asyncio
2+
- asyncio.__main__
3+
- asyncio.base_events
4+
- asyncio.base_futures
5+
- asyncio.base_subprocess
6+
- asyncio.base_tasks
7+
- asyncio.compat
8+
- asyncio.constants
9+
- asyncio.coroutines
10+
- asyncio.events
11+
- asyncio.exceptions
12+
- asyncio.format_helpers
13+
- asyncio.futures
14+
- asyncio.locks
15+
- asyncio.log
16+
- asyncio.proactor_events
17+
- asyncio.protocols
18+
- asyncio.queues
19+
- asyncio.runners
20+
- asyncio.selector_events
21+
- asyncio.sslproto
22+
- asyncio.staggered
23+
- asyncio.streams
24+
- asyncio.subprocess
25+
- asyncio.tasks
26+
- asyncio.test_utils
27+
- asyncio.transports
28+
- asyncio.trsock
29+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- asyncio
2+
- asyncio.__main__
3+
- asyncio.base_events
4+
- asyncio.base_futures
5+
- asyncio.base_subprocess
6+
- asyncio.base_tasks
7+
- asyncio.constants
8+
- asyncio.coroutines
9+
- asyncio.events
10+
- asyncio.exceptions
11+
- asyncio.format_helpers
12+
- asyncio.futures
13+
- asyncio.locks
14+
- asyncio.log
15+
- asyncio.proactor_events
16+
- asyncio.protocols
17+
- asyncio.queues
18+
- asyncio.runners
19+
- asyncio.selector_events
20+
- asyncio.sslproto
21+
- asyncio.staggered
22+
- asyncio.streams
23+
- asyncio.subprocess
24+
- asyncio.tasks
25+
- asyncio.threads
26+
- asyncio.transports
27+
- asyncio.trsock
28+
- asyncio.unix_events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- asyncio
2+
- asyncio.__main__
3+
- asyncio.base_events
4+
- asyncio.base_futures
5+
- asyncio.base_subprocess
6+
- asyncio.base_tasks
7+
- asyncio.compat
8+
- asyncio.constants
9+
- asyncio.coroutines
10+
- asyncio.events
11+
- asyncio.exceptions
12+
- asyncio.format_helpers
13+
- asyncio.futures
14+
- asyncio.locks
15+
- asyncio.log
16+
- asyncio.proactor_events
17+
- asyncio.protocols
18+
- asyncio.queues
19+
- asyncio.runners
20+
- asyncio.selector_events
21+
- asyncio.sslproto
22+
- asyncio.staggered
23+
- asyncio.streams
24+
- asyncio.subprocess
25+
- asyncio.tasks
26+
- asyncio.test_utils
27+
- asyncio.threads
28+
- asyncio.transports
29+
- asyncio.trsock
30+
- asyncio.unix_events

0 commit comments

Comments
 (0)