mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Make test_decimal work with -Qnew.
This commit is contained in:
parent
df511798e4
commit
96c3f7f56b
1 changed files with 16 additions and 10 deletions
|
@ -503,16 +503,22 @@ class DecimalImplicitConstructionTest(unittest.TestCase):
|
||||||
self.assertEqual(eval('Decimal(10) != E()'), 'ne 10')
|
self.assertEqual(eval('Decimal(10) != E()'), 'ne 10')
|
||||||
|
|
||||||
# insert operator methods and then exercise them
|
# insert operator methods and then exercise them
|
||||||
for sym, lop, rop in (
|
oplist = [
|
||||||
('+', '__add__', '__radd__'),
|
('+', '__add__', '__radd__'),
|
||||||
('-', '__sub__', '__rsub__'),
|
('-', '__sub__', '__rsub__'),
|
||||||
('*', '__mul__', '__rmul__'),
|
('*', '__mul__', '__rmul__'),
|
||||||
('/', '__div__', '__rdiv__'),
|
('%', '__mod__', '__rmod__'),
|
||||||
('%', '__mod__', '__rmod__'),
|
('//', '__floordiv__', '__rfloordiv__'),
|
||||||
('//', '__floordiv__', '__rfloordiv__'),
|
('**', '__pow__', '__rpow__')
|
||||||
('**', '__pow__', '__rpow__'),
|
]
|
||||||
):
|
if 1/2 == 0:
|
||||||
|
# testing with classic division, so add __div__
|
||||||
|
oplist.append(('/', '__div__', '__rdiv__'))
|
||||||
|
else:
|
||||||
|
# testing with -Qnew, so add __truediv__
|
||||||
|
oplist.append(('/', '__truediv__', '__rtruediv__'))
|
||||||
|
|
||||||
|
for sym, lop, rop in oplist:
|
||||||
setattr(E, lop, lambda self, other: 'str' + lop + str(other))
|
setattr(E, lop, lambda self, other: 'str' + lop + str(other))
|
||||||
setattr(E, rop, lambda self, other: str(other) + rop + 'str')
|
setattr(E, rop, lambda self, other: str(other) + rop + 'str')
|
||||||
self.assertEqual(eval('E()' + sym + 'Decimal(10)'),
|
self.assertEqual(eval('E()' + sym + 'Decimal(10)'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue