diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-11 00:02:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-11 00:02:56 (GMT) |
commit | e1e3f648ad6ab467356d2d14e1d208583c1a76c6 (patch) | |
tree | c0150f3e23ab5cc8b120373fa3ac0ecfb36afd7d | |
parent | 4b224e8729365c3f0b1901cc2217e9591719a332 (diff) | |
download | cpython-e1e3f648ad6ab467356d2d14e1d208583c1a76c6.zip cpython-e1e3f648ad6ab467356d2d14e1d208583c1a76c6.tar.gz cpython-e1e3f648ad6ab467356d2d14e1d208583c1a76c6.tar.bz2 |
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29758)
(cherry picked from commit abfc794bbf2c6a0939ddd81b6e700c46944ba87a)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
-rw-r--r-- | Lib/test/test_capi.py | 16 | ||||
-rw-r--r-- | 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 974e3d0..b5cb3ad 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -631,6 +631,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): @@ -1013,14 +1021,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() diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 9f25b64..c5c9428 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -400,7 +400,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* |