mirror of https://github.com/python/cpython
Fix py3k warnings in test_decimal, using unittest.assertItemsEqual.
This commit is contained in:
parent
4a0f8b89f6
commit
8f43cec41b
|
@ -30,7 +30,8 @@ import pickle, copy
|
||||||
import unittest
|
import unittest
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import numbers
|
import numbers
|
||||||
from test.test_support import (run_unittest, run_doctest, is_resource_enabled)
|
from test.test_support import (run_unittest, run_doctest,
|
||||||
|
is_resource_enabled, check_py3k_warnings)
|
||||||
import random
|
import random
|
||||||
try:
|
try:
|
||||||
import threading
|
import threading
|
||||||
|
@ -201,7 +202,7 @@ class DecimalTest(unittest.TestCase):
|
||||||
if skip_expected:
|
if skip_expected:
|
||||||
raise unittest.SkipTest
|
raise unittest.SkipTest
|
||||||
return
|
return
|
||||||
for line in open(file).xreadlines():
|
for line in open(file):
|
||||||
line = line.replace('\r\n', '').replace('\n', '')
|
line = line.replace('\r\n', '').replace('\n', '')
|
||||||
#print line
|
#print line
|
||||||
try:
|
try:
|
||||||
|
@ -360,12 +361,9 @@ class DecimalTest(unittest.TestCase):
|
||||||
myexceptions = self.getexceptions()
|
myexceptions = self.getexceptions()
|
||||||
self.context.clear_flags()
|
self.context.clear_flags()
|
||||||
|
|
||||||
myexceptions.sort()
|
|
||||||
theirexceptions.sort()
|
|
||||||
|
|
||||||
self.assertEqual(result, ans,
|
self.assertEqual(result, ans,
|
||||||
'Incorrect answer for ' + s + ' -- got ' + result)
|
'Incorrect answer for ' + s + ' -- got ' + result)
|
||||||
self.assertEqual(myexceptions, theirexceptions,
|
self.assertItemsEqual(myexceptions, theirexceptions,
|
||||||
'Incorrect flags set in ' + s + ' -- got ' + str(myexceptions))
|
'Incorrect flags set in ' + s + ' -- got ' + str(myexceptions))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -616,12 +614,13 @@ class DecimalImplicitConstructionTest(unittest.TestCase):
|
||||||
('//', '__floordiv__', '__rfloordiv__'),
|
('//', '__floordiv__', '__rfloordiv__'),
|
||||||
('**', '__pow__', '__rpow__')
|
('**', '__pow__', '__rpow__')
|
||||||
]
|
]
|
||||||
if 1/2 == 0:
|
with check_py3k_warnings():
|
||||||
# testing with classic division, so add __div__
|
if 1 / 2 == 0:
|
||||||
oplist.append(('/', '__div__', '__rdiv__'))
|
# testing with classic division, so add __div__
|
||||||
else:
|
oplist.append(('/', '__div__', '__rdiv__'))
|
||||||
# testing with -Qnew, so add __truediv__
|
else:
|
||||||
oplist.append(('/', '__truediv__', '__rtruediv__'))
|
# testing with -Qnew, so add __truediv__
|
||||||
|
oplist.append(('/', '__truediv__', '__rtruediv__'))
|
||||||
|
|
||||||
for sym, lop, rop in oplist:
|
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))
|
||||||
|
@ -1199,8 +1198,9 @@ class DecimalUsabilityTest(unittest.TestCase):
|
||||||
self.assertEqual(a, b)
|
self.assertEqual(a, b)
|
||||||
|
|
||||||
# with None
|
# with None
|
||||||
self.assertFalse(Decimal(1) < None)
|
with check_py3k_warnings():
|
||||||
self.assertTrue(Decimal(1) > None)
|
self.assertFalse(Decimal(1) < None)
|
||||||
|
self.assertTrue(Decimal(1) > None)
|
||||||
|
|
||||||
def test_copy_and_deepcopy_methods(self):
|
def test_copy_and_deepcopy_methods(self):
|
||||||
d = Decimal('43.24')
|
d = Decimal('43.24')
|
||||||
|
@ -2141,16 +2141,14 @@ class ContextFlags(unittest.TestCase):
|
||||||
for flag in extra_flags:
|
for flag in extra_flags:
|
||||||
if flag not in expected_flags:
|
if flag not in expected_flags:
|
||||||
expected_flags.append(flag)
|
expected_flags.append(flag)
|
||||||
expected_flags.sort()
|
|
||||||
|
|
||||||
# flags we actually got
|
# flags we actually got
|
||||||
new_flags = [k for k,v in context.flags.items() if v]
|
new_flags = [k for k,v in context.flags.items() if v]
|
||||||
new_flags.sort()
|
|
||||||
|
|
||||||
self.assertEqual(ans, new_ans,
|
self.assertEqual(ans, new_ans,
|
||||||
"operation produces different answers depending on flags set: " +
|
"operation produces different answers depending on flags set: " +
|
||||||
"expected %s, got %s." % (ans, new_ans))
|
"expected %s, got %s." % (ans, new_ans))
|
||||||
self.assertEqual(new_flags, expected_flags,
|
self.assertItemsEqual(new_flags, expected_flags,
|
||||||
"operation raises different flags depending on flags set: " +
|
"operation raises different flags depending on flags set: " +
|
||||||
"expected %s, got %s" % (expected_flags, new_flags))
|
"expected %s, got %s" % (expected_flags, new_flags))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue