Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_with.ExceptionalTestCase Class Reference
Inheritance diagram for test.test_with.ExceptionalTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_with.ExceptionalTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def testSingleResource
def testExceptionNormalized
def testNestedSingleStatements
def testMultipleResourcesInSingleStatement
def testNestedExceptionBeforeInnerStatement
def testNestedExceptionAfterInnerStatement
def testRaisedStopIteration1
def testRaisedStopIteration2
def testRaisedStopIteration3
def testRaisedGeneratorExit1
def testRaisedGeneratorExit2
def testErrorsInBool
def setUp
def assertInWithManagerInvariants
def assertAfterWithManagerInvariants
def assertAfterWithManagerInvariantsNoError
def assertInWithGeneratorInvariants
def assertAfterWithGeneratorInvariantsNoError
def raiseTestException
def assertAfterWithManagerInvariantsWithError
def assertAfterWithGeneratorInvariantsWithError

Public Attributes

 bar
 exit_result
 TEST_EXCEPTION
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 354 of file test_with.py.


Member Function Documentation

Definition at line 211 of file test_with.py.

00211 
00212     def assertAfterWithGeneratorInvariantsNoError(self, mock_generator):
00213         self.assertTrue(mock_generator.yielded)
00214         self.assertTrue(mock_generator.stopped)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 230 of file test_with.py.

00230 
00231     def assertAfterWithGeneratorInvariantsWithError(self, mock_generator):
00232         self.assertTrue(mock_generator.yielded)
00233         self.assertTrue(mock_generator.stopped)
00234 

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_with.ContextmanagerAssertionMixin.assertAfterWithManagerInvariants (   self,
  mock_manager,
  exit_args 
) [inherited]

Definition at line 198 of file test_with.py.

00198 
00199     def assertAfterWithManagerInvariants(self, mock_manager, exit_args):
00200         self.assertTrue(mock_manager.enter_called)
00201         self.assertTrue(mock_manager.exit_called)
00202         self.assertEqual(mock_manager.exit_args, exit_args)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file test_with.py.

00203 
00204     def assertAfterWithManagerInvariantsNoError(self, mock_manager):
00205         self.assertAfterWithManagerInvariants(mock_manager,
00206             (None, None, None))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_with.ContextmanagerAssertionMixin.assertAfterWithManagerInvariantsWithError (   self,
  mock_manager,
  exc_type = None 
) [inherited]

Definition at line 219 of file test_with.py.

00219 
00220                                                   exc_type=None):
00221         self.assertTrue(mock_manager.enter_called)
00222         self.assertTrue(mock_manager.exit_called)
00223         if exc_type is None:
00224             self.assertEqual(mock_manager.exit_args[1], self.TEST_EXCEPTION)
00225             exc_type = type(self.TEST_EXCEPTION)
00226         self.assertEqual(mock_manager.exit_args[0], exc_type)
00227         # Test the __exit__ arguments. Issue #7853
00228         self.assertIsInstance(mock_manager.exit_args[1], exc_type)
00229         self.assertIsNot(mock_manager.exit_args[2], None)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_with.ContextmanagerAssertionMixin.assertInWithGeneratorInvariants (   self,
  mock_generator 
) [inherited]

Definition at line 207 of file test_with.py.

00207 
00208     def assertInWithGeneratorInvariants(self, mock_generator):
00209         self.assertTrue(mock_generator.yielded)
00210         self.assertFalse(mock_generator.stopped)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_with.ContextmanagerAssertionMixin.assertInWithManagerInvariants (   self,
  mock_manager 
) [inherited]

Definition at line 193 of file test_with.py.

00193 
00194     def assertInWithManagerInvariants(self, mock_manager):
00195         self.assertTrue(mock_manager.enter_called)
00196         self.assertFalse(mock_manager.exit_called)
00197         self.assertEqual(mock_manager.exit_args, None)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 215 of file test_with.py.

00215 
00216     def raiseTestException(self):
00217         raise self.TEST_EXCEPTION

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 190 of file test_with.py.

00190 
00191     def setUp(self):
00192         self.TEST_EXCEPTION = RuntimeError("test exception")

Here is the caller graph for this function:

Definition at line 515 of file test_with.py.

00515 
00516     def testErrorsInBool(self):
00517         # issue4589: __exit__ return code may raise an exception
00518         # when looking at its truth value.
00519 
00520         class cm(object):
00521             def __init__(self, bool_conversion):
00522                 class Bool:
00523                     def __bool__(self):
00524                         return bool_conversion()
00525                 self.exit_result = Bool()
00526             def __enter__(self):
00527                 return 3
00528             def __exit__(self, a, b, c):
00529                 return self.exit_result
00530 
00531         def trueAsBool():
00532             with cm(lambda: True):
00533                 self.fail("Should NOT see this")
00534         trueAsBool()
00535 
00536         def falseAsBool():
00537             with cm(lambda: False):
00538                 self.fail("Should raise")
00539         self.assertRaises(AssertionError, falseAsBool)
00540 
00541         def failAsBool():
00542             with cm(lambda: 1//0):
00543                 self.fail("Should NOT see this")
00544         self.assertRaises(ZeroDivisionError, failAsBool)
00545 

Here is the call graph for this function:

Definition at line 366 of file test_with.py.

00366 
00367     def testExceptionNormalized(self):
00368         cm = mock_contextmanager_generator()
00369         def shouldThrow():
00370             with cm as self.resource:
00371                 # Note this relies on the fact that 1 // 0 produces an exception
00372                 # that is not normalized immediately.
00373                 1 // 0
00374         self.assertRaises(ZeroDivisionError, shouldThrow)
00375         self.assertAfterWithManagerInvariantsWithError(cm, ZeroDivisionError)

Here is the call graph for this function:

Definition at line 393 of file test_with.py.

00393 
00394     def testMultipleResourcesInSingleStatement(self):
00395         cm_a = mock_contextmanager_generator()
00396         cm_b = mock_contextmanager_generator()
00397         mock_nested = MockNested(cm_a, cm_b)
00398         def shouldThrow():
00399             with mock_nested as (self.resource_a, self.resource_b):
00400                 self.assertInWithManagerInvariants(cm_a)
00401                 self.assertInWithManagerInvariants(cm_b)
00402                 self.assertInWithManagerInvariants(mock_nested)
00403                 self.assertInWithGeneratorInvariants(self.resource_a)
00404                 self.assertInWithGeneratorInvariants(self.resource_b)
00405                 self.raiseTestException()
00406         self.assertRaises(RuntimeError, shouldThrow)
00407         self.assertAfterWithManagerInvariantsWithError(cm_a)
00408         self.assertAfterWithManagerInvariantsWithError(cm_b)
00409         self.assertAfterWithManagerInvariantsWithError(mock_nested)
00410         self.assertAfterWithGeneratorInvariantsWithError(self.resource_a)
00411         self.assertAfterWithGeneratorInvariantsWithError(self.resource_b)

Here is the call graph for this function:

Definition at line 433 of file test_with.py.

00433 
00434     def testNestedExceptionAfterInnerStatement(self):
00435         mock_a = mock_contextmanager_generator()
00436         mock_b = mock_contextmanager_generator()
00437         def shouldThrow():
00438             with mock_a as self.foo:
00439                 with mock_b as self.bar:
00440                     self.assertInWithManagerInvariants(mock_a)
00441                     self.assertInWithManagerInvariants(mock_b)
00442                     self.assertInWithGeneratorInvariants(self.foo)
00443                     self.assertInWithGeneratorInvariants(self.bar)
00444                 self.raiseTestException()
00445         self.assertRaises(RuntimeError, shouldThrow)
00446         self.assertAfterWithManagerInvariantsWithError(mock_a)
00447         self.assertAfterWithManagerInvariantsNoError(mock_b)
00448         self.assertAfterWithGeneratorInvariantsWithError(self.foo)
00449         self.assertAfterWithGeneratorInvariantsNoError(self.bar)

Here is the call graph for this function:

Definition at line 412 of file test_with.py.

00412 
00413     def testNestedExceptionBeforeInnerStatement(self):
00414         mock_a = mock_contextmanager_generator()
00415         mock_b = mock_contextmanager_generator()
00416         self.bar = None
00417         def shouldThrow():
00418             with mock_a as self.foo:
00419                 self.assertInWithManagerInvariants(mock_a)
00420                 self.assertInWithGeneratorInvariants(self.foo)
00421                 self.raiseTestException()
00422                 with mock_b as self.bar:
00423                     pass
00424         self.assertRaises(RuntimeError, shouldThrow)
00425         self.assertAfterWithManagerInvariantsWithError(mock_a)
00426         self.assertAfterWithGeneratorInvariantsWithError(self.foo)
00427 
00428         # The inner statement stuff should never have been touched
00429         self.assertEqual(self.bar, None)
00430         self.assertFalse(mock_b.enter_called)
00431         self.assertFalse(mock_b.exit_called)
00432         self.assertEqual(mock_b.exit_args, None)

Here is the call graph for this function:

Definition at line 376 of file test_with.py.

00376 
00377     def testNestedSingleStatements(self):
00378         mock_a = mock_contextmanager_generator()
00379         mock_b = mock_contextmanager_generator()
00380         def shouldThrow():
00381             with mock_a as self.foo:
00382                 with mock_b as self.bar:
00383                     self.assertInWithManagerInvariants(mock_a)
00384                     self.assertInWithManagerInvariants(mock_b)
00385                     self.assertInWithGeneratorInvariants(self.foo)
00386                     self.assertInWithGeneratorInvariants(self.bar)
00387                     self.raiseTestException()
00388         self.assertRaises(RuntimeError, shouldThrow)
00389         self.assertAfterWithManagerInvariantsWithError(mock_a)
00390         self.assertAfterWithManagerInvariantsWithError(mock_b)
00391         self.assertAfterWithGeneratorInvariantsWithError(self.foo)
00392         self.assertAfterWithGeneratorInvariantsWithError(self.bar)

Here is the call graph for this function:

Definition at line 489 of file test_with.py.

00489 
00490     def testRaisedGeneratorExit1(self):
00491         # From bug 1462485
00492         @contextmanager
00493         def cm():
00494             yield
00495 
00496         def shouldThrow():
00497             with cm():
00498                 raise GeneratorExit("from with")
00499 
00500         self.assertRaises(GeneratorExit, shouldThrow)

Definition at line 501 of file test_with.py.

00501 
00502     def testRaisedGeneratorExit2(self):
00503         # From bug 1462485
00504         class cm (object):
00505             def __enter__(self):
00506                 pass
00507             def __exit__(self, type, value, traceback):
00508                 pass
00509 
00510         def shouldThrow():
00511             with cm():
00512                 raise GeneratorExit("from with")
00513 
00514         self.assertRaises(GeneratorExit, shouldThrow)

Here is the call graph for this function:

Definition at line 450 of file test_with.py.

00450 
00451     def testRaisedStopIteration1(self):
00452         # From bug 1462485
00453         @contextmanager
00454         def cm():
00455             yield
00456 
00457         def shouldThrow():
00458             with cm():
00459                 raise StopIteration("from with")
00460 
00461         self.assertRaises(StopIteration, shouldThrow)

Definition at line 462 of file test_with.py.

00462 
00463     def testRaisedStopIteration2(self):
00464         # From bug 1462485
00465         class cm(object):
00466             def __enter__(self):
00467                 pass
00468             def __exit__(self, type, value, traceback):
00469                 pass
00470 
00471         def shouldThrow():
00472             with cm():
00473                 raise StopIteration("from with")
00474 
00475         self.assertRaises(StopIteration, shouldThrow)

Here is the call graph for this function:

Definition at line 476 of file test_with.py.

00476 
00477     def testRaisedStopIteration3(self):
00478         # Another variant where the exception hasn't been instantiated
00479         # From bug 1705170
00480         @contextmanager
00481         def cm():
00482             yield
00483 
00484         def shouldThrow():
00485             with cm():
00486                 raise next(iter([]))
00487 
00488         self.assertRaises(StopIteration, shouldThrow)

Definition at line 355 of file test_with.py.

00355 
00356     def testSingleResource(self):
00357         cm = mock_contextmanager_generator()
00358         def shouldThrow():
00359             with cm as self.resource:
00360                 self.assertInWithManagerInvariants(cm)
00361                 self.assertInWithGeneratorInvariants(self.resource)
00362                 self.raiseTestException()
00363         self.assertRaises(RuntimeError, shouldThrow)
00364         self.assertAfterWithManagerInvariantsWithError(cm)
00365         self.assertAfterWithGeneratorInvariantsWithError(self.resource)

Here is the call graph for this function:


Member Data Documentation

Definition at line 415 of file test_with.py.

Definition at line 524 of file test_with.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 191 of file test_with.py.


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