summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-11-24 18:30:03 (GMT)
committerGitHub <noreply@github.com>2021-11-24 18:30:03 (GMT)
commitabfc794bbf2c6a0939ddd81b6e700c46944ba87a (patch)
treec82ad4145f5b3b067eb346efa641cd993cbba905
parentb30bf4520ae9d6e7eca09d812dd8a86c020b9202 (diff)
downloadcpython-abfc794bbf2c6a0939ddd81b6e700c46944ba87a.zip
cpython-abfc794bbf2c6a0939ddd81b6e700c46944ba87a.tar.gz
cpython-abfc794bbf2c6a0939ddd81b6e700c46944ba87a.tar.bz2
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750)
-rw-r--r--Lib/test/test_capi.py16
-rw-r--r--Modules/_testcapimodule.c2
2 files changed, 9 insertions, 9 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 5e1619b..d512470 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -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()
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index c9ba148..0216c98 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*