]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96272: Replace `test_source_encoding`'s `test_pep263` with `test_import_encoded_mo...
authorMichael Droettboom <mdboom@gmail.com>
Thu, 25 Aug 2022 19:19:16 +0000 (15:19 -0400)
committerGitHub <noreply@github.com>
Thu, 25 Aug 2022 19:19:16 +0000 (14:19 -0500)
Editors don't agree that `test_source_encoding.py` was valid koi8-r, making it
hard to edit that file without the editor breaking it in some way (see gh-96272).

Only one test actually relied on the koi8-r encoding and it was a duplicate of a
test from the deprecated `imp` module's `test_imp`, so here we replace
`test_pep263` with `test_import_encoded_module` stolen from `test_imp` and
set `test_source_encoding.py`'s encoding to utf-8 to make editing it easier
going forward.

Lib/test/test_imp.py
Lib/test/test_source_encoding.py

index d44dc6b49f2935bbb0392e9df3f2bf082fc7dbdf..35b6afa91ebd4f804fbbd245b605b28445ab0afe 100644 (file)
@@ -66,11 +66,7 @@ class ImportTests(unittest.TestCase):
         self.test_strings = mod.test_strings
         self.test_path = mod.__path__
 
-    def test_import_encoded_module(self):
-        for modname, encoding, teststr in self.test_strings:
-            mod = importlib.import_module('test.encoded_modules.'
-                                          'module_' + modname)
-            self.assertEqual(teststr, mod.test)
+    # test_import_encoded_module moved to test_source_encoding.py
 
     def test_find_module_encoding(self):
         for mod, encoding, _ in self.test_strings:
index 8d7b573c7e915b9dbf039d5f1faad73b8622fc2a..8e68b4eae3300381c67469340a1e700107d3427a 100644 (file)
@@ -1,4 +1,4 @@
-# -*- coding: koi8-r -*-
+# -*- coding: utf-8 -*-
 
 import unittest
 from test.support import script_helper, captured_stdout, requires_subprocess
@@ -12,15 +12,14 @@ import tempfile
 
 class MiscSourceEncodingTest(unittest.TestCase):
 
-    def test_pep263(self):
-        self.assertEqual(
-            "ðÉÔÏÎ".encode("utf-8"),
-            b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
-        )
-        self.assertEqual(
-            "\ð".encode("utf-8"),
-            b'\\\xd0\x9f'
-        )
+    def test_import_encoded_module(self):
+        from test.encoded_modules import test_strings
+        # Make sure we're actually testing something
+        self.assertGreaterEqual(len(test_strings), 1)
+        for modname, encoding, teststr in test_strings:
+            mod = importlib.import_module('test.encoded_modules.'
+                                          'module_' + modname)
+            self.assertEqual(teststr, mod.test)
 
     def test_compilestring(self):
         # see #1882