Skip to content

Commit da61843

Browse files
gotmax23domdfcodingpre-commit-ci[bot]
authored
Fix Python 3.14 test failures (#137)
* tests: fix pathlib.PurePosixPath repr on py3.14 ``` fish for i in python3.{9,10,11,12,13,14} echo -n "$i " $i -c 'import pathlib; print(repr(pathlib.PurePosixPath))' end ``` ``` python3.9 <class 'pathlib.PurePosixPath'> python3.10 <class 'pathlib.PurePosixPath'> python3.11 <class 'pathlib.PurePosixPath'> python3.12 <class 'pathlib.PurePosixPath'> python3.13 <class 'pathlib._local.PurePosixPath'> python3.14 <class 'pathlib.PurePosixPath'> ``` * words: fix alphabet_sort exception handling for py3.14 As of python/cpython#121395, the format of the list.index exception has changed and parsing it like this no longer works. Relying on implementation details like this is always risky, so this solution should be more future-proof. * Skip pathlib.PurePath for from_uri test in Python 3.13 * Configure testing on Python 3.14 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Dominic Davis-Foster <dominic@davis-foster.co.uk> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c219013 commit da61843

File tree

9 files changed

+27
-15
lines changed

9 files changed

+27
-15
lines changed

.github/workflows/python_ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: "windows-2022"
2323
continue-on-error: ${{ matrix.config.experimental }}
2424
env:
25-
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
25+
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,3.14,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
2626

2727
strategy:
2828
fail-fast: False
@@ -35,6 +35,7 @@ jobs:
3535
- {python-version: "3.11", testenvs: "py311,build", experimental: False}
3636
- {python-version: "3.12", testenvs: "py312,build", experimental: False}
3737
- {python-version: "3.13", testenvs: "py313,build", experimental: False}
38+
- {python-version: "3.14", testenvs: "py314,build", experimental: False}
3839
- {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False}
3940
- {python-version: "pypy-3.8", testenvs: "pypy38", experimental: False}
4041
- {python-version: "pypy-3.9-v7.3.15", testenvs: "pypy39", experimental: True}

.github/workflows/python_ci_linux.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: "ubuntu-22.04"
2424
continue-on-error: ${{ matrix.config.experimental }}
2525
env:
26-
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
26+
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,3.14,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
2727

2828
strategy:
2929
fail-fast: False
@@ -36,6 +36,7 @@ jobs:
3636
- {python-version: "3.11", testenvs: "py311,build", experimental: False}
3737
- {python-version: "3.12", testenvs: "py312,build", experimental: False}
3838
- {python-version: "3.13", testenvs: "py313,build", experimental: False}
39+
- {python-version: "3.14", testenvs: "py314,build", experimental: False}
3940
- {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False}
4041
- {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False}
4142
- {python-version: "pypy-3.9", testenvs: "pypy39", experimental: True}

.github/workflows/python_ci_macos.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: "macos-${{ matrix.config.os-ver }}"
2323
continue-on-error: ${{ matrix.config.experimental }}
2424
env:
25-
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
25+
USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,3.14,pypy-3.7,pypy-3.8,pypy-3.9,pypy-3.10'
2626

2727
strategy:
2828
fail-fast: False
@@ -35,6 +35,7 @@ jobs:
3535
- {python-version: "3.11", os-ver: "14", testenvs: "py311,build", experimental: False}
3636
- {python-version: "3.12", os-ver: "14", testenvs: "py312,build", experimental: False}
3737
- {python-version: "3.13", os-ver: "14", testenvs: "py313,build", experimental: False}
38+
- {python-version: "3.14", os-ver: "14", testenvs: "py314,build", experimental: False}
3839
- {python-version: "pypy-3.7", os-ver: "15-intel", testenvs: "pypy37,build", experimental: False}
3940
- {python-version: "pypy-3.8", os-ver: "14", testenvs: "pypy38,build", experimental: False}
4041
- {python-version: "pypy-3.9", os-ver: "14", testenvs: "pypy39", experimental: True}

domdf_python_tools/words.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,13 @@ def alpha_sort(
171171

172172
alphabet_ = list(alphabet)
173173

174-
try:
175-
return sorted(iterable, key=lambda attr: [alphabet_.index(letter) for letter in attr], reverse=reverse)
176-
except ValueError as e:
177-
m = re.match(r"'(.*)' is not in list", str(e))
178-
if m:
179-
raise ValueError(f"The character {m.group(1)!r} was not found in the alphabet.") from None
180-
else: # pragma: no cover
181-
raise e
174+
def _alphabet_index(letter: str) -> int:
175+
try:
176+
return alphabet_.index(letter)
177+
except ValueError:
178+
raise ValueError(f"The character {letter!r} was not found in the alphabet.") from None
179+
180+
return sorted(iterable, key=lambda attr: [_alphabet_index(letter) for letter in attr], reverse=reverse)
182181

183182

184183
class Font(Dict[str, str]):

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ classifiers = [
2323
"Programming Language :: Python :: 3.11",
2424
"Programming Language :: Python :: 3.12",
2525
"Programming Language :: Python :: 3.13",
26+
"Programming Language :: Python :: 3.14",
2627
"Programming Language :: Python :: Implementation :: CPython",
2728
"Programming Language :: Python :: Implementation :: PyPy",
2829
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -142,7 +143,7 @@ base-classifiers = [
142143
"Topic :: Software Development :: Libraries :: Python Modules",
143144
"Typing :: Typed",
144145
]
145-
python-versions = [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13",]
146+
python-versions = [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14",]
146147
python-implementations = [ "CPython", "PyPy",]
147148
platforms = [ "Windows", "macOS", "Linux",]
148149
license-key = "MIT"

repo_helper.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ python_versions:
2525
"3.11":
2626
"3.12":
2727
"3.13":
28+
"3.14":
2829
pypy37:
2930
pypy38:
3031
pypy39:

tests/test_paths.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# 3rd party
2121
import pytest
2222
from coincidence.regressions import AdvancedDataRegressionFixture
23-
from coincidence.selectors import not_pypy, not_windows, only_windows
23+
from coincidence.selectors import max_version, not_pypy, not_windows, only_windows
2424

2525
# this package
2626
from domdf_python_tools import paths
@@ -925,7 +925,13 @@ def test_sort_paths():
925925

926926

927927
@pytest.mark.parametrize("path", _from_uri_paths)
928-
@pytest.mark.parametrize("left_type", [pathlib.PurePath, pathlib.Path, PathPlus])
928+
@pytest.mark.parametrize(
929+
"left_type", [
930+
pytest.param(pathlib.PurePath, marks=max_version((3, 13))),
931+
pathlib.Path,
932+
PathPlus,
933+
]
934+
)
929935
def test_pathplus_from_uri(path: str, left_type: Type):
930936
assert PathPlus.from_uri(left_type(path).as_uri()).as_posix() == path
931937

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_printr(obj, expects, capsys):
124124
assert re.match(expects, stdout[0])
125125

126126

127-
if sys.version_info >= (3, 13):
127+
if sys.version_info[:2] == (3, 13):
128128
pure_posix_path_expected = "<class 'pathlib._local.PurePosixPath'>"
129129
else:
130130
pure_posix_path_expected = "<class 'pathlib.PurePosixPath'>"

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ envlist =
2929
py311
3030
py312
3131
py313
32+
py314
3233
pypy37
3334
pypy38
3435
pypy39
@@ -52,6 +53,7 @@ test =
5253
py311
5354
py312
5455
py313
56+
py314
5557
pypy37
5658
pypy38
5759
pypy39

0 commit comments

Comments
 (0)