Index: Lib/test/test_repr.py =================================================================== --- Lib/test/test_repr.py (revision 78803) +++ Lib/test/test_repr.py (working copy) @@ -8,7 +8,7 @@ import shutil import unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, check_py3k_warnings from repr import repr as r # Don't shadow builtin repr from repr import Repr @@ -174,7 +174,8 @@ def test_buffer(self): # XXX doesn't test buffers with no b_base or read-write buffers (see # bufferobject.c). The test is fairly incomplete too. Sigh. - x = buffer('foo') + with check_py3k_warnings(): + x = buffer('foo') self.assertTrue(repr(x).startswith(' 0): d2 = f.read(int(dlen)) Index: Lib/test/test_opcodes.py =================================================================== --- Lib/test/test_opcodes.py (revision 78803) +++ Lib/test/test_opcodes.py (working copy) @@ -1,6 +1,6 @@ # Python test set -- part 2, opcodes -from test.test_support import run_unittest +from test.test_support import run_unittest, check_py3k_warnings import unittest class OpcodeTest(unittest.TestCase): @@ -9,7 +9,7 @@ n = 0 for i in range(10): n = n+i - try: 1/0 + try: 1 // 0 except NameError: pass except ZeroDivisionError: pass except TypeError: pass @@ -110,7 +110,12 @@ def test_main(): - run_unittest(OpcodeTest) + with check_py3k_warnings(("exceptions must derive from BaseException", + DeprecationWarning), + ("catching classes that don't inherit " + "from BaseException is not allowed", + DeprecationWarning)): + run_unittest(OpcodeTest) if __name__ == '__main__': test_main() Index: Lib/test/test_inspect.py =================================================================== --- Lib/test/test_inspect.py (revision 78803) +++ Lib/test/test_inspect.py (working copy) @@ -4,10 +4,13 @@ import inspect import datetime -from test.test_support import run_unittest +from test.test_support import run_unittest, check_py3k_warnings -from test import inspect_fodder as mod -from test import inspect_fodder2 as mod2 +with check_py3k_warnings( + ("tuple parameter unpacking has been removed", SyntaxWarning), + quiet=True): + from test import inspect_fodder as mod + from test import inspect_fodder2 as mod2 # C module for test_findsource_binary import unicodedata @@ -29,7 +32,7 @@ import __builtin__ try: - 1/0 + 1 // 0 except: tb = sys.exc_traceback @@ -420,11 +423,14 @@ self.assertArgSpecEquals(A.m, ['self']) def test_getargspec_sublistofone(self): - def sublistOfOne((foo,)): return 1 - self.assertArgSpecEquals(sublistOfOne, [['foo']]) + with check_py3k_warnings( + ("tuple parameter unpacking has been removed", SyntaxWarning), + ("parenthesized argument names are invalid", SyntaxWarning)): + exec 'def sublistOfOne((foo,)): return 1' + self.assertArgSpecEquals(sublistOfOne, [['foo']]) - def fakeSublistOfOne((foo)): return 1 - self.assertArgSpecEquals(fakeSublistOfOne, ['foo']) + exec 'def fakeSublistOfOne((foo)): return 1' + self.assertArgSpecEquals(fakeSublistOfOne, ['foo']) def test_classify_oldstyle(self): class A: Index: Lib/test/test_array.py =================================================================== --- Lib/test/test_array.py (revision 78803) +++ Lib/test/test_array.py (working copy) @@ -749,7 +749,8 @@ def test_buffer(self): a = array.array(self.typecode, self.example) - b = buffer(a) + with test_support.check_py3k_warnings(): + b = buffer(a) self.assertEqual(b[0], a.tostring()[0]) def test_weakref(self): Index: Lib/test/test_complex_args.py =================================================================== --- Lib/test/test_complex_args.py (revision 78803) +++ Lib/test/test_complex_args.py (working copy) @@ -1,23 +1,30 @@ 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 @@ -26,16 +33,22 @@ 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) @@ -44,18 +57,22 @@ 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 @@ -64,16 +81,22 @@ 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) @@ -82,10 +105,14 @@ 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() Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (revision 78803) +++ Lib/test/test_socket.py (working copy) @@ -123,8 +123,9 @@ self.server_ready.wait() self.client_ready.set() self.clientSetUp() - if not callable(test_func): - raise TypeError, "test_func must be a callable function" + with test_support.check_py3k_warnings(): + if not callable(test_func): + raise TypeError("test_func must be a callable function.") try: test_func() except Exception, strerror: @@ -132,7 +133,7 @@ self.clientTearDown() def clientSetUp(self): - raise NotImplementedError, "clientSetUp must be implemented." + raise NotImplementedError("clientSetUp must be implemented.") def clientTearDown(self): self.done.set() @@ -282,8 +283,8 @@ orig = sys.getrefcount(__name__) socket.getnameinfo(__name__,0) except TypeError: - if sys.getrefcount(__name__) <> orig: - self.fail("socket.getnameinfo loses a reference") + self.assertEqual(sys.getrefcount(__name__), orig, + "socket.getnameinfo loses a reference") def testInterpreterCrash(self): # Making sure getnameinfo doesn't crash the interpreter @@ -1234,7 +1235,8 @@ self.assertEqual(msg, MSG) def _testRecvInto(self): - buf = buffer(MSG) + with test_support.check_py3k_warnings(): + buf = buffer(MSG) self.serv_conn.send(buf) def testRecvFromInto(self): @@ -1245,7 +1247,8 @@ self.assertEqual(msg, MSG) def _testRecvFromInto(self): - buf = buffer(MSG) + with test_support.check_py3k_warnings(): + buf = buffer(MSG) self.serv_conn.send(buf) Index: Lib/test/test_heapq.py =================================================================== --- Lib/test/test_heapq.py (revision 78803) +++ Lib/test/test_heapq.py (working copy) @@ -356,7 +356,10 @@ for f in (self.module.nlargest, self.module.nsmallest): for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)): for g in (G, I, Ig, L, R): - self.assertEqual(f(2, g(s)), f(2,s)) + with test_support.check_py3k_warnings( + ("comparing unequal types not supported", + DeprecationWarning), quiet=True): + self.assertEqual(f(2, g(s)), f(2,s)) self.assertEqual(f(2, S(s)), []) self.assertRaises(TypeError, f, 2, X(s)) self.assertRaises(TypeError, f, 2, N(s)) Index: Lib/test/test_StringIO.py =================================================================== --- Lib/test/test_StringIO.py (revision 78803) +++ Lib/test/test_StringIO.py (working copy) @@ -137,12 +137,10 @@ def test_main(): - test_support.run_unittest( - TestStringIO, - TestcStringIO, - TestBufferStringIO, - TestBuffercStringIO - ) + test_support.run_unittest(TestStringIO, TestcStringIO) + with test_support.check_py3k_warnings(("buffer.. not supported", + DeprecationWarning)): + test_support.run_unittest(TestBufferStringIO, TestBuffercStringIO) if __name__ == '__main__': test_main() Index: Lib/test/test_long.py =================================================================== --- Lib/test/test_long.py (revision 78803) +++ Lib/test/test_long.py (working copy) @@ -574,11 +574,12 @@ def __getslice__(self, i, j): return i, j - self.assertEqual(X()[-5L:7L], (-5, 7)) - # use the clamping effect to test the smallest and largest longs - # that fit a Py_ssize_t - slicemin, slicemax = X()[-2L**100:2L**100] - self.assertEqual(X()[slicemin:slicemax], (slicemin, slicemax)) + with test_support.check_py3k_warnings(): + self.assertEqual(X()[-5L:7L], (-5, 7)) + # use the clamping effect to test the smallest and largest longs + # that fit a Py_ssize_t + slicemin, slicemax = X()[-2L**100:2L**100] + self.assertEqual(X()[slicemin:slicemax], (slicemin, slicemax)) # ----------------------------------- tests of auto int->long conversion @@ -616,8 +617,9 @@ checkit(x, '*', y) if y: - expected = longx / longy - got = x / y + with test_support.check_py3k_warnings(): + expected = longx / longy + got = x / y checkit(x, '/', y) expected = longx // longy Index: Lib/test/test_syntax.py =================================================================== --- Lib/test/test_syntax.py (revision 78803) +++ Lib/test/test_syntax.py (working copy) @@ -552,7 +552,9 @@ def test_main(): test_support.run_unittest(SyntaxTestCase) from test import test_syntax - test_support.run_doctest(test_syntax, verbosity=True) + with test_support.check_py3k_warnings(("backquote not supported", + SyntaxWarning)): + test_support.run_doctest(test_syntax, verbosity=True) if __name__ == "__main__": test_main() Index: Lib/test/test_tarfile.py =================================================================== --- Lib/test/test_tarfile.py (revision 78803) +++ Lib/test/test_tarfile.py (working copy) @@ -711,7 +711,9 @@ return os.path.isfile(name) tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") - tar.add(tempdir, arcname="empty_dir", exclude=exclude) + # DeprecationWarning: use the filter argument instead + with test_support.check_warnings(): + tar.add(tempdir, arcname="empty_dir", exclude=exclude) tar.close() tar = tarfile.open(tmpname, "r") Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (revision 78803) +++ Lib/test/test_compile.py (working copy) @@ -2,6 +2,7 @@ import sys import _ast from test import test_support +import textwrap class TestSpecifics(unittest.TestCase): @@ -142,6 +143,9 @@ 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)): return a,b self.assertEqual(comp_args((1, 2)), (1, 2)) @@ -159,6 +163,7 @@ return a, b, c self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) self.assertEqual(comp_args(), (2, 3, 4)) + ''') def test_argument_order(self): try: Index: Lib/test/list_tests.py =================================================================== --- Lib/test/list_tests.py (revision 78803) +++ Lib/test/list_tests.py (working copy) @@ -36,7 +36,7 @@ self.assertEqual(str(a0), str(l0)) self.assertEqual(repr(a0), repr(l0)) - self.assertEqual(`a2`, `l2`) + self.assertEqual(repr(a2), repr(l2)) self.assertEqual(str(a2), "[0, 1, 2]") self.assertEqual(repr(a2), "[0, 1, 2]") @@ -421,6 +421,11 @@ self.assertRaises(TypeError, u.reverse, 42) def test_sort(self): + with test_support.check_py3k_warnings( + ("the cmp argument is not supported", DeprecationWarning)): + self._test_sort() + + def _test_sort(self): u = self.type2test([1, 0]) u.sort() self.assertEqual(u, [0, 1]) Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 78803) +++ Lib/test/test_doctest.py (working copy) @@ -2169,7 +2169,7 @@ >>> doctest.master = None # Reset master. (Note: we'll be clearing doctest.master after each call to -`doctest.testfile`, to supress warnings about multiple tests with the +`doctest.testfile`, to suppress warnings about multiple tests with the same name.) Globals may be specified with the `globs` and `extraglobs` parameters: @@ -2462,9 +2462,13 @@ def test_main(): # Check the doctest cases in doctest itself: test_support.run_doctest(doctest, verbosity=True) + # Check the doctest cases defined here: from test import test_doctest - test_support.run_doctest(test_doctest, verbosity=True) + with test_support.check_py3k_warnings( + ("backquote not supported", SyntaxWarning), + ("execfile.. not supported", DeprecationWarning)): + test_support.run_doctest(test_doctest, verbosity=True) import trace, sys def test_coverage(coverdir): Index: Lib/test/test_sort.py =================================================================== --- Lib/test/test_sort.py (revision 78803) +++ Lib/test/test_sort.py (working copy) @@ -185,7 +185,7 @@ def test_stability(self): data = [(random.randrange(100), i) for i in xrange(200)] copy = data[:] - data.sort(key=lambda (x,y): x) # sort on the random first field + data.sort(key=lambda x: x[0]) # sort on the random first field copy.sort() # sort using both fields self.assertEqual(data, copy) # should get the same result @@ -207,7 +207,7 @@ # Verify that the wrapper has been removed data = range(-2,2) dup = data[:] - self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x) + self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1 // x) self.assertEqual(data, dup) def test_key_with_mutation(self): @@ -274,17 +274,19 @@ TestBugs, ) - test_support.run_unittest(*test_classes) - - # verify reference counting - if verbose and hasattr(sys, "gettotalrefcount"): - import gc - counts = [None] * 5 - for i in xrange(len(counts)): - test_support.run_unittest(*test_classes) - gc.collect() - counts[i] = sys.gettotalrefcount() - print counts + with test_support.check_py3k_warnings( + ("the cmp argument is not supported", DeprecationWarning)): + test_support.run_unittest(*test_classes) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in xrange(len(counts)): + test_support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print counts if __name__ == "__main__": test_main(verbose=True) Index: Lib/test/test_operator.py =================================================================== --- Lib/test/test_operator.py (revision 78803) +++ Lib/test/test_operator.py (working copy) @@ -192,7 +192,8 @@ class C: pass def check(self, o, v): - self.assertTrue(operator.isCallable(o) == callable(o) == v) + with test_support.check_py3k_warnings(): + self.assertTrue(operator.isCallable(o) == callable(o) == v) check(self, 4, 0) check(self, operator.isCallable, 1) check(self, C, 1) @@ -306,8 +307,9 @@ self.assertRaises(TypeError, operator.contains, None, None) self.assertTrue(operator.contains(range(4), 2)) self.assertFalse(operator.contains(range(4), 5)) - self.assertTrue(operator.sequenceIncludes(range(4), 2)) - self.assertFalse(operator.sequenceIncludes(range(4), 5)) + with test_support.check_py3k_warnings(): + self.assertTrue(operator.sequenceIncludes(range(4), 2)) + self.assertFalse(operator.sequenceIncludes(range(4), 5)) def test_setitem(self): a = range(3) Index: Lib/test/test_types.py =================================================================== --- Lib/test/test_types.py (revision 78803) +++ Lib/test/test_types.py (working copy) @@ -1,6 +1,7 @@ # Python test set -- part 6, built-in types -from test.test_support import run_unittest, have_unicode, run_with_locale +from test.test_support import run_unittest, have_unicode, run_with_locale, \ + check_py3k_warnings import unittest import sys import locale @@ -741,7 +742,10 @@ self.assertRaises(ValueError, format, 0, ',' + code) def test_main(): - run_unittest(TypesTests) + with check_py3k_warnings( + ("buffer.. not supported", DeprecationWarning), + ("classic long division", DeprecationWarning)): + run_unittest(TypesTests) if __name__ == '__main__': test_main() Index: Lib/test/test_peepholer.py =================================================================== --- Lib/test/test_peepholer.py (revision 78803) +++ Lib/test/test_peepholer.py (working copy) @@ -206,17 +206,20 @@ import sys from test import test_support test_classes = (TestTranforms,) - test_support.run_unittest(*test_classes) - # verify reference counting - if verbose and hasattr(sys, "gettotalrefcount"): - import gc - counts = [None] * 5 - for i in xrange(len(counts)): - test_support.run_unittest(*test_classes) - gc.collect() - counts[i] = sys.gettotalrefcount() - print counts + with test_support.check_py3k_warnings( + ("backquote not supported", SyntaxWarning)): + test_support.run_unittest(*test_classes) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in xrange(len(counts)): + test_support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print counts if __name__ == "__main__": test_main(verbose=True) Index: Lib/test/test_zipimport_support.py =================================================================== --- Lib/test/test_zipimport_support.py (revision 78803) +++ Lib/test/test_zipimport_support.py (working copy) @@ -166,8 +166,13 @@ test_zipped_doctest.test_testfile, test_zipped_doctest.test_unittest_reportflags, ] - for obj in known_good_tests: - _run_object_doctest(obj, test_zipped_doctest) + # Silence Py3k warning + # Needed for test_DocTestParser and test_debug + with test.test_support.check_py3k_warnings( + ("backquote not supported", SyntaxWarning), + ("execfile.. not supported", DeprecationWarning)): + for obj in known_good_tests: + _run_object_doctest(obj, test_zipped_doctest) def test_doctest_main_issue4197(self): test_src = textwrap.dedent("""\ Index: Lib/test/test_buffer.py =================================================================== --- Lib/test/test_buffer.py (revision 78803) +++ Lib/test/test_buffer.py (working copy) @@ -23,7 +23,9 @@ def test_main(): - test_support.run_unittest(BufferTests) + with test_support.check_py3k_warnings(("buffer.. not supported", + DeprecationWarning)): + test_support.run_unittest(BufferTests) if __name__ == "__main__": test_main() Index: Lib/test/test_scope.py =================================================================== --- Lib/test/test_scope.py (revision 78803) +++ Lib/test/test_scope.py (working copy) @@ -1,5 +1,6 @@ import unittest -from test.test_support import check_syntax_error, run_unittest +from test.test_support import check_syntax_error, run_unittest, \ + check_py3k_warnings import warnings warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "") @@ -321,10 +322,14 @@ self.assertEqual(makeReturner2(a=11)()['a'], 11) - def makeAddPair((a, b)): - def addPair((c, d)): - return (a + c, b + d) - return addPair + with check_py3k_warnings(("tuple parameter unpacking " + "has been removed", SyntaxWarning)): + exec """\ +def makeAddPair((a, b)): + def addPair((c, d)): + return (a + c, b + d) + return addPair +""" in locals() self.assertEqual(makeAddPair((1, 2))((100, 200)), (101,202)) @@ -471,7 +476,7 @@ return g d = f(2)(4) - self.assertTrue(d.has_key('h')) + self.assertTrue('h' in d) del d['h'] self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6}) Index: Lib/test/test_marshal.py =================================================================== --- Lib/test/test_marshal.py (revision 78803) +++ Lib/test/test_marshal.py (working copy) @@ -129,7 +129,9 @@ def test_buffer(self): for s in ["", "Andrč Previn", "abc", " "*10000]: - b = buffer(s) + with test_support.check_py3k_warnings(("buffer.. not supported", + DeprecationWarning)): + b = buffer(s) new = marshal.loads(marshal.dumps(b)) self.assertEqual(s, new) marshal.dump(b, file(test_support.TESTFN, "wb")) Index: Lib/test/test_iter.py =================================================================== --- Lib/test/test_iter.py (revision 78803) +++ Lib/test/test_iter.py (working copy) @@ -1,7 +1,8 @@ # Test iterators. import unittest -from test.test_support import run_unittest, TESTFN, unlink, have_unicode +from test.test_support import run_unittest, TESTFN, unlink, have_unicode, \ + check_py3k_warnings # Test result of triple loop (too big to inline) TRIPLETS = [(0, 0, 0), (0, 0, 1), (0, 0, 2), @@ -396,21 +397,24 @@ # Test map()'s use of iterators. def test_builtin_map(self): - self.assertEqual(map(None, SequenceClass(5)), range(5)) self.assertEqual(map(lambda x: x+1, SequenceClass(5)), range(1, 6)) d = {"one": 1, "two": 2, "three": 3} - self.assertEqual(map(None, d), d.keys()) self.assertEqual(map(lambda k, d=d: (k, d[k]), d), d.items()) dkeys = d.keys() expected = [(i < len(d) and dkeys[i] or None, i, i < len(d) and dkeys[i] or None) for i in range(5)] - self.assertEqual(map(None, d, - SequenceClass(5), - iter(d.iterkeys())), - expected) + + # Deprecated map(None, ...) + with check_py3k_warnings(): + self.assertEqual(map(None, SequenceClass(5)), range(5)) + self.assertEqual(map(None, d), d.keys()) + self.assertEqual(map(None, d, + SequenceClass(5), + iter(d.iterkeys())), + expected) f = open(TESTFN, "w") try: @@ -506,7 +510,11 @@ self.assertEqual(zip(x, y), expected) # Test reduces()'s use of iterators. - def test_builtin_reduce(self): + def test_deprecated_builtin_reduce(self): + with check_py3k_warnings(): + self._test_builtin_reduce() + + def _test_builtin_reduce(self): from operator import add self.assertEqual(reduce(add, SequenceClass(5)), 10) self.assertEqual(reduce(add, SequenceClass(5), 42), 52) Index: Lib/test/mapping_tests.py =================================================================== --- Lib/test/mapping_tests.py (revision 78803) +++ Lib/test/mapping_tests.py (working copy) @@ -1,6 +1,7 @@ # tests common to dict and UserDict import unittest import UserDict +import test_support class BasicTestMappingProtocol(unittest.TestCase): @@ -54,13 +55,17 @@ #len self.assertEqual(len(p), 0) self.assertEqual(len(d), len(self.reference)) - #has_key + #in for k in self.reference: - self.assertTrue(d.has_key(k)) self.assertIn(k, d) for k in self.other: - self.assertFalse(d.has_key(k)) self.assertNotIn(k, d) + #has_key + with test_support.check_py3k_warnings(quiet=True): + for k in self.reference: + self.assertTrue(d.has_key(k)) + for k in self.other: + self.assertFalse(d.has_key(k)) #cmp self.assertEqual(cmp(p,p), 0) self.assertEqual(cmp(d,d), 0) Index: Lib/test/test_sets.py =================================================================== --- Lib/test/test_sets.py (revision 78803) +++ Lib/test/test_sets.py (working copy) @@ -510,15 +510,16 @@ self.assertEqual(self.set != self.other, True) def test_ge_gt_le_lt(self): - self.assertRaises(TypeError, lambda: self.set < self.other) - self.assertRaises(TypeError, lambda: self.set <= self.other) - self.assertRaises(TypeError, lambda: self.set > self.other) - self.assertRaises(TypeError, lambda: self.set >= self.other) - - self.assertRaises(TypeError, lambda: self.other < self.set) - self.assertRaises(TypeError, lambda: self.other <= self.set) - self.assertRaises(TypeError, lambda: self.other > self.set) - self.assertRaises(TypeError, lambda: self.other >= self.set) + with test_support.check_py3k_warnings(quiet=True): + self.assertRaises(TypeError, lambda: self.set < self.other) + self.assertRaises(TypeError, lambda: self.set <= self.other) + self.assertRaises(TypeError, lambda: self.set > self.other) + self.assertRaises(TypeError, lambda: self.set >= self.other) + + self.assertRaises(TypeError, lambda: self.other < self.set) + self.assertRaises(TypeError, lambda: self.other <= self.set) + self.assertRaises(TypeError, lambda: self.other > self.set) + self.assertRaises(TypeError, lambda: self.other >= self.set) def test_union_update_operator(self): try: @@ -679,20 +680,11 @@ def test_copy(self): dup = self.set.copy() - dup_list = list(dup); dup_list.sort() - set_list = list(self.set); set_list.sort() - self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertTrue(dup_list[i] is set_list[i]) + self.assertSetEqual(dup, self.set) def test_deep_copy(self): dup = copy.deepcopy(self.set) - ##print type(dup), repr(dup) - dup_list = list(dup); dup_list.sort() - set_list = list(self.set); set_list.sort() - self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertEqual(dup_list[i], set_list[i]) + self.assertSetEqual(dup, self.set) #------------------------------------------------------------------------------ Index: Lib/test/test_MimeWriter.py =================================================================== --- Lib/test/test_MimeWriter.py (revision 78803) +++ Lib/test/test_MimeWriter.py (working copy) @@ -8,11 +8,10 @@ """ import unittest, StringIO -from test.test_support import run_unittest +from test.test_support import run_unittest, import_module -import warnings -warnings.filterwarnings("ignore", "the MimeWriter module is deprecated.*", - DeprecationWarning) +import_module("mimetools", deprecated=True) +import_module("MimeWriter", deprecated=True) from MimeWriter import MimeWriter Index: Lib/test/test_univnewlines2k.py =================================================================== --- Lib/test/test_univnewlines2k.py (revision 78803) +++ Lib/test/test_univnewlines2k.py (working copy) @@ -80,7 +80,8 @@ def test_execfile(self): namespace = {} - execfile(test_support.TESTFN, namespace) + with test_support.check_py3k_warnings(): + execfile(test_support.TESTFN, namespace) func = namespace['line3'] self.assertEqual(func.func_code.co_firstlineno, 3) self.assertEqual(namespace['line4'], FATX) Index: Lib/test/test_grammar.py =================================================================== --- Lib/test/test_grammar.py (revision 78803) +++ Lib/test/test_grammar.py (working copy) @@ -8,7 +8,8 @@ # regression test, the filterwarnings() call has been added to # regrtest.py. -from test.test_support import run_unittest, check_syntax_error +from test.test_support import run_unittest, check_syntax_error, \ + check_py3k_warnings import unittest import sys # testing import * @@ -152,8 +153,9 @@ f1(*(), **{}) def f2(one_argument): pass def f3(two, arguments): pass - def f4(two, (compound, (argument, list))): pass - def f5((compound, first), two): pass + # Silence Py3k warning + exec('def f4(two, (compound, (argument, list))): pass') + exec('def f5((compound, first), two): pass') self.assertEquals(f2.func_code.co_varnames, ('one_argument',)) self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments')) if sys.platform.startswith('java'): @@ -172,7 +174,8 @@ def v0(*rest): pass def v1(a, *rest): pass def v2(a, b, *rest): pass - def v3(a, (b, c), *rest): return a, b, c, rest + # Silence Py3k warning + exec('def v3(a, (b, c), *rest): return a, b, c, rest') f1() f2(1) @@ -277,9 +280,10 @@ d22v(*(1, 2, 3, 4)) d22v(1, 2, *(3, 4, 5)) d22v(1, *(2, 3), **{'d': 4}) - def d31v((x)): pass + # Silence Py3k warning + exec('def d31v((x)): pass') + exec('def d32v((x,)): pass') d31v(1) - def d32v((x,)): pass d32v((1,)) # keyword arguments after *arglist @@ -474,7 +478,7 @@ continue except: raise - if count > 2 or big_hippo <> 1: + if count > 2 or big_hippo != 1: self.fail("continue then break in try/except in loop broken!") test_inner() @@ -677,7 +681,6 @@ x = (1 == 1) if 1 == 1: pass if 1 != 1: pass - if 1 <> 1: pass if 1 < 1: pass if 1 > 1: pass if 1 <= 1: pass @@ -686,7 +689,10 @@ if 1 is not 1: pass if 1 in (): pass if 1 not in (): pass - if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass + if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1: pass + # Silence Py3k warning + if eval('1 <> 1'): pass + if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass def testBinaryMaskOps(self): x = 1 & 1 @@ -774,9 +780,10 @@ x = {'one', 'two', 'three'} x = {2, 3, 4,} - x = `x` - x = `1 or 2 or 3` - self.assertEqual(`1,2`, '(1, 2)') + # Silence Py3k warning + x = eval('`x`') + x = eval('`1 or 2 or 3`') + self.assertEqual(eval('`1,2`'), '(1, 2)') x = x x = 'x' @@ -988,7 +995,13 @@ def test_main(): - run_unittest(TokenTests, GrammarTests) + with check_py3k_warnings( + ("backquote not supported", SyntaxWarning), + ("tuple parameter unpacking has been removed", SyntaxWarning), + ("parenthesized argument names are invalid", SyntaxWarning), + ("classic int division", DeprecationWarning), + (".+ not supported in 3.x", DeprecationWarning)): + run_unittest(TokenTests, GrammarTests) if __name__ == '__main__': test_main() Index: Lib/test/test_decimal.py =================================================================== --- Lib/test/test_decimal.py (revision 78803) +++ Lib/test/test_decimal.py (working copy) @@ -30,7 +30,8 @@ import unittest from decimal import * 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 try: import threading @@ -179,7 +180,20 @@ return True return False -class DecimalTest(unittest.TestCase): +class BaseTestCase(unittest.TestCase): + + def assertSameElements(self, expected_seq, actual_seq, msg=None): + # Fix the default assertSameElements: + # - [0, 1] and [1, 0, 1] compare unequal. See #7832 + with check_py3k_warnings( + ("comparing unequal types not supported", DeprecationWarning), + ("type inequality comparisons not supported", + DeprecationWarning), + quiet=True): + self.assertEqual(sorted(expected_seq), sorted(actual_seq), msg) + + +class DecimalTest(BaseTestCase): """Class which tests the Decimal class against the test cases. Changed for unittest. @@ -201,7 +215,7 @@ if skip_expected: raise unittest.SkipTest return - for line in open(file).xreadlines(): + for line in open(file): line = line.replace('\r\n', '').replace('\n', '') #print line try: @@ -360,12 +374,9 @@ myexceptions = self.getexceptions() self.context.clear_flags() - myexceptions.sort() - theirexceptions.sort() - self.assertEqual(result, ans, 'Incorrect answer for ' + s + ' -- got ' + result) - self.assertEqual(myexceptions, theirexceptions, + self.assertSameElements(myexceptions, theirexceptions, 'Incorrect flags set in ' + s + ' -- got ' + str(myexceptions)) return @@ -387,7 +398,7 @@ # The following classes test the behaviour of Decimal according to PEP 327 -class DecimalExplicitConstructionTest(unittest.TestCase): +class DecimalExplicitConstructionTest(BaseTestCase): '''Unit tests for Explicit Construction cases of Decimal.''' def test_explicit_empty(self): @@ -557,7 +568,7 @@ self.assertEqual(str(Decimal(input)), expected) -class DecimalImplicitConstructionTest(unittest.TestCase): +class DecimalImplicitConstructionTest(BaseTestCase): '''Unit tests for Implicit Construction cases of Decimal.''' def test_implicit_from_None(self): @@ -616,12 +627,13 @@ ('//', '__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)) @@ -632,7 +644,7 @@ '10' + rop + 'str') -class DecimalFormatTest(unittest.TestCase): +class DecimalFormatTest(BaseTestCase): '''Unit tests for the format function.''' def test_formatting(self): # triples giving a format, a Decimal, and the expected result @@ -851,7 +863,7 @@ self.assertEqual(get_fmt(123456, crazy, '013n'), '000-01-2345-6') -class DecimalArithmeticOperatorsTest(unittest.TestCase): +class DecimalArithmeticOperatorsTest(BaseTestCase): '''Unit tests for all arithmetic operators, binary and unary.''' def test_addition(self): @@ -1123,7 +1135,7 @@ return -class DecimalUseOfContextTest(unittest.TestCase): +class DecimalUseOfContextTest(BaseTestCase): '''Unit tests for Use of Context cases in Decimal.''' try: @@ -1155,7 +1167,7 @@ del test_threading -class DecimalUsabilityTest(unittest.TestCase): +class DecimalUsabilityTest(BaseTestCase): '''Unit tests for Usability cases of Decimal.''' def test_comparison_operators(self): @@ -1199,8 +1211,9 @@ 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') @@ -1529,7 +1542,7 @@ Decimal(-12).fma(Decimal(45), Decimal(67))) -class DecimalPythonAPItests(unittest.TestCase): +class DecimalPythonAPItests(BaseTestCase): def test_abc(self): self.assertTrue(issubclass(Decimal, numbers.Number)) @@ -1622,7 +1635,7 @@ self.assertEqual(repr(context.create_decimal_from_float(10)), "Decimal('10')") -class ContextAPItests(unittest.TestCase): +class ContextAPItests(BaseTestCase): def test_pickle(self): c = Context() @@ -2076,7 +2089,7 @@ self.assertEqual(c.to_integral_value(10), d) self.assertRaises(TypeError, c.to_integral_value, '10') -class WithStatementTest(unittest.TestCase): +class WithStatementTest(BaseTestCase): # Can't do these as docstrings until Python 2.6 # as doctest can't handle __future__ statements @@ -2102,7 +2115,7 @@ self.assertTrue(new_ctx is not set_ctx, 'did not copy the context') self.assertTrue(set_ctx is enter_ctx, '__enter__ returned wrong context') -class ContextFlags(unittest.TestCase): +class ContextFlags(BaseTestCase): def test_flags_irrelevant(self): # check that the result (numeric result + flags raised) of an # arithmetic operation doesn't depend on the current flags @@ -2141,16 +2154,14 @@ for flag in extra_flags: if flag not in expected_flags: expected_flags.append(flag) - expected_flags.sort() # flags we actually got new_flags = [k for k,v in context.flags.items() if v] - 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, + self.assertSameElements(new_flags, expected_flags, "operation raises different flags depending on flags set: " + "expected %s, got %s" % (expected_flags, new_flags)) Index: Lib/test/test_undocumented_details.py =================================================================== --- Lib/test/test_undocumented_details.py (revision 78803) +++ Lib/test/test_undocumented_details.py (working copy) @@ -1,4 +1,4 @@ -from test.test_support import run_unittest +from test.test_support import run_unittest, check_py3k_warnings import unittest class TestImplementationComparisons(unittest.TestCase): @@ -32,7 +32,8 @@ self.assertTrue(g_cell != h_cell) def test_main(): - run_unittest(TestImplementationComparisons) + with check_py3k_warnings(): + run_unittest(TestImplementationComparisons) if __name__ == '__main__': test_main() Index: Lib/test/test_struct.py =================================================================== --- Lib/test/test_struct.py (revision 78803) +++ Lib/test/test_struct.py (working copy) @@ -2,7 +2,7 @@ import unittest import struct import warnings -from test.test_support import run_unittest +from test.test_support import run_unittest, check_warnings, check_py3k_warnings import sys ISBIGENDIAN = sys.byteorder == "big" @@ -297,10 +297,21 @@ def __long__(self): return -163L - for badobject in ("a string", 3+42j, randrange): + self.assertRaises((TypeError, struct.error), + struct.pack, self.format, + "a string") + self.assertRaises((TypeError, struct.error), + struct.pack, self.format, + randrange) + self.assertRaises((TypeError, struct.error), + struct.pack, self.format, + randrange) + with check_warnings(("integer argument expected, " + "got non-integer", DeprecationWarning), + quiet=True): self.assertRaises((TypeError, struct.error), struct.pack, self.format, - badobject) + 3+42j) # an attempt to convert a non-integer (with an # implicit conversion via __int__) should succeed, @@ -395,28 +406,28 @@ self.check_float_coerce(endian + fmt, 1.0) self.check_float_coerce(endian + fmt, 1.5) - def test_unpack_from(self): + def test_unpack_from(self, cls=str): test_string = 'abcd01234' fmt = '4s' s = struct.Struct(fmt) - for cls in (str, buffer): - data = cls(test_string) - self.assertEqual(s.unpack_from(data), ('abcd',)) - self.assertEqual(s.unpack_from(data, 2), ('cd01',)) - self.assertEqual(s.unpack_from(data, 4), ('0123',)) - for i in xrange(6): - self.assertEqual(s.unpack_from(data, i), (data[i:i+4],)) - for i in xrange(6, len(test_string) + 1): - self.assertRaises(struct.error, s.unpack_from, data, i) - for cls in (str, buffer): - data = cls(test_string) - self.assertEqual(struct.unpack_from(fmt, data), ('abcd',)) - self.assertEqual(struct.unpack_from(fmt, data, 2), ('cd01',)) - self.assertEqual(struct.unpack_from(fmt, data, 4), ('0123',)) - for i in xrange(6): - self.assertEqual(struct.unpack_from(fmt, data, i), (data[i:i+4],)) - for i in xrange(6, len(test_string) + 1): - self.assertRaises(struct.error, struct.unpack_from, fmt, data, i) + + data = cls(test_string) + self.assertEqual(s.unpack_from(data), ('abcd',)) + self.assertEqual(s.unpack_from(data, 2), ('cd01',)) + self.assertEqual(s.unpack_from(data, 4), ('0123',)) + for i in xrange(6): + self.assertEqual(s.unpack_from(data, i), (data[i:i+4],)) + for i in xrange(6, len(test_string) + 1): + self.assertRaises(struct.error, s.unpack_from, data, i) + + data = cls(test_string) + self.assertEqual(struct.unpack_from(fmt, data), ('abcd',)) + self.assertEqual(struct.unpack_from(fmt, data, 2), ('cd01',)) + self.assertEqual(struct.unpack_from(fmt, data, 4), ('0123',)) + for i in xrange(6): + self.assertEqual(struct.unpack_from(fmt, data, i), (data[i:i+4],)) + for i in xrange(6, len(test_string) + 1): + self.assertRaises(struct.error, struct.unpack_from, fmt, data, i) def test_pack_into(self): test_string = 'Reykjavik rocks, eow!' @@ -465,17 +476,21 @@ self.assertRaises(struct.error, pack_into, small_buf, 2, test_string) def test_unpack_with_buffer(self): - # SF bug 1563759: struct.unpack doens't support buffer protocol objects - data1 = array.array('B', '\x12\x34\x56\x78') - data2 = buffer('......\x12\x34\x56\x78......', 6, 4) - for data in [data1, data2]: - value, = struct.unpack('>I', data) - self.assertEqual(value, 0x12345678) + with check_py3k_warnings(("buffer.. not supported in 3.x", + DeprecationWarning)): + # SF bug 1563759: struct.unpack doens't support buffer protocol objects + data1 = array.array('B', '\x12\x34\x56\x78') + data2 = buffer('......\x12\x34\x56\x78......', 6, 4) + for data in [data1, data2]: + value, = struct.unpack('>I', data) + self.assertEqual(value, 0x12345678) + + self.test_unpack_from(cls=buffer) def test_bool(self): for prefix in tuple("<>!=")+('',): false = (), [], [], '', 0 - true = [1], 'test', 5, -1, 0xffffffffL+1, 0xffffffff/2 + true = [1], 'test', 5, -1, 0xffffffffL+1, 0xffffffff//2 falseFormat = prefix + '?' * len(false) packedFalse = struct.pack(falseFormat, *false) Index: Lib/test/test_weakref.py =================================================================== --- Lib/test/test_weakref.py (revision 78803) +++ Lib/test/test_weakref.py (working copy) @@ -54,10 +54,10 @@ # Live reference: o = C() wr = weakref.ref(o) - `wr` + repr(wr) # Dead reference: del o - `wr` + repr(wr) def test_basic_callback(self): self.check_basic_callback(C) @@ -169,7 +169,8 @@ p.append(12) self.assertEqual(len(L), 1) self.assertTrue(p, "proxy for non-empty UserList should be true") - p[:] = [2, 3] + with test_support.check_py3k_warnings(): + p[:] = [2, 3] self.assertEqual(len(L), 2) self.assertEqual(len(p), 2) self.assertIn(3, p, "proxy didn't support __contains__() properly") @@ -182,10 +183,11 @@ ## self.assertEqual(repr(L2), repr(p2)) L3 = UserList.UserList(range(10)) p3 = weakref.proxy(L3) - self.assertEqual(L3[:], p3[:]) - self.assertEqual(L3[5:], p3[5:]) - self.assertEqual(L3[:5], p3[:5]) - self.assertEqual(L3[2:5], p3[2:5]) + with test_support.check_py3k_warnings(): + self.assertEqual(L3[:], p3[:]) + self.assertEqual(L3[5:], p3[5:]) + self.assertEqual(L3[:5], p3[:5]) + self.assertEqual(L3[2:5], p3[2:5]) def test_proxy_unicode(self): # See bug 5037 @@ -831,7 +833,7 @@ def test_weak_keys(self): # # This exercises d.copy(), d.items(), d[] = v, d[], del d[], - # len(d), d.has_key(). + # len(d), in d. # dict, objects = self.make_weak_keyed_dict() for o in objects: @@ -853,8 +855,8 @@ "deleting the keys did not clear the dictionary") o = Object(42) dict[o] = "What is the meaning of the universe?" - self.assertTrue(dict.has_key(o)) - self.assertTrue(not dict.has_key(34)) + self.assertIn(o, dict) + self.assertNotIn(34, dict) def test_weak_keyed_iters(self): dict, objects = self.make_weak_keyed_dict() @@ -866,7 +868,6 @@ objects2 = list(objects) for wr in refs: ob = wr() - self.assertTrue(dict.has_key(ob)) self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -877,7 +878,6 @@ self.assertEqual(len(list(dict.iterkeyrefs())), len(objects)) for wr in dict.iterkeyrefs(): ob = wr() - self.assertTrue(dict.has_key(ob)) self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -991,16 +991,16 @@ " -- value parameters must be distinct objects") weakdict = klass() o = weakdict.setdefault(key, value1) - self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) - self.assertTrue(weakdict.get(key) is value1) - self.assertTrue(weakdict[key] is value1) + self.assertIs(o, value1) + self.assertIn(key, weakdict) + self.assertIs(weakdict.get(key), value1) + self.assertIs(weakdict[key], value1) o = weakdict.setdefault(key, value2) - self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) - self.assertTrue(weakdict.get(key) is value1) - self.assertTrue(weakdict[key] is value1) + self.assertIs(o, value1) + self.assertIn(key, weakdict) + self.assertIs(weakdict.get(key), value1) + self.assertIs(weakdict[key], value1) def test_weak_valued_dict_setdefault(self): self.check_setdefault(weakref.WeakValueDictionary, @@ -1012,24 +1012,24 @@ def check_update(self, klass, dict): # - # This exercises d.update(), len(d), d.keys(), d.has_key(), + # This exercises d.update(), len(d), d.keys(), in d, # d.get(), d[]. # weakdict = klass() weakdict.update(dict) - self.assertTrue(len(weakdict) == len(dict)) + self.assertEqual(len(weakdict), len(dict)) for k in weakdict.keys(): - self.assertTrue(dict.has_key(k), + self.assertIn(k, dict, "mysterious new key appeared in weak dict") v = dict.get(k) - self.assertTrue(v is weakdict[k]) - self.assertTrue(v is weakdict.get(k)) + self.assertIs(v, weakdict[k]) + self.assertIs(v, weakdict.get(k)) for k in dict.keys(): - self.assertTrue(weakdict.has_key(k), + self.assertIn(k, weakdict, "original key disappeared in weak dict") v = dict[k] - self.assertTrue(v is weakdict[k]) - self.assertTrue(v is weakdict.get(k)) + self.assertIs(v, weakdict[k]) + self.assertIs(v, weakdict.get(k)) def test_weak_valued_dict_update(self): self.check_update(weakref.WeakValueDictionary, Index: Lib/test/test_bool.py =================================================================== --- Lib/test/test_bool.py (revision 78803) +++ Lib/test/test_bool.py (working copy) @@ -85,10 +85,10 @@ self.assertEqual(False*1, 0) self.assertIsNot(False*1, False) - self.assertEqual(True/1, 1) - self.assertIsNot(True/1, True) - self.assertEqual(False/1, 0) - self.assertIsNot(False/1, False) + self.assertEqual(True//1, 1) + self.assertIsNot(True//1, True) + self.assertEqual(False//1, 0) + self.assertIsNot(False//1, False) for b in False, True: for i in 0, 1, 2: @@ -162,8 +162,9 @@ self.assertIs(hasattr([], "wobble"), False) def test_callable(self): - self.assertIs(callable(len), True) - self.assertIs(callable(1), False) + with test_support.check_py3k_warnings(): + self.assertIs(callable(len), True) + self.assertIs(callable(1), False) def test_isinstance(self): self.assertIs(isinstance(True, bool), True) @@ -178,8 +179,11 @@ self.assertIs(issubclass(int, bool), False) def test_haskey(self): - self.assertIs({}.has_key(1), False) - self.assertIs({1:1}.has_key(1), True) + self.assertIs(1 in {}, False) + self.assertIs(1 in {1:1}, True) + with test_support.check_py3k_warnings(): + self.assertIs({}.has_key(1), False) + self.assertIs({1:1}.has_key(1), True) def test_string(self): self.assertIs("xyz".endswith("z"), True) @@ -251,8 +255,9 @@ import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) - self.assertIs(operator.isCallable(0), False) - self.assertIs(operator.isCallable(len), True) + with test_support.check_py3k_warnings(): + self.assertIs(operator.isCallable(0), False) + self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) Index: Lib/test/test_slice.py =================================================================== --- Lib/test/test_slice.py (revision 78803) +++ Lib/test/test_slice.py (working copy) @@ -115,7 +115,8 @@ tmp.append((i, j, k)) x = X() - x[1:2] = 42 + with test_support.check_py3k_warnings(): + x[1:2] = 42 self.assertEquals(tmp, [(1, 2, 42)]) def test_pickle(self): Index: Lib/test/test_unittest.py =================================================================== --- Lib/test/test_unittest.py (revision 78803) +++ Lib/test/test_unittest.py (working copy) @@ -3009,13 +3009,14 @@ Do not use these methods. They will go away in 3.3. """ - self.failIfEqual(3, 5) - self.failUnlessEqual(3, 3) - self.failUnlessAlmostEqual(2.0, 2.0) - self.failIfAlmostEqual(3.0, 5.0) - self.failUnless(True) - self.failUnlessRaises(TypeError, lambda _: 3.14 + u'spam') - self.failIf(False) + with test_support.check_warnings(): + self.failIfEqual(3, 5) + self.failUnlessEqual(3, 3) + self.failUnlessAlmostEqual(2.0, 2.0) + self.failIfAlmostEqual(3.0, 5.0) + self.failUnless(True) + self.failUnlessRaises(TypeError, lambda _: 3.14 + u'spam') + self.failIf(False) def testDeepcopy(self): # Issue: 5660 Index: Lib/test/test_richcmp.py =================================================================== --- Lib/test/test_richcmp.py (revision 78803) +++ Lib/test/test_richcmp.py (working copy) @@ -327,7 +327,12 @@ self.assertIs(op(x, y), True) def test_main(): - test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest) + test_support.run_unittest(VectorTest, NumberTest, MiscTest, ListTest) + with test_support.check_py3k_warnings(("dict inequality comparisons " + "not supported in 3.x", + DeprecationWarning)): + test_support.run_unittest(DictTest) + if __name__ == "__main__": test_main() Index: Lib/test/test_multiprocessing.py =================================================================== --- Lib/test/test_multiprocessing.py (revision 78803) +++ Lib/test/test_multiprocessing.py (working copy) @@ -2023,7 +2023,9 @@ loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases) - run(suite) + with test_support.check_py3k_warnings( + (".+__(get|set)slice__ has been removed", DeprecationWarning)): + run(suite) ThreadsMixin.pool.terminate() ProcessesMixin.pool.terminate() Index: Lib/test/test_bigmem.py =================================================================== --- Lib/test/test_bigmem.py (revision 78803) +++ Lib/test/test_bigmem.py (working copy) @@ -97,21 +97,21 @@ def test_encode(self, size): return self.basic_encode_test(size, 'utf-8') - @precisionbigmemtest(size=_4G / 6 + 2, memuse=2) + @precisionbigmemtest(size=_4G // 6 + 2, memuse=2) def test_encode_raw_unicode_escape(self, size): try: return self.basic_encode_test(size, 'raw_unicode_escape') except MemoryError: pass # acceptable on 32-bit - @precisionbigmemtest(size=_4G / 5 + 70, memuse=3) + @precisionbigmemtest(size=_4G // 5 + 70, memuse=3) def test_encode_utf7(self, size): try: return self.basic_encode_test(size, 'utf7') except MemoryError: pass # acceptable on 32-bit - @precisionbigmemtest(size=_4G / 4 + 5, memuse=6) + @precisionbigmemtest(size=_4G // 4 + 5, memuse=6) def test_encode_utf32(self, size): try: return self.basic_encode_test(size, 'utf32', expectedsize=4*size+4) @@ -122,7 +122,7 @@ def test_decodeascii(self, size): return self.basic_encode_test(size, 'ascii', c='A') - @precisionbigmemtest(size=_4G / 5, memuse=6+2) + @precisionbigmemtest(size=_4G // 5, memuse=6+2) def test_unicode_repr_oflw(self, size): try: s = u"\uAAAA"*size @@ -516,7 +516,7 @@ self.assertEquals(s.count('\\'), size) self.assertEquals(s.count('0'), size * 2) - @bigmemtest(minsize=2**32 / 5, memuse=6+2) + @bigmemtest(minsize=2**32 // 5, memuse=6+2) def test_unicode_repr(self, size): s = u"\uAAAA" * size self.assertTrue(len(repr(s)) > size) @@ -1053,7 +1053,8 @@ @precisionbigmemtest(size=_1G, memuse=4) def test_repeat(self, size): try: - b = buffer("AAAA")*size + with test_support.check_py3k_warnings(): + b = buffer("AAAA")*size except MemoryError: pass # acceptable on 32-bit else: Index: Lib/test/test_class.py =================================================================== --- Lib/test/test_class.py (revision 78803) +++ Lib/test/test_class.py (working copy) @@ -407,7 +407,7 @@ self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))]) callLst[:] = [] - testme <> 1 # XXX kill this in py3k + eval('testme <> 1') # XXX kill this in py3k self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (testme, 1))]) callLst[:] = [] @@ -427,7 +427,7 @@ self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))]) callLst[:] = [] - 1 <> testme + eval('1 <> testme') self.assertCallStack([("__coerce__", (testme, 1)), ('__cmp__', (1, testme))]) callLst[:] = [] @@ -616,7 +616,11 @@ hash(a.f) def test_main(): - test_support.run_unittest(ClassTests) + with test_support.check_py3k_warnings( + (".+__(get|set|del)slice__ has been removed", DeprecationWarning), + ("classic int division", DeprecationWarning), + ("<> not supported", DeprecationWarning)): + test_support.run_unittest(ClassTests) if __name__=='__main__': test_main() Index: Lib/test/test_augassign.py =================================================================== --- Lib/test/test_augassign.py (revision 78803) +++ Lib/test/test_augassign.py (working copy) @@ -1,6 +1,6 @@ # Augmented assignment test. -from test.test_support import run_unittest +from test.test_support import run_unittest, check_py3k_warnings import unittest @@ -324,7 +324,8 @@ '''.splitlines()) def test_main(): - run_unittest(AugAssignTest) + with check_py3k_warnings(("classic int division", DeprecationWarning)): + run_unittest(AugAssignTest) if __name__ == '__main__': test_main() Index: Lib/test/test_userdict.py =================================================================== --- Lib/test/test_userdict.py (revision 78803) +++ Lib/test/test_userdict.py (working copy) @@ -45,7 +45,7 @@ # Test __repr__ self.assertEqual(str(u0), str(d0)) self.assertEqual(repr(u1), repr(d1)) - self.assertEqual(`u2`, `d2`) + self.assertEqual(repr(u2), repr(d2)) # Test __cmp__ and __len__ all = [d0, d1, d2, u, u0, u1, u2, uu, uu0, uu1, uu2] @@ -95,12 +95,13 @@ # Test has_key and "in". for i in u2.keys(): - self.assertTrue(u2.has_key(i)) self.assertIn(i, u2) - self.assertEqual(u1.has_key(i), d1.has_key(i)) self.assertEqual(i in u1, i in d1) - self.assertEqual(u0.has_key(i), d0.has_key(i)) self.assertEqual(i in u0, i in d0) + with test_support.check_py3k_warnings(): + self.assertTrue(u2.has_key(i)) + self.assertEqual(u1.has_key(i), d1.has_key(i)) + self.assertEqual(u0.has_key(i), d0.has_key(i)) # Test update t = UserDict.UserDict() Index: Lib/test/test_builtin.py =================================================================== --- Lib/test/test_builtin.py (revision 78803) +++ Lib/test/test_builtin.py (working copy) @@ -3,14 +3,10 @@ import platform import unittest from test.test_support import fcmp, have_unicode, TESTFN, unlink, \ - run_unittest + run_unittest, check_py3k_warnings from operator import neg -import sys, warnings, cStringIO, random, UserDict -warnings.filterwarnings("ignore", "hex../oct.. of negative int", - FutureWarning, __name__) -warnings.filterwarnings("ignore", "integer argument expected", - DeprecationWarning, "unittest") +import sys, cStringIO, random, UserDict # count the number of test runs. # used to skip running test_execfile() multiple times @@ -419,7 +415,9 @@ f.write('z = z+1\n') f.write('z = z*2\n') f.close() - execfile(TESTFN) + with check_py3k_warnings(("execfile.. not supported in 3.x", + DeprecationWarning)): + execfile(TESTFN) def test_execfile(self): global numruns @@ -1542,17 +1540,24 @@ data = 'The quick Brown fox Jumped over The lazy Dog'.split() self.assertRaises(TypeError, sorted, data, None, lambda x,y: 0) +def _run_unittest(*args): + with check_py3k_warnings( + (".+ not supported in 3.x", DeprecationWarning), + (".+ is renamed to imp.reload", DeprecationWarning), + ("classic int division", DeprecationWarning)): + run_unittest(*args) + def test_main(verbose=None): test_classes = (BuiltinTest, TestSorted) - run_unittest(*test_classes) + _run_unittest(*test_classes) # verify reference counting if verbose and hasattr(sys, "gettotalrefcount"): import gc counts = [None] * 5 for i in xrange(len(counts)): - run_unittest(*test_classes) + _run_unittest(*test_classes) gc.collect() counts[i] = sys.gettotalrefcount() print counts Index: Lib/test/test_userlist.py =================================================================== --- Lib/test/test_userlist.py (revision 78803) +++ Lib/test/test_userlist.py (working copy) @@ -53,7 +53,9 @@ self.assertEqual(iter(T((1,2))).next(), "0!!!") def test_main(): - test_support.run_unittest(UserListTest) + with test_support.check_py3k_warnings( + (".+__(get|set|del)slice__ has been removed", DeprecationWarning)): + test_support.run_unittest(UserListTest) if __name__ == "__main__": test_main() Index: Lib/test/test_call.py =================================================================== --- Lib/test/test_call.py (revision 78803) +++ Lib/test/test_call.py (working copy) @@ -12,7 +12,8 @@ self.assertRaises(TypeError, {}.has_key) def test_varargs1(self): - {}.has_key(0) + with test_support.check_py3k_warnings(): + {}.has_key(0) def test_varargs2(self): self.assertRaises(TypeError, {}.has_key, 0, 1) @@ -24,11 +25,13 @@ pass def test_varargs1_ext(self): - {}.has_key(*(0,)) + with test_support.check_py3k_warnings(): + {}.has_key(*(0,)) def test_varargs2_ext(self): try: - {}.has_key(*(1, 2)) + with test_support.check_py3k_warnings(): + {}.has_key(*(1, 2)) except TypeError: pass else: Index: Lib/test/test_sys.py =================================================================== --- Lib/test/test_sys.py (revision 78803) +++ Lib/test/test_sys.py (working copy) @@ -79,7 +79,8 @@ self.assertTrue(value is exc) self.assertTrue(traceback is not None) - sys.exc_clear() + with test.test_support.check_py3k_warnings(): + sys.exc_clear() typ, value, traceback = sys.exc_info() self.assertTrue(typ is None) @@ -507,7 +508,8 @@ # bool check(True, size(h + 'l')) # buffer - check(buffer(''), size(h + '2P2Pil')) + with test.test_support.check_py3k_warnings(): + check(buffer(''), size(h + '2P2Pil')) # builtin_function_or_method check(len, size(h + '3P')) # bytearray Index: Lib/test/test_ast.py =================================================================== --- Lib/test/test_ast.py (revision 78803) +++ Lib/test/test_ast.py (working copy) @@ -302,7 +302,9 @@ def test_main(): - test_support.run_unittest(AST_Tests, ASTHelpers_Test) + with test_support.check_py3k_warnings(("backquote not supported", + SyntaxWarning)): + test_support.run_unittest(AST_Tests, ASTHelpers_Test) def main(): if __name__ != '__main__':