]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-108303: Fix and move `badsyntax_pep3120.py` (GH-109513) (#109724)
authorNikita Sobolev <mail@sobolevn.me>
Fri, 22 Sep 2023 15:50:32 +0000 (18:50 +0300)
committerGitHub <noreply@github.com>
Fri, 22 Sep 2023 15:50:32 +0000 (17:50 +0200)
* [3.11] gh-108303: Fix and move `badsyntax_pep3120.py` (GH-109513)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>.
(cherry picked from commit 4dd47c63a97b3c39cd964ad12431fcdaf76dc823)

Backport to 3.11: update also test_imp.

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/.ruff.toml
Lib/test/test_imp.py
Lib/test/test_utf8source.py
Lib/test/tokenizedata/badsyntax_pep3120.py [moved from Lib/test/badsyntax_pep3120.py with 100% similarity]

index 08bd5c8a87ee217e12a68eaf156d6d983a7c44c4..0afa0fe36b0ce4090724837444f5e6cafb34f870 100644 (file)
@@ -3,13 +3,13 @@ select = [
     "F811",  # Redefinition of unused variable (useful for finding test methods with the same name)
 ]
 extend-exclude = [
+    # Excluded (these aren't actually executed, they're just "data files")
+    "tokenizedata/*.py",
     # Failed to lint
-    "badsyntax_pep3120.py",
     "encoded_modules/module_iso_8859_1.py",
     "encoded_modules/module_koi8_r.py",
     "test_source_encoding.py",
     # Failed to parse
-    "badsyntax_3131.py",
     "test_fstring.py",
     # TODO Fix: F811 Redefinition of unused name
     "test_buffer.py",
index 4bb03908fc2bb27ffb38deff4832fab3d33e8b10..4062afd725487028c3514ed434f3207fcda96ead 100644 (file)
@@ -78,7 +78,7 @@ class ImportTests(unittest.TestCase):
             with imp.find_module('module_' + mod, self.test_path)[0] as fd:
                 self.assertEqual(fd.encoding, encoding)
 
-        path = [os.path.dirname(__file__)]
+        path = [os.path.join(os.path.dirname(__file__), 'tokenizedata')]
         with self.assertRaises(SyntaxError):
             imp.find_module('badsyntax_pep3120', path)
 
@@ -203,9 +203,11 @@ class ImportTests(unittest.TestCase):
             os_helper.rmtree('__pycache__')
 
     def test_issue9319(self):
-        path = os.path.dirname(__file__)
+        path = os.path.join(os.path.dirname(__file__), "tokenizedata")
         self.assertRaises(SyntaxError,
-                          imp.find_module, "badsyntax_pep3120", [path])
+                          imp.find_module,
+                          "badsyntax_pep3120",
+                          [path])
 
     def test_load_from_source(self):
         # Verify that the imp module can correctly load and find .py files
index 97dced8a6228890490f5659b5496b2befff0aab1..c42b6aaaab579d45ffa5a15abd2e430332b14639 100644 (file)
@@ -1,5 +1,3 @@
-# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
-
 import unittest
 
 class PEP3120Test(unittest.TestCase):
@@ -16,7 +14,7 @@ class PEP3120Test(unittest.TestCase):
 
     def test_badsyntax(self):
         try:
-            import test.badsyntax_pep3120
+            import test.tokenizedata.badsyntax_pep3120
         except SyntaxError as msg:
             msg = str(msg).lower()
             self.assertTrue('utf-8' in msg)