mirror of
https://github.com/python/cpython.git
synced 2025-08-21 17:25:34 +00:00
bpo-45822: Minor cleanups to the test_Py_CompileString test (GH-29750) (GH-29758)
(cherry picked from commit abfc794bbf
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
4b224e8729
commit
e1e3f648ad
2 changed files with 9 additions and 9 deletions
|
@ -631,6 +631,14 @@ class CAPITest(unittest.TestCase):
|
||||||
s = _testcapi.pyobject_bytes_from_null()
|
s = _testcapi.pyobject_bytes_from_null()
|
||||||
self.assertEqual(s, b'<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):
|
class TestPendingCalls(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -1013,14 +1021,6 @@ class Test_ModuleStateAccess(unittest.TestCase):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
increment_count(1, 2, 3)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -400,7 +400,7 @@ pycompilestring(PyObject* self, PyObject *obj) {
|
||||||
if (the_string == NULL) {
|
if (the_string == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return Py_CompileString(the_string, "blech", Py_file_input);
|
return Py_CompileString(the_string, "<string>", Py_file_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue