forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-93649: Split _testcapimodule.c into smaller files
* Move many functions from _testcapimodule.c into more specific files in Modules/_testcapi/. * Add files: * Modules/_testcapi/frame.c * Modules/_testcapi/function.c * Modules/_testcapi/type.c * In moved code: * Replace get_testerror() with PyExc_AssertionError. * Replace raiseTestError() with PyErr_Format(PyExc_AssertionError, ...).
- Loading branch information
Showing
18 changed files
with
1,337 additions
and
1,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import sys | ||
import unittest | ||
from test.support import import_helper | ||
|
||
|
||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class TestCAPI(unittest.TestCase): | ||
def getframe(self): | ||
return sys._getframe() | ||
|
||
def test_frame_getters(self): | ||
frame = self.getframe() | ||
self.assertEqual(frame.f_locals, _testcapi.frame_getlocals(frame)) | ||
self.assertIs(frame.f_globals, _testcapi.frame_getglobals(frame)) | ||
self.assertIs(frame.f_builtins, _testcapi.frame_getbuiltins(frame)) | ||
self.assertEqual(frame.f_lasti, _testcapi.frame_getlasti(frame)) | ||
|
||
def test_getvar(self): | ||
current_frame = sys._getframe() | ||
x = 1 | ||
self.assertEqual(_testcapi.frame_getvar(current_frame, "x"), 1) | ||
self.assertEqual(_testcapi.frame_getvarstring(current_frame, b"x"), 1) | ||
with self.assertRaises(NameError): | ||
_testcapi.frame_getvar(current_frame, "y") | ||
with self.assertRaises(NameError): | ||
_testcapi.frame_getvarstring(current_frame, b"y") | ||
|
||
# wrong name type | ||
with self.assertRaises(TypeError): | ||
_testcapi.frame_getvar(current_frame, b'x') | ||
with self.assertRaises(TypeError): | ||
_testcapi.frame_getvar(current_frame, 123) | ||
|
||
def getgenframe(self): | ||
yield sys._getframe() | ||
|
||
def test_frame_get_generator(self): | ||
gen = self.getgenframe() | ||
frame = next(gen) | ||
self.assertIs(gen, _testcapi.frame_getgenerator(frame)) | ||
|
||
def test_frame_fback_api(self): | ||
"""Test that accessing `f_back` does not cause a segmentation fault on | ||
a frame created with `PyFrame_New` (GH-99110).""" | ||
def dummy(): | ||
pass | ||
|
||
frame = _testcapi.frame_new(dummy.__code__, globals(), locals()) | ||
# The following line should not cause a segmentation fault. | ||
self.assertIsNone(frame.f_back) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.