From 46c025d40fd8c2c335e5240e65612285ccfd677a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 27 May 2025 09:25:20 +0200 Subject: [PATCH 1/3] gh-62824: Adjust test_alias_modules_exist test to allow .pyc codec files In Fedora, we install many codecs as .pyc files to save space. This test was failing when running from installed Python: ====================================================================== FAIL: test_alias_modules_exist (test.test_codecs.TransformCodecTest.test_alias_modules_exist) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python3.14/test/test_codecs.py", line 3115, in test_alias_modules_exist self.assertTrue(os.path.isfile(codec_file), ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "Codec file not found: " + codec_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: False is not true : Codec file not found: /usr/lib64/python3.14/encodings/cp037.py ---------------------------------------------------------------------- --- Lib/test/test_codecs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 8c9a0972492294..eda88f2aadfa88 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3112,7 +3112,9 @@ def test_alias_modules_exist(self): encodings_dir = os.path.dirname(encodings.__file__) for value in encodings.aliases.aliases.values(): codec_file = os.path.join(encodings_dir, value + ".py") - self.assertTrue(os.path.isfile(codec_file), + pyc_file = codec_file + "c" + self.assertTrue(os.path.isfile(codec_file) + or os.path.isfile(pyc_file), "Codec file not found: " + codec_file) def test_quopri_stateless(self): From 21c1e40def3481b12cb89defaa575b5f06ab95b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 27 May 2025 09:47:08 +0200 Subject: [PATCH 2/3] Look for modules in test_alias_modules_exist, not files --- Lib/test/test_codecs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index eda88f2aadfa88..7be08e0e287679 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1,6 +1,7 @@ import codecs import contextlib import copy +import importlib import io import pickle import os @@ -3111,11 +3112,9 @@ def test_aliases(self): def test_alias_modules_exist(self): encodings_dir = os.path.dirname(encodings.__file__) for value in encodings.aliases.aliases.values(): - codec_file = os.path.join(encodings_dir, value + ".py") - pyc_file = codec_file + "c" - self.assertTrue(os.path.isfile(codec_file) - or os.path.isfile(pyc_file), - "Codec file not found: " + codec_file) + codec_mod = f"encodings.{value}" + self.assertIsNotNone(importlib.util.find_spec(codec_mod), + "Codec module not found: " + codec_mod) def test_quopri_stateless(self): # Should encode with quotetabs=True From 660660ee39027d4ae86d169fbcc9c45dcd892687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 27 May 2025 09:49:01 +0200 Subject: [PATCH 3/3] Use more f-strings --- Lib/test/test_codecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 7be08e0e287679..d8666f7290e72e 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3114,7 +3114,7 @@ def test_alias_modules_exist(self): for value in encodings.aliases.aliases.values(): codec_mod = f"encodings.{value}" self.assertIsNotNone(importlib.util.find_spec(codec_mod), - "Codec module not found: " + codec_mod) + f"Codec module not found: {codec_mod}") def test_quopri_stateless(self): # Should encode with quotetabs=True