Skip to content

Commit e1e3f64

Browse files
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29758)
(cherry picked from commit abfc794) Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 4b224e8 commit e1e3f64

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Lib/test/test_capi.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,14 @@ def test_pyobject_bytes_from_null(self):
631631
s = _testcapi.pyobject_bytes_from_null()
632632
self.assertEqual(s, b'<NULL>')
633633

634+
def test_Py_CompileString(self):
635+
# Check that Py_CompileString respects the coding cookie
636+
_compile = _testcapi.Py_CompileString
637+
code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
638+
result = _compile(code)
639+
expected = compile(code, "<string>", "exec")
640+
self.assertEqual(result.co_consts, expected.co_consts)
641+
634642

635643
class TestPendingCalls(unittest.TestCase):
636644

@@ -1013,14 +1021,6 @@ def test_state_access(self):
10131021
with self.assertRaises(TypeError):
10141022
increment_count(1, 2, 3)
10151023

1016-
def test_Py_CompileString(self):
1017-
# Check that Py_CompileString respects the coding cookie
1018-
_compile = _testcapi.Py_CompileString
1019-
code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
1020-
result = _compile(code)
1021-
expected = compile(code, "<string>", "exec")
1022-
self.assertEqual(result.co_consts, expected.co_consts)
1023-
10241024

10251025
if __name__ == "__main__":
10261026
unittest.main()

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ pycompilestring(PyObject* self, PyObject *obj) {
400400
if (the_string == NULL) {
401401
return NULL;
402402
}
403-
return Py_CompileString(the_string, "blech", Py_file_input);
403+
return Py_CompileString(the_string, "<string>", Py_file_input);
404404
}
405405

406406
static PyObject*

0 commit comments

Comments
 (0)