Mailing List Archive

bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750)
https://github.com/python/cpython/commit/abfc794bbf2c6a0939ddd81b6e700c46944ba87a
commit: abfc794bbf2c6a0939ddd81b6e700c46944ba87a
branch: main
author: Pablo Galindo Salgado <Pablogsal@gmail.com>
committer: pablogsal <Pablogsal@gmail.com>
date: 2021-11-24T18:30:03Z
summary:

bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750)

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 5e1619bf7dc9d..d51247003ded1 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -635,6 +635,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):

@@ -1017,14 +1025,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 c9ba148973162..0216c985415ce 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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*

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins