Skip to content

Commit 8704d6b

Browse files
authored
pythongh-62824: Adjust test_alias_modules_exist test to use imports instead of file checks (python#134777)
1 parent 92ea1eb commit 8704d6b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Lib/test/test_codecs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import codecs
22
import contextlib
33
import copy
4+
import importlib
45
import io
56
import pickle
67
import os
@@ -3111,9 +3112,9 @@ def test_aliases(self):
31113112
def test_alias_modules_exist(self):
31123113
encodings_dir = os.path.dirname(encodings.__file__)
31133114
for value in encodings.aliases.aliases.values():
3114-
codec_file = os.path.join(encodings_dir, value + ".py")
3115-
self.assertTrue(os.path.isfile(codec_file),
3116-
"Codec file not found: " + codec_file)
3115+
codec_mod = f"encodings.{value}"
3116+
self.assertIsNotNone(importlib.util.find_spec(codec_mod),
3117+
f"Codec module not found: {codec_mod}")
31173118

31183119
def test_quopri_stateless(self):
31193120
# Should encode with quotetabs=True

0 commit comments

Comments
 (0)