MCPcopy Index your code
hub / github.com/RustPython/RustPython / testExceptionCleanupState

Method testExceptionCleanupState

Lib/test/test_exceptions.py:791–910  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

789 e
790
791 def testExceptionCleanupState(self):
792 # Make sure exception state is cleaned up as soon as the except
793 # block is left. See #2507
794
795 class MyException(Exception):
796 def __init__(self, obj):
797 self.obj = obj
798 class MyObj:
799 pass
800
801 def inner_raising_func():
802 # Create some references in exception value and traceback
803 local_ref = obj
804 raise MyException(obj)
805
806 # Qualified "except" with "as"
807 obj = MyObj()
808 wr = weakref.ref(obj)
809 try:
810 inner_raising_func()
811 except MyException as e:
812 pass
813 obj = None
814 gc_collect() # For PyPy or other GCs.
815 obj = wr()
816 self.assertIsNone(obj)
817
818 # Qualified "except" without "as"
819 obj = MyObj()
820 wr = weakref.ref(obj)
821 try:
822 inner_raising_func()
823 except MyException:
824 pass
825 obj = None
826 gc_collect() # For PyPy or other GCs.
827 obj = wr()
828 self.assertIsNone(obj)
829
830 # Bare "except"
831 obj = MyObj()
832 wr = weakref.ref(obj)
833 try:
834 inner_raising_func()
835 except:
836 pass
837 obj = None
838 gc_collect() # For PyPy or other GCs.
839 obj = wr()
840 self.assertIsNone(obj)
841
842 # "except" with premature block leave
843 obj = MyObj()
844 wr = weakref.ref(obj)
845 for i in [0]:
846 try:
847 inner_raising_func()
848 except:

Callers

nothing calls this directly

Calls 5

gc_collectFunction · 0.90
check_impl_detailFunction · 0.90
assertIsNoneMethod · 0.80
MyObjClass · 0.70
ContextClass · 0.70

Tested by

no test coverage detected