Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down