Back to index

python3.2  3.2.2
Public Member Functions
test.test_raise.TestContext Class Reference

List of all members.

Public Member Functions

def test_instance_context_instance_raise
def test_class_context_instance_raise
def test_class_context_class_raise
def test_c_exception_context
def test_c_exception_raise
def test_noraise_finally
def test_raise_finally
def test_context_manager
def test_cycle_broken
def test_reraise_cycle_broken
def test_3118
def test_3611

Detailed Description

Definition at line 193 of file test_raise.py.


Member Function Documentation

Definition at line 314 of file test_raise.py.

00314 
00315     def test_3118(self):
00316         # deleting the generator caused the __context__ to be cleared
00317         def gen():
00318             try:
00319                 yield 1
00320             finally:
00321                 pass
00322 
00323         def f():
00324             g = gen()
00325             next(g)
00326             try:
00327                 try:
00328                     raise ValueError
00329                 except:
00330                     del g
00331                     raise KeyError
00332             except Exception as e:
00333                 self.assertIsInstance(e.__context__, ValueError)
00334 
00335         f()

Here is the call graph for this function:

Definition at line 336 of file test_raise.py.

00336 
00337     def test_3611(self):
00338         # A re-raised exception in a __del__ caused the __context__
00339         # to be cleared
00340         class C:
00341             def __del__(self):
00342                 try:
00343                     1/0
00344                 except:
00345                     raise
00346 
00347         def f():
00348             x = C()
00349             try:
00350                 try:
00351                     x.x
00352                 except AttributeError:
00353                     del x
00354                     raise TypeError
00355             except Exception as e:
00356                 self.assertNotEqual(e.__context__, None)
00357                 self.assertIsInstance(e.__context__, AttributeError)
00358 
00359         with support.captured_output("stderr"):
00360             f()

Here is the call graph for this function:

Definition at line 232 of file test_raise.py.

00232 
00233     def test_c_exception_context(self):
00234         try:
00235             try:
00236                 1/0
00237             except:
00238                 raise OSError
00239         except OSError as e:
00240             self.assertIsInstance(e.__context__, ZeroDivisionError)
00241         else:
00242             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 243 of file test_raise.py.

00243 
00244     def test_c_exception_raise(self):
00245         try:
00246             try:
00247                 1/0
00248             except:
00249                 xyzzy
00250         except NameError as e:
00251             self.assertIsInstance(e.__context__, ZeroDivisionError)
00252         else:
00253             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 219 of file test_raise.py.

00219 
00220     def test_class_context_class_raise(self):
00221         context = IndexError
00222         try:
00223             try:
00224                 raise context
00225             except:
00226                 raise OSError
00227         except OSError as e:
00228             self.assertNotEqual(e.__context__, context)
00229             self.assertIsInstance(e.__context__, context)
00230         else:
00231             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 206 of file test_raise.py.

00206 
00207     def test_class_context_instance_raise(self):
00208         context = IndexError
00209         try:
00210             try:
00211                 raise context
00212             except:
00213                 raise OSError()
00214         except OSError as e:
00215             self.assertNotEqual(e.__context__, context)
00216             self.assertIsInstance(e.__context__, context)
00217         else:
00218             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 276 of file test_raise.py.

00276 
00277     def test_context_manager(self):
00278         class ContextManager:
00279             def __enter__(self):
00280                 pass
00281             def __exit__(self, t, v, tb):
00282                 xyzzy
00283         try:
00284             with ContextManager():
00285                 1/0
00286         except NameError as e:
00287             self.assertIsInstance(e.__context__, ZeroDivisionError)
00288         else:
00289             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 290 of file test_raise.py.

00290 
00291     def test_cycle_broken(self):
00292         # Self-cycles (when re-raising a caught exception) are broken
00293         try:
00294             try:
00295                 1/0
00296             except ZeroDivisionError as e:
00297                 raise e
00298         except ZeroDivisionError as e:
00299             self.assertTrue(e.__context__ is None, e.__context__)

Here is the call graph for this function:

Definition at line 194 of file test_raise.py.

00194 
00195     def test_instance_context_instance_raise(self):
00196         context = IndexError()
00197         try:
00198             try:
00199                 raise context
00200             except:
00201                 raise OSError()
00202         except OSError as e:
00203             self.assertEqual(e.__context__, context)
00204         else:
00205             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 254 of file test_raise.py.

00254 
00255     def test_noraise_finally(self):
00256         try:
00257             try:
00258                 pass
00259             finally:
00260                 raise OSError
00261         except OSError as e:
00262             self.assertTrue(e.__context__ is None)
00263         else:
00264             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 265 of file test_raise.py.

00265 
00266     def test_raise_finally(self):
00267         try:
00268             try:
00269                 1/0
00270             finally:
00271                 raise OSError
00272         except OSError as e:
00273             self.assertIsInstance(e.__context__, ZeroDivisionError)
00274         else:
00275             self.fail("No exception raised")

Here is the call graph for this function:

Definition at line 300 of file test_raise.py.

00300 
00301     def test_reraise_cycle_broken(self):
00302         # Non-trivial context cycles (through re-raising a previous exception)
00303         # are broken too.
00304         try:
00305             try:
00306                 xyzzy
00307             except NameError as a:
00308                 try:
00309                     1/0
00310                 except ZeroDivisionError:
00311                     raise a
00312         except NameError as e:
00313             self.assertTrue(e.__context__.__context__ is None)

Here is the call graph for this function:


The documentation for this class was generated from the following file: