|
1 | 1 | # stdlib
|
2 | 2 | import inspect
|
| 3 | +import platform |
| 4 | +import re |
3 | 5 | import sys
|
4 | 6 | from contextlib import contextmanager
|
5 | 7 |
|
@@ -124,7 +126,7 @@ def test_discover_entry_points_by_name_name_match_func(advanced_data_regression:
|
124 | 126 | advanced_data_regression.check({k: v.__name__ for k, v in entry_points.items()})
|
125 | 127 |
|
126 | 128 |
|
127 |
| -@pytest.mark.parametrize( |
| 129 | +iter_submodules_versions = pytest.mark.parametrize( |
128 | 130 | "version",
|
129 | 131 | [
|
130 | 132 | 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:
|
173 | 175 | pytest.param("3.10", marks=only_version("3.10", reason="Output differs on Python 3.10")),
|
174 | 176 | ]
|
175 | 177 | )
|
| 178 | + |
| 179 | + |
| 180 | +@iter_submodules_versions |
176 | 181 | @pytest.mark.parametrize(
|
177 | 182 | "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"], |
188 | 184 | )
|
189 | 185 | def test_iter_submodules(version, module: str, advanced_data_regression: AdvancedDataRegressionFixture):
|
190 | 186 | 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"))) |
0 commit comments