import unittest
from test import test_support
+import textwrap
class ComplexArgsTestCase(unittest.TestCase):
def check(self, func, expected, *args):
self.assertEqual(func(*args), expected)
- # These functions are tested below as lambdas too. If you add a function test,
- # also add a similar lambda test.
+ # These functions are tested below as lambdas too. If you add a
+ # function test, also add a similar lambda test.
+
+ # Functions are wrapped in "exec" statements in order to
+ # silence Py3k warnings.
def test_func_parens_no_unpacking(self):
+ exec textwrap.dedent("""
def f(((((x))))): return x
self.check(f, 1, 1)
# Inner parens are elided, same as: f(x,)
def f(((x)),): return x
self.check(f, 2, 2)
+ """)
def test_func_1(self):
+ exec textwrap.dedent("""
def f(((((x),)))): return x
self.check(f, 3, (3,))
def f(((((x)),))): return x
self.check(f, 5, (5,))
def f(((x),)): return x
self.check(f, 6, (6,))
+ """)
def test_func_2(self):
+ exec textwrap.dedent("""
def f(((((x)),),)): return x
self.check(f, 2, ((2,),))
+ """)
def test_func_3(self):
+ exec textwrap.dedent("""
def f((((((x)),),),)): return x
self.check(f, 3, (((3,),),))
+ """)
def test_func_complex(self):
+ exec textwrap.dedent("""
def f((((((x)),),),), a, b, c): return x, a, b, c
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
def f(a, b, c, ((((((x)),)),),)): return a, b, c, x
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
+ """)
# Duplicate the tests above, but for lambda. If you add a lambda test,
# also add a similar function test above.
def test_lambda_parens_no_unpacking(self):
+ exec textwrap.dedent("""
f = lambda (((((x))))): x
self.check(f, 1, 1)
# Inner parens are elided, same as: f(x,)
f = lambda ((x)),: x
self.check(f, 2, 2)
+ """)
def test_lambda_1(self):
+ exec textwrap.dedent("""
f = lambda (((((x),)))): x
self.check(f, 3, (3,))
f = lambda (((((x)),))): x
self.check(f, 5, (5,))
f = lambda (((x),)): x
self.check(f, 6, (6,))
+ """)
def test_lambda_2(self):
+ exec textwrap.dedent("""
f = lambda (((((x)),),)): x
self.check(f, 2, ((2,),))
+ """)
def test_lambda_3(self):
+ exec textwrap.dedent("""
f = lambda ((((((x)),),),)): x
self.check(f, 3, (((3,),),))
+ """)
def test_lambda_complex(self):
+ exec textwrap.dedent("""
f = lambda (((((x)),),),), a, b, c: (x, a, b, c)
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
f = lambda a, b, c, ((((((x)),)),),): (a, b, c, x)
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
+ """)
def test_main():
- test_support.run_unittest(ComplexArgsTestCase)
+ with test_support._check_py3k_warnings(
+ ("tuple parameter unpacking has been removed", SyntaxWarning),
+ ("parenthesized argument names are invalid", SyntaxWarning)):
+ test_support.run_unittest(ComplexArgsTestCase)
if __name__ == "__main__":
test_main()
from decimal import *
import numbers
from test.test_support import (TestSkipped, run_unittest, run_doctest,
- is_resource_enabled)
+ is_resource_enabled, _check_py3k_warnings)
import random
try:
import threading
if skip_expected:
raise TestSkipped
return
- for line in open(file).xreadlines():
+ for line in open(file):
line = line.replace('\r\n', '').replace('\n', '')
#print line
try:
myexceptions = self.getexceptions()
self.context.clear_flags()
- myexceptions.sort()
- theirexceptions.sort()
+ with _check_py3k_warnings(quiet=True):
+ myexceptions.sort()
+ theirexceptions.sort()
self.assertEqual(result, ans,
'Incorrect answer for ' + s + ' -- got ' + result)
('//', '__floordiv__', '__rfloordiv__'),
('**', '__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__'))
+ with _check_py3k_warnings():
+ 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))
self.assertEqual(a, b)
# with None
- self.assertFalse(Decimal(1) < None)
- self.assertTrue(Decimal(1) > None)
+ with _check_py3k_warnings():
+ self.assertFalse(Decimal(1) < None)
+ self.assertTrue(Decimal(1) > None)
def test_copy_and_deepcopy_methods(self):
d = Decimal('43.24')
for flag in extra_flags:
if flag not in expected_flags:
expected_flags.append(flag)
- expected_flags.sort()
+ with _check_py3k_warnings(quiet=True):
+ expected_flags.sort()
# flags we actually got
new_flags = [k for k,v in context.flags.items() if v]
- new_flags.sort()
+ with _check_py3k_warnings(quiet=True):
+ new_flags.sort()
self.assertEqual(ans, new_ans,
"operation produces different answers depending on flags set: " +
"expected %s, got %s." % (ans, new_ans))
self.assertEqual(new_flags, expected_flags,
- "operation raises different flags depending on flags set: " +
- "expected %s, got %s" % (expected_flags, new_flags))
+ "operation raises different flags depending on flags set: " +
+ "expected %s, got %s" % (expected_flags, new_flags))
def test_main(arith=False, verbose=None, todo_tests=None, debug=None):
""" Execute the tests.