Update test_exceptions.py from Cpython v3.11.2 by Masorubka1 · Pull Request #4819 · RustPython/RustPython
# Errors thrown by tokenizer.c check('(0x+1)', 1, 3)
# TODO: RUSTPYTHON @unittest.expectedFailure def test_notes(self): for e in [BaseException(1), Exception(2), ValueError(3)]: with self.subTest(e=e): self.assertFalse(hasattr(e, '__notes__')) e.add_note("My Note") self.assertEqual(e.__notes__, ["My Note"])
with self.assertRaises(TypeError): e.add_note(42) self.assertEqual(e.__notes__, ["My Note"])
e.add_note("Your Note") self.assertEqual(e.__notes__, ["My Note", "Your Note"])
del e.__notes__ self.assertFalse(hasattr(e, '__notes__'))
e.add_note("Our Note") self.assertEqual(e.__notes__, ["Our Note"])
e.__notes__ = 42 self.assertEqual(e.__notes__, 42)
with self.assertRaises(TypeError): e.add_note("will not work") self.assertEqual(e.__notes__, 42)
def testWithTraceback(self): try: raise IndexError(4)
# def test_3114(self): # # Bug #3114: in its destructor, MyObject retrieves a pointer to # # obsolete and/or deallocated objects. # class MyObject: # def __del__(self): # nonlocal e # e = sys.exc_info() # e = () # try: # raise Exception(MyObject()) # except: # pass # gc_collect() # For PyPy or other GCs. # self.assertEqual(e, (None, None, None)) def test_3114(self): # Bug #3114: in its destructor, MyObject retrieves a pointer to # obsolete and/or deallocated objects. class MyObject: def __del__(self): nonlocal e e = sys.exc_info() e = () try: raise Exception(MyObject()) except: pass gc_collect() # For PyPy or other GCs. self.assertEqual(e, (None, None, None))
def test_raise_does_not_create_context_chain_cycle(self): class A(Exception):
def test_context_of_exception_in_try_and_finally(self): try: try: te = TypeError(1) raise te finally: ve = ValueError(2) raise ve except Exception as e: exc = e
self.assertIs(exc, ve) self.assertIs(exc.__context__, te)
def test_context_of_exception_in_except_and_finally(self): try: try: te = TypeError(1) raise te except: ve = ValueError(2) raise ve finally: oe = OSError(3) raise oe except Exception as e: exc = e
self.assertIs(exc, oe) self.assertIs(exc.__context__, ve) self.assertIs(exc.__context__.__context__, te)
def test_context_of_exception_in_else_and_finally(self): try: try: pass except: pass else: ve = ValueError(1) raise ve finally: oe = OSError(2) raise oe except Exception as e: exc = e
self.assertIs(exc, oe) self.assertIs(exc.__context__, ve)
# TODO: RUSTPYTHON @unittest.expectedFailure def test_unicode_change_attributes(self):
@cpython_only def test_MemoryError(self):
# TODO: RUSTPYTHON @unittest.expectedFailure def test_getattr_has_name_and_obj(self): class A: blech = None
def test_getattr_has_name_and_obj_for_method(self): class A:
class TestInvalidExceptionMatcher(unittest.TestCase): # TODO: RUSTPYTHON @unittest.expectedFailure def test_except_star_invalid_exception_type(self): with self.assertRaises(TypeError): try: raise ValueError except 42: pass
with self.assertRaises(TypeError): try: raise ValueError except (ValueError, 42): pass
class PEP626Tests(unittest.TestCase):
def lineno_after_raise(self, f, *expected):
def test_lineno_after_raise_in_with_exit(self):