From: <pj...@us...> - 2008-12-10 08:10:32
|
Revision: 5731 http://jython.svn.sourceforge.net/jython/?rev=5731&view=rev Author: pjenvey Date: 2008-12-10 08:10:31 +0000 (Wed, 10 Dec 2008) Log Message: ----------- merge in new test from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_with.py -c 67684 Modified Paths: -------------- trunk/jython/Lib/test/test_with.py Modified: trunk/jython/Lib/test/test_with.py =================================================================== --- trunk/jython/Lib/test/test_with.py 2008-12-10 07:34:57 UTC (rev 5730) +++ trunk/jython/Lib/test/test_with.py 2008-12-10 08:10:31 UTC (rev 5731) @@ -505,7 +505,37 @@ self.assertRaises(GeneratorExit, shouldThrow) + def testErrorsInBool(self): + # issue4589: __exit__ return code may raise an exception + # when looking at its truth value. + class cm(object): + def __init__(self, bool_conversion): + class Bool: + def __nonzero__(self): + return bool_conversion() + self.exit_result = Bool() + def __enter__(self): + return 3 + def __exit__(self, a, b, c): + return self.exit_result + + def trueAsBool(): + with cm(lambda: True): + self.fail("Should NOT see this") + trueAsBool() + + def falseAsBool(): + with cm(lambda: False): + self.fail("Should raise") + self.assertRaises(AssertionError, falseAsBool) + + def failAsBool(): + with cm(lambda: 1//0): + self.fail("Should NOT see this") + self.assertRaises(ZeroDivisionError, failAsBool) + + class NonLocalFlowControlTestCase(unittest.TestCase, ContextmanagerAssertionMixin): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |