From fcadf2da45e28c1a39bd7f3ecf39f35abe5edbc7 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Wed, 24 Nov 2021 18:30:03 +0000 Subject: [PATCH] bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (cherry picked from commit abfc794bbf2c6a0939ddd81b6e700c46944ba87a) Co-authored-by: Pablo Galindo Salgado --- Lib/test/test_capi.py | 16 ++++++++-------- Modules/_testcapimodule.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 23e65df67190c01..87f327414b54ed6 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -549,6 +549,14 @@ def test_pyobject_bytes_from_null(self): s = _testcapi.pyobject_bytes_from_null() self.assertEqual(s, b'') + 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, "", "exec") + self.assertEqual(result.co_consts, expected.co_consts) + class TestPendingCalls(unittest.TestCase): @@ -926,14 +934,6 @@ def test_state_access(self): 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, "", "exec") - self.assertEqual(result.co_consts, expected.co_consts) - if __name__ == "__main__": unittest.main() diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index d1f756395373da1..ad1b07454355edf 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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, "", Py_file_input); } static PyObject*