Skip to content

Commit abfc794

Browse files
authored
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750)
1 parent b30bf45 commit abfc794

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
@@ -635,6 +635,14 @@ def test_pyobject_bytes_from_null(self):
635635
s = _testcapi.pyobject_bytes_from_null()
636636
self.assertEqual(s, b'<NULL>')
637637

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

639647
class TestPendingCalls(unittest.TestCase):
640648

@@ -1017,14 +1025,6 @@ def test_state_access(self):
10171025
with self.assertRaises(TypeError):
10181026
increment_count(1, 2, 3)
10191027

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

10291029
if __name__ == "__main__":
10301030
unittest.main()

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pycompilestring(PyObject* self, PyObject *obj) {
391391
if (the_string == NULL) {
392392
return NULL;
393393
}
394-
return Py_CompileString(the_string, "blech", Py_file_input);
394+
return Py_CompileString(the_string, "<string>", Py_file_input);
395395
}
396396

397397
static PyObject*

0 commit comments

Comments
 (0)