|
6 | 6 | import threading |
7 | 7 | import unittest |
8 | 8 | import weakref |
9 | | -try: |
10 | | - import _testcapi |
11 | | -except ImportError: |
12 | | - _testcapi = None |
13 | 9 |
|
14 | 10 | from collections.abc import Mapping |
15 | 11 | from test import support |
@@ -773,51 +769,6 @@ def f(): |
773 | 769 | self.assertIs(catcher.unraisable.exc_type, TypeError) |
774 | 770 | self.assertIsNone(weak()) |
775 | 771 |
|
776 | | -@unittest.skipIf(_testcapi is None, 'need _testcapi') |
777 | | -class TestCAPI(unittest.TestCase): |
778 | | - def getframe(self): |
779 | | - return sys._getframe() |
780 | | - |
781 | | - def test_frame_getters(self): |
782 | | - frame = self.getframe() |
783 | | - self.assertEqual(frame.f_locals, _testcapi.frame_getlocals(frame)) |
784 | | - self.assertIs(frame.f_globals, _testcapi.frame_getglobals(frame)) |
785 | | - self.assertIs(frame.f_builtins, _testcapi.frame_getbuiltins(frame)) |
786 | | - self.assertEqual(frame.f_lasti, _testcapi.frame_getlasti(frame)) |
787 | | - |
788 | | - def test_getvar(self): |
789 | | - current_frame = sys._getframe() |
790 | | - x = 1 |
791 | | - self.assertEqual(_testcapi.frame_getvar(current_frame, "x"), 1) |
792 | | - self.assertEqual(_testcapi.frame_getvarstring(current_frame, b"x"), 1) |
793 | | - with self.assertRaises(NameError): |
794 | | - _testcapi.frame_getvar(current_frame, "y") |
795 | | - with self.assertRaises(NameError): |
796 | | - _testcapi.frame_getvarstring(current_frame, b"y") |
797 | | - |
798 | | - # wrong name type |
799 | | - with self.assertRaises(TypeError): |
800 | | - _testcapi.frame_getvar(current_frame, b'x') |
801 | | - with self.assertRaises(TypeError): |
802 | | - _testcapi.frame_getvar(current_frame, 123) |
803 | | - |
804 | | - def getgenframe(self): |
805 | | - yield sys._getframe() |
806 | | - |
807 | | - def test_frame_get_generator(self): |
808 | | - gen = self.getgenframe() |
809 | | - frame = next(gen) |
810 | | - self.assertIs(gen, _testcapi.frame_getgenerator(frame)) |
811 | | - |
812 | | - def test_frame_fback_api(self): |
813 | | - """Test that accessing `f_back` does not cause a segmentation fault on |
814 | | - a frame created with `PyFrame_New` (GH-99110).""" |
815 | | - def dummy(): |
816 | | - pass |
817 | | - |
818 | | - frame = _testcapi.frame_new(dummy.__code__, globals(), locals()) |
819 | | - # The following line should not cause a segmentation fault. |
820 | | - self.assertIsNone(frame.f_back) |
821 | 772 |
|
822 | 773 | if __name__ == "__main__": |
823 | 774 | unittest.main() |
0 commit comments