mirror of
https://github.com/python/cpython.git
synced 2025-08-21 17:25:34 +00:00
Merged revisions 79187-79189 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79187 | florent.xicluna | 2010-03-21 12:50:44 +0200 (Sun, 21 Mar 2010) | 2 lines Silence more py3k warnings in unittest.case. ........ r79188 | florent.xicluna | 2010-03-21 12:51:40 +0200 (Sun, 21 Mar 2010) | 2 lines Fix py3k warnings in test_decimal, using unittest.assertItemsEqual. ........ r79189 | florent.xicluna | 2010-03-21 13:03:21 +0200 (Sun, 21 Mar 2010) | 2 lines Silence some py3k SyntaxWarning using check_py3k_warnings() with "exec" statements. ........
This commit is contained in:
parent
620f5c91d7
commit
d24b5d8fc7
3 changed files with 56 additions and 19 deletions
|
@ -2,6 +2,7 @@ import unittest
|
||||||
import sys
|
import sys
|
||||||
import _ast
|
import _ast
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
import textwrap
|
||||||
|
|
||||||
class TestSpecifics(unittest.TestCase):
|
class TestSpecifics(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -129,6 +130,9 @@ def f(x):
|
||||||
|
|
||||||
def test_complex_args(self):
|
def test_complex_args(self):
|
||||||
|
|
||||||
|
with test_support._check_py3k_warnings(
|
||||||
|
("tuple parameter unpacking has been removed", SyntaxWarning)):
|
||||||
|
exec textwrap.dedent('''
|
||||||
def comp_args((a, b)):
|
def comp_args((a, b)):
|
||||||
return a,b
|
return a,b
|
||||||
self.assertEqual(comp_args((1, 2)), (1, 2))
|
self.assertEqual(comp_args((1, 2)), (1, 2))
|
||||||
|
@ -146,6 +150,7 @@ def f(x):
|
||||||
return a, b, c
|
return a, b, c
|
||||||
self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3))
|
self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3))
|
||||||
self.assertEqual(comp_args(), (2, 3, 4))
|
self.assertEqual(comp_args(), (2, 3, 4))
|
||||||
|
''')
|
||||||
|
|
||||||
def test_argument_order(self):
|
def test_argument_order(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
import textwrap
|
||||||
|
|
||||||
class ComplexArgsTestCase(unittest.TestCase):
|
class ComplexArgsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def check(self, func, expected, *args):
|
def check(self, func, expected, *args):
|
||||||
self.assertEqual(func(*args), expected)
|
self.assertEqual(func(*args), expected)
|
||||||
|
|
||||||
# These functions are tested below as lambdas too. If you add a function test,
|
# These functions are tested below as lambdas too. If you add a
|
||||||
# also add a similar lambda test.
|
# 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):
|
def test_func_parens_no_unpacking(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
def f(((((x))))): return x
|
def f(((((x))))): return x
|
||||||
self.check(f, 1, 1)
|
self.check(f, 1, 1)
|
||||||
# Inner parens are elided, same as: f(x,)
|
# Inner parens are elided, same as: f(x,)
|
||||||
def f(((x)),): return x
|
def f(((x)),): return x
|
||||||
self.check(f, 2, 2)
|
self.check(f, 2, 2)
|
||||||
|
""")
|
||||||
|
|
||||||
def test_func_1(self):
|
def test_func_1(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
def f(((((x),)))): return x
|
def f(((((x),)))): return x
|
||||||
self.check(f, 3, (3,))
|
self.check(f, 3, (3,))
|
||||||
def f(((((x)),))): return x
|
def f(((((x)),))): return x
|
||||||
|
@ -26,16 +33,22 @@ class ComplexArgsTestCase(unittest.TestCase):
|
||||||
self.check(f, 5, (5,))
|
self.check(f, 5, (5,))
|
||||||
def f(((x),)): return x
|
def f(((x),)): return x
|
||||||
self.check(f, 6, (6,))
|
self.check(f, 6, (6,))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_func_2(self):
|
def test_func_2(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
def f(((((x)),),)): return x
|
def f(((((x)),),)): return x
|
||||||
self.check(f, 2, ((2,),))
|
self.check(f, 2, ((2,),))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_func_3(self):
|
def test_func_3(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
def f((((((x)),),),)): return x
|
def f((((((x)),),),)): return x
|
||||||
self.check(f, 3, (((3,),),))
|
self.check(f, 3, (((3,),),))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_func_complex(self):
|
def test_func_complex(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
def f((((((x)),),),), a, b, c): return x, a, b, c
|
def f((((((x)),),),), a, b, c): return x, a, b, c
|
||||||
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
|
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
|
||||||
|
|
||||||
|
@ -44,18 +57,22 @@ class ComplexArgsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def f(a, b, c, ((((((x)),)),),)): return a, b, c, x
|
def f(a, b, c, ((((((x)),)),),)): return a, b, c, x
|
||||||
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
|
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
|
||||||
|
""")
|
||||||
|
|
||||||
# Duplicate the tests above, but for lambda. If you add a lambda test,
|
# Duplicate the tests above, but for lambda. If you add a lambda test,
|
||||||
# also add a similar function test above.
|
# also add a similar function test above.
|
||||||
|
|
||||||
def test_lambda_parens_no_unpacking(self):
|
def test_lambda_parens_no_unpacking(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
f = lambda (((((x))))): x
|
f = lambda (((((x))))): x
|
||||||
self.check(f, 1, 1)
|
self.check(f, 1, 1)
|
||||||
# Inner parens are elided, same as: f(x,)
|
# Inner parens are elided, same as: f(x,)
|
||||||
f = lambda ((x)),: x
|
f = lambda ((x)),: x
|
||||||
self.check(f, 2, 2)
|
self.check(f, 2, 2)
|
||||||
|
""")
|
||||||
|
|
||||||
def test_lambda_1(self):
|
def test_lambda_1(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
f = lambda (((((x),)))): x
|
f = lambda (((((x),)))): x
|
||||||
self.check(f, 3, (3,))
|
self.check(f, 3, (3,))
|
||||||
f = lambda (((((x)),))): x
|
f = lambda (((((x)),))): x
|
||||||
|
@ -64,16 +81,22 @@ class ComplexArgsTestCase(unittest.TestCase):
|
||||||
self.check(f, 5, (5,))
|
self.check(f, 5, (5,))
|
||||||
f = lambda (((x),)): x
|
f = lambda (((x),)): x
|
||||||
self.check(f, 6, (6,))
|
self.check(f, 6, (6,))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_lambda_2(self):
|
def test_lambda_2(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
f = lambda (((((x)),),)): x
|
f = lambda (((((x)),),)): x
|
||||||
self.check(f, 2, ((2,),))
|
self.check(f, 2, ((2,),))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_lambda_3(self):
|
def test_lambda_3(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
f = lambda ((((((x)),),),)): x
|
f = lambda ((((((x)),),),)): x
|
||||||
self.check(f, 3, (((3,),),))
|
self.check(f, 3, (((3,),),))
|
||||||
|
""")
|
||||||
|
|
||||||
def test_lambda_complex(self):
|
def test_lambda_complex(self):
|
||||||
|
exec textwrap.dedent("""
|
||||||
f = lambda (((((x)),),),), a, b, c: (x, a, b, c)
|
f = lambda (((((x)),),),), a, b, c: (x, a, b, c)
|
||||||
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
|
self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
|
||||||
|
|
||||||
|
@ -82,10 +105,14 @@ class ComplexArgsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
f = lambda a, b, c, ((((((x)),)),),): (a, b, c, x)
|
f = lambda a, b, c, ((((((x)),)),),): (a, b, c, x)
|
||||||
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
|
self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
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__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -32,7 +32,7 @@ import unittest
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import numbers
|
import numbers
|
||||||
from test.test_support import (TestSkipped, run_unittest, run_doctest,
|
from test.test_support import (TestSkipped, run_unittest, run_doctest,
|
||||||
is_resource_enabled)
|
is_resource_enabled, _check_py3k_warnings)
|
||||||
import random
|
import random
|
||||||
try:
|
try:
|
||||||
import threading
|
import threading
|
||||||
|
@ -219,7 +219,7 @@ class DecimalTest(unittest.TestCase):
|
||||||
if skip_expected:
|
if skip_expected:
|
||||||
raise TestSkipped
|
raise TestSkipped
|
||||||
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:
|
||||||
|
@ -381,8 +381,9 @@ class DecimalTest(unittest.TestCase):
|
||||||
myexceptions = self.getexceptions()
|
myexceptions = self.getexceptions()
|
||||||
self.context.clear_flags()
|
self.context.clear_flags()
|
||||||
|
|
||||||
myexceptions.sort()
|
with _check_py3k_warnings(quiet=True):
|
||||||
theirexceptions.sort()
|
myexceptions.sort()
|
||||||
|
theirexceptions.sort()
|
||||||
|
|
||||||
self.assertEqual(result, ans,
|
self.assertEqual(result, ans,
|
||||||
'Incorrect answer for ' + s + ' -- got ' + result)
|
'Incorrect answer for ' + s + ' -- got ' + result)
|
||||||
|
@ -637,12 +638,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))
|
||||||
|
@ -1095,8 +1097,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')
|
||||||
|
@ -1556,18 +1559,20 @@ 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()
|
with _check_py3k_warnings(quiet=True):
|
||||||
|
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()
|
with _check_py3k_warnings(quiet=True):
|
||||||
|
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.assertEqual(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))
|
||||||
|
|
||||||
def test_main(arith=False, verbose=None, todo_tests=None, debug=None):
|
def test_main(arith=False, verbose=None, todo_tests=None, debug=None):
|
||||||
""" Execute the tests.
|
""" Execute the tests.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue