Skip to content

Commit fcadf2d

Browse files
pablogsalmiss-islington
authored andcommitted
bpo-45822: Minor cleanups to the test_Py_CompileString test (pythonGH-29750)
(cherry picked from commit abfc794) Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 455ed45 commit fcadf2d

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
@@ -549,6 +549,14 @@ def test_pyobject_bytes_from_null(self):
549549
s = _testcapi.pyobject_bytes_from_null()
550550
self.assertEqual(s, b'<NULL>')
551551

552+
def test_Py_CompileString(self):
553+
# Check that Py_CompileString respects the coding cookie
554+
_compile = _testcapi.Py_CompileString
555+
code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
556+
result = _compile(code)
557+
expected = compile(code, "<string>", "exec")
558+
self.assertEqual(result.co_consts, expected.co_consts)
559+
552560

553561
class TestPendingCalls(unittest.TestCase):
554562

@@ -926,14 +934,6 @@ def test_state_access(self):
926934
with self.assertRaises(TypeError):
927935
increment_count(1, 2, 3)
928936

929-
def test_Py_CompileString(self):
930-
# Check that Py_CompileString respects the coding cookie
931-
_compile = _testcapi.Py_CompileString
932-
code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
933-
result = _compile(code)
934-
expected = compile(code, "<string>", "exec")
935-
self.assertEqual(result.co_consts, expected.co_consts)
936-
937937

938938
if __name__ == "__main__":
939939
unittest.main()

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pycompilestring(PyObject* self, PyObject *obj) {
339339
if (the_string == NULL) {
340340
return NULL;
341341
}
342-
return Py_CompileString(the_string, "blech", Py_file_input);
342+
return Py_CompileString(the_string, "<string>", Py_file_input);
343343
}
344344

345345
static PyObject*

0 commit comments

Comments
 (0)