[Python-checkins] bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29759)
ambv
webhook-mailer at python.org
Fri Dec 10 19:03:20 EST 2021
https://github.com/python/cpython/commit/5f622f1d5c5425ed1e992da6611edfb486a9bf7c
commit: 5f622f1d5c5425ed1e992da6611edfb486a9bf7c
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-12-11T01:03:15+01:00
summary:
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29759)
(cherry picked from commit abfc794bbf2c6a0939ddd81b6e700c46944ba87a)
Co-authored-by: Pablo Galindo Salgado <Pablogsal at gmail.com>
files:
M Lib/test/test_capi.py
M Modules/_testcapimodule.c
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 23e65df67190c..87f327414b54e 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'<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 @@ 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, "<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 d1f756395373d..ad1b07454355e 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, "<string>", Py_file_input);
}
static PyObject*
More information about the Python-checkins
mailing list