Skip to content

Commit

Permalink
Special-case Alt Linux in tests (#88)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
domdfcoding committed Oct 3, 2022
1 parent 174bcc0 commit 8ddf718
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 11 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/python_ci_alt_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file is managed by 'repo_helper'. Don't edit it directly.
---
name: ALT Linux

on:
push:
branches-ignore:
- 'repo-helper-update'
- 'pre-commit-ci-update-config'
- 'imgbot'
tags:
- '*'
pull_request:

permissions:
actions: write
issues: write
contents: read

jobs:
tests:
name: "alt-linux / Python ${{ matrix.config.python-version }}"
runs-on: "ubuntu-20.04"
container:
image: ghcr.io/domdfcoding/alt-linux-python:latest
continue-on-error: ${{ matrix.config.experimental }}
env:
USING_COVERAGE: '3.10'

strategy:
fail-fast: False
matrix:
config:
- {python-version: "3.10", testenvs: "py310,build", experimental: False}

steps:
- name: Checkout 🛎️
uses: "actions/checkout@v3"

- name: "Configure"
run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}

- name: Check for changed files
if: startsWith(github.ref, 'refs/tags/') != true
uses: dorny/paths-filter@v2
id: changes
with:
list-files: "json"
filters: |
code:
- '!(doc-source/**|CONTRIBUTING.rst|.imgbotconfig|.pre-commit-config.yaml|.pylintrc|.readthedocs.yml)'
- name: Install dependencies 🔧
id: setup-python
if: ${{ steps.changes.outputs.code == 'true' || steps.changes.outcome == 'skipped' }}
run: |
python3 -VV
python3 -m site
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install --upgrade tox virtualenv!=20.16.0
python3 -m pip install --upgrade coverage_pyver_pragma
- name: "Run Tests for Python ${{ matrix.config.python-version }}"
if: steps.setup-python.outcome == 'success'
run: python3 -m tox -e "${{ matrix.config.testenvs }}" -s false
84 changes: 73 additions & 11 deletions tests/test_import_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# stdlib
import inspect
import platform
import re
import sys
from contextlib import contextmanager

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


@pytest.mark.parametrize(
iter_submodules_versions = pytest.mark.parametrize(
"version",
[
pytest.param(3.6, marks=only_version(3.6, reason="Output differs on Python 3.6")),
Expand Down Expand Up @@ -173,18 +175,78 @@ def test_discover_entry_points_by_name_name_match_func(advanced_data_regression:
pytest.param("3.10", marks=only_version("3.10", reason="Output differs on Python 3.10")),
]
)


@iter_submodules_versions
@pytest.mark.parametrize(
"module",
[
"collections",
"importlib",
"domdf_python_tools",
"consolekit",
"asyncio",
"json",
"cRQefleMvm",
"reprlib"
],
["collections", "importlib", "domdf_python_tools", "consolekit", "json", "cRQefleMvm", "reprlib"],
)
def test_iter_submodules(version, module: str, advanced_data_regression: AdvancedDataRegressionFixture):
advanced_data_regression.check(list(iter_submodules(module)))


if sys.version_info < (3, 10):
# From https://github.com/python/cpython/blob/main/Lib/platform.py#L1319
# License: https://github.com/python/cpython/blob/main/LICENSE

### freedesktop.org os-release standard
# https://www.freedesktop.org/software/systemd/man/os-release.html

# NAME=value with optional quotes (' or "). The regular expression is less
# strict than shell lexer, but that's ok.
_os_release_line = re.compile("^(?P<name>[a-zA-Z0-9_]+)=(?P<quote>[\"']?)(?P<value>.*)(?P=quote)$")
# unescape five special characters mentioned in the standard
_os_release_unescape = re.compile(r"\\([\\\$\"\'`])")
# /etc takes precedence over /usr/lib
_os_release_candidates = ("/etc/os-release", "/usr/lib/os-release")

def freedesktop_os_release():
"""
Return operation system identification from freedesktop.org os-release
"""

errno = None
for candidate in _os_release_candidates:
try:
with open(candidate, encoding="utf-8") as f:
info = {"ID": "linux"}

for line in f:
mo = _os_release_line.match(line)
if mo is not None:
info[mo.group("name")] = _os_release_unescape.sub(r"\1", mo.group("value"))

return info

except OSError as e:
errno = e.errno

raise OSError(errno, f"Unable to read files {', '.join(_os_release_candidates)}")

else:
freedesktop_os_release = platform.freedesktop_os_release

on_alt_linux = False

if platform.system() == "Linux":
try:
on_alt_linux = freedesktop_os_release()["ID"] == "altlinux"
except OSError:
pass


@iter_submodules_versions
@pytest.mark.parametrize(
"platform",
[
pytest.param('', marks=pytest.mark.skipif(on_alt_linux, reason="Not for ALT Linux")),
pytest.param("altlinux", marks=pytest.mark.skipif(not on_alt_linux, reason="Only for ALT Linux")),
]
)
def test_iter_submodules_asyncio(
platform,
version,
advanced_data_regression: AdvancedDataRegressionFixture,
):
advanced_data_regression.check(list(iter_submodules("asyncio")))
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- asyncio
- asyncio.__main__
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.exceptions
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.mixins
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.staggered
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.threads
- asyncio.transports
- asyncio.trsock
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- asyncio
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.compat
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.selector_events
- asyncio.sslproto
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.test_utils
- asyncio.transports
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- asyncio
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.transports
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- asyncio
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.compat
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.test_utils
- asyncio.transports
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- asyncio
- asyncio.__main__
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.exceptions
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.staggered
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.transports
- asyncio.trsock
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- asyncio
- asyncio.__main__
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.compat
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.exceptions
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.staggered
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.test_utils
- asyncio.transports
- asyncio.trsock
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- asyncio
- asyncio.__main__
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.exceptions
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.staggered
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.threads
- asyncio.transports
- asyncio.trsock
- asyncio.unix_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- asyncio
- asyncio.__main__
- asyncio.base_events
- asyncio.base_futures
- asyncio.base_subprocess
- asyncio.base_tasks
- asyncio.compat
- asyncio.constants
- asyncio.coroutines
- asyncio.events
- asyncio.exceptions
- asyncio.format_helpers
- asyncio.futures
- asyncio.locks
- asyncio.log
- asyncio.proactor_events
- asyncio.protocols
- asyncio.queues
- asyncio.runners
- asyncio.selector_events
- asyncio.sslproto
- asyncio.staggered
- asyncio.streams
- asyncio.subprocess
- asyncio.tasks
- asyncio.test_utils
- asyncio.threads
- asyncio.transports
- asyncio.trsock
- asyncio.unix_events

0 comments on commit 8ddf718

Please sign in to comment.