]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29759)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 11 Dec 2021 00:03:15 +0000 (16:03 -0800)
committerGitHub <noreply@github.com>
Sat, 11 Dec 2021 00:03:15 +0000 (01:03 +0100)
(cherry picked from commit abfc794bbf2c6a0939ddd81b6e700c46944ba87a)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_capi.py
Modules/_testcapimodule.c

index 23e65df67190c01892d0a2922b384d72f1a8d574..87f327414b54ed6aea6c1aee9558e16424a1a435 100644 (file)
@@ -549,6 +549,14 @@ class CAPITest(unittest.TestCase):
         s = _testcapi.pyobject_bytes_from_null()
         self.assertEqual(s, b'<NULL>')
 
+    def test_Py_CompileString(self):
+        # Check that Py_CompileString respects the coding cookie
+        _compile = _testcapi.Py_CompileString
+        code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
+        result = _compile(code)
+        expected = compile(code, "<string>", "exec")
+        self.assertEqual(result.co_consts, expected.co_consts)
+
 
 class TestPendingCalls(unittest.TestCase):
 
@@ -926,14 +934,6 @@ class Test_ModuleStateAccess(unittest.TestCase):
                 with self.assertRaises(TypeError):
                     increment_count(1, 2, 3)
 
-    def test_Py_CompileString(self):
-        # Check that Py_CompileString respects the coding cookie
-        _compile = _testcapi.Py_CompileString
-        code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
-        result = _compile(code)
-        expected = compile(code, "<string>", "exec")
-        self.assertEqual(result.co_consts, expected.co_consts)
-
 
 if __name__ == "__main__":
     unittest.main()
index d1f756395373da1a00feedace72401f90bd09a8d..ad1b07454355edfc1ca596d023331c05b7b5de80 100644 (file)
@@ -339,7 +339,7 @@ pycompilestring(PyObject* self, PyObject *obj) {
     if (the_string == NULL) {
         return NULL;
     }
-    return Py_CompileString(the_string, "blech", Py_file_input);
+    return Py_CompileString(the_string, "<string>", Py_file_input);
 }
 
 static PyObject*