From 15d219d871f8b836fbc3b4bebd83614f60dc7d5c Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Mon, 4 Dec 2023 16:07:23 +0400 Subject: [PATCH 1/6] Fix the test that broke after 3.12 changes to locale.normalize - On Linux, C.UTF-8 locale is now part of the standard. macOS and Windows use en_US.UTF-8 instead. - Up to 3.11, `locale.normalize` was converting `C.UTF-8` into `en_US.UTF-8`. If you normalized the locale string, it was impossible to set `C.UTF-8`. - In 3.12, `C.UTF-8` maps to itself. - https://github.com/python/cpython/pull/14925 - https://peps.python.org/pep-0538/ - `C.UTF-8` doesn't seem to be used anywhere else in the codebase, except for this one test. - Other fix would be to inject a previous value to `locale.locale_alias` dictionary for certain platforms. However, this is part of the private implementation and could change without prior notice. - More changes to the locale are scheduled for 3.15. --- test/unit/b2http/test_b2http.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/unit/b2http/test_b2http.py b/test/unit/b2http/test_b2http.py index 4ab4da27b..038c0b4da 100644 --- a/test/unit/b2http/test_b2http.py +++ b/test/unit/b2http/test_b2http.py @@ -11,6 +11,7 @@ import datetime import locale +import sys from unittest.mock import MagicMock, call, patch import apiver_deps @@ -32,7 +33,6 @@ ) from b2sdk.b2http import setlocale - from ..test_base import TestBase @@ -306,9 +306,11 @@ class TestB2HttpUserAgentAppend(TestB2Http): class TestSetLocaleContextManager(TestBase): def test_set_locale_context_manager(self): - test_locale = locale.normalize( - 'C.utf8' - ) # C.UTF-8 on Ubuntu 18.04 Bionic, C.utf8 on Ubuntu 22.04 Jammy + # C.UTF-8 on Ubuntu 18.04 Bionic, C.utf8 on Ubuntu 22.04 Jammy + # Neither macOS nor Windows have C.UTF-8 locale, and they use `en_US.UTF-8`. + # Since Python 3.12, locale.normalize no longer falls back + # to the `en_US` version, so we're providing it here manually. + test_locale = locale.normalize('C.UTF-8' if sys.platform == 'linux' else 'en_US.UTF-8') other_locale = 'C' saved = locale.setlocale(locale.LC_ALL) From 811f2b9244e064437287b6eda0a9696fdaa22edf Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Mon, 4 Dec 2023 16:19:00 +0400 Subject: [PATCH 2/6] Format applied --- test/unit/b2http/test_b2http.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/b2http/test_b2http.py b/test/unit/b2http/test_b2http.py index 038c0b4da..d77c034a2 100644 --- a/test/unit/b2http/test_b2http.py +++ b/test/unit/b2http/test_b2http.py @@ -33,6 +33,7 @@ ) from b2sdk.b2http import setlocale + from ..test_base import TestBase From 0daf660c5f7e70bacf9d664f9f788a9e94efd72a Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Mon, 4 Dec 2023 16:23:09 +0400 Subject: [PATCH 3/6] Added changelog entry for towncrier --- changelog.d/py312-setlocale-fail.infrastructure.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/py312-setlocale-fail.infrastructure.md diff --git a/changelog.d/py312-setlocale-fail.infrastructure.md b/changelog.d/py312-setlocale-fail.infrastructure.md new file mode 100644 index 000000000..d13015278 --- /dev/null +++ b/changelog.d/py312-setlocale-fail.infrastructure.md @@ -0,0 +1 @@ +Fixed tests failing because of changes made to `locale.normalize` in Python 3.12. From b3a018c857fab3618722647d4fce523defc8954e Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Mon, 4 Dec 2023 16:41:16 +0400 Subject: [PATCH 4/6] Prepended + to the changelog filename, as it's not closing any GitHub ticket --- ....infrastructure.md => +py312-setlocale-fail.infrastructure.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{py312-setlocale-fail.infrastructure.md => +py312-setlocale-fail.infrastructure.md} (100%) diff --git a/changelog.d/py312-setlocale-fail.infrastructure.md b/changelog.d/+py312-setlocale-fail.infrastructure.md similarity index 100% rename from changelog.d/py312-setlocale-fail.infrastructure.md rename to changelog.d/+py312-setlocale-fail.infrastructure.md From 9e5de2002ec6c179a01ef1da3a4ada975f29c030 Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Tue, 5 Dec 2023 09:47:34 +0400 Subject: [PATCH 5/6] Removed TODO mentioning a broken locale in CI --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22723bdc6..bf1ef507c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,6 @@ jobs: python-version: "pypy-3.10" - os: "windows-latest" python-version: "pypy-3.10" - # TODO: 3.12 setlocale(...) is broken on Windows & Mac - os: "macos-latest" python-version: "3.12" - os: "windows-latest" From c94fde9811116d1de48968d94e38a7653eb3fa72 Mon Sep 17 00:00:00 2001 From: Krzysztof Kalinowski Date: Tue, 5 Dec 2023 13:24:38 +0400 Subject: [PATCH 6/6] Re-enabled 3.12 test matrix for both Windows and macOS --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf1ef507c..d4c9771ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,10 +92,6 @@ jobs: python-version: "pypy-3.10" - os: "windows-latest" python-version: "pypy-3.10" - - os: "macos-latest" - python-version: "3.12" - - os: "windows-latest" - python-version: "3.12" steps: - uses: actions/checkout@v3 with: