Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed.

This commit is contained in:
Brett Cannon 2006-06-13 22:26:13 +00:00
parent 1541ef08af
commit 5dc3e3f17a
1 changed files with 19 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import copy
import sys import sys
import warnings import warnings
import unittest 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__ # Fake a number that implements numeric methods through __coerce__
class CoerceNumber: class CoerceNumber:
@ -318,6 +318,24 @@ class CoercionTest(unittest.TestCase):
return 0 return 0
self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 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(): def test_main():
warnings.filterwarnings("ignore", warnings.filterwarnings("ignore",
r'complex divmod\(\), // and % are deprecated', r'complex divmod\(\), // and % are deprecated',