diff options
author | Brett Cannon <bcannon@gmail.com> | 2006-06-13 22:26:13 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2006-06-13 22:26:13 (GMT) |
commit | 5dc3e3f17ab76b44e0ca29c6ab5b3b95093f5710 (patch) | |
tree | ccbcb5cc8c880b28cdd67ef9f539d420b64240ba | |
parent | 1541ef08afda1da09ec99cfb5305fdc0af04ef40 (diff) | |
download | cpython-5dc3e3f17ab76b44e0ca29c6ab5b3b95093f5710.zip cpython-5dc3e3f17ab76b44e0ca29c6ab5b3b95093f5710.tar.gz cpython-5dc3e3f17ab76b44e0ca29c6ab5b3b95093f5710.tar.bz2 |
Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.
-rw-r--r-- | Lib/test/test_coercion.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py index 4356817..d704e4b 100644 --- a/Lib/test/test_coercion.py +++ b/Lib/test/test_coercion.py @@ -2,7 +2,7 @@ import copy import sys import warnings import unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, TestFailed # Fake a number that implements numeric methods through __coerce__ class CoerceNumber: @@ -318,6 +318,24 @@ class CoercionTest(unittest.TestCase): return 0 self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 0) + def test_infinite_rec_classic_classes(self): + # if __coerce__() returns its arguments reversed it causes an infinite + # recursion for classic classes. + class Tester: + def __coerce__(self, other): + return other, self + + exc = TestFailed("__coerce__() returning its arguments reverse " + "should raise RuntimeError") + try: + Tester() + 1 + except (RuntimeError, TypeError): + return + except: + raise exc + else: + raise exc + def test_main(): warnings.filterwarnings("ignore", r'complex divmod\(\), // and % are deprecated', |