]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Wed, 24 Nov 2021 18:30:03 +0000 (18:30 +0000)
committerGitHub <noreply@github.com>
Wed, 24 Nov 2021 18:30:03 +0000 (18:30 +0000)
Lib/test/test_capi.py
Modules/_testcapimodule.c

index 5e1619bf7dc9da9f4376f101ce6ffc2865fab28c..d51247003ded1c8d462bc91ef5b845dc24bbde0b 100644 (file)
@@ -635,6 +635,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):
 
@@ -1017,14 +1025,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 c9ba1489731622530ed1f4031a174496f69bfbcd..0216c985415ce4d5fda758331fd24139c3d920e5 100644 (file)
@@ -391,7 +391,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*