Index: Lib/test/list_tests.py =================================================================== --- Lib/test/list_tests.py (revision 77734) +++ Lib/test/list_tests.py (working copy) @@ -4,7 +4,7 @@ import sys import os - +import warnings from test import test_support, seq_tests class CommonTest(seq_tests.CommonTest): @@ -36,7 +36,9 @@ self.assertEqual(str(a0), str(l0)) self.assertEqual(repr(a0), repr(l0)) - self.assertEqual(`a2`, `l2`) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertEqual(eval('`a2`'), eval('`l2`')) self.assertEqual(str(a2), "[0, 1, 2]") self.assertEqual(repr(a2), "[0, 1, 2]") @@ -421,6 +423,13 @@ self.assertRaises(TypeError, u.reverse, 42) def test_sort(self): + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "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_ast.py =================================================================== --- Lib/test/test_ast.py (revision 77734) +++ Lib/test/test_ast.py (working copy) @@ -1,6 +1,7 @@ import sys, itertools, unittest from test import test_support import ast +import warnings def to_tuple(t): if t is None or isinstance(t, (basestring, int, long, complex)): @@ -302,7 +303,11 @@ def test_main(): - test_support.run_unittest(AST_Tests, ASTHelpers_Test) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "backquote not supported", + SyntaxWarning) + test_support.run_unittest(AST_Tests, ASTHelpers_Test) def main(): if __name__ != '__main__': Index: Lib/test/test_augassign.py =================================================================== --- Lib/test/test_augassign.py (revision 77734) +++ Lib/test/test_augassign.py (working copy) @@ -2,6 +2,7 @@ from test.test_support import run_unittest import unittest +import warnings class AugAssignTest(unittest.TestCase): @@ -324,7 +325,11 @@ '''.splitlines()) def test_main(): - run_unittest(AugAssignTest) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "classic int division", + DeprecationWarning) + run_unittest(AugAssignTest) if __name__ == '__main__': test_main() Index: Lib/test/test_buffer.py =================================================================== --- Lib/test/test_buffer.py (revision 77734) +++ Lib/test/test_buffer.py (working copy) @@ -6,6 +6,7 @@ import unittest from test import test_support +import warnings class BufferTests(unittest.TestCase): @@ -23,7 +24,11 @@ def test_main(): - test_support.run_unittest(BufferTests) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "buffer.. not supported", + DeprecationWarning) + test_support.run_unittest(BufferTests) if __name__ == "__main__": test_main() Index: Lib/test/test_builtin.py =================================================================== --- Lib/test/test_builtin.py (revision 77734) +++ Lib/test/test_builtin.py (working copy) @@ -7,10 +7,6 @@ from operator import neg import sys, warnings, cStringIO, random, fractions, UserDict -warnings.filterwarnings("ignore", "hex../oct.. of negative int", - FutureWarning, __name__) -warnings.filterwarnings("ignore", "integer argument expected", - DeprecationWarning, "unittest") # count the number of test runs. # used to skip running test_execfile() multiple times @@ -419,7 +415,11 @@ f.write('z = z+1\n') f.write('z = z*2\n') f.close() - execfile(TESTFN) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", ".+ not supported in 3.x", + DeprecationWarning) + execfile(TESTFN) def test_execfile(self): global numruns @@ -1542,17 +1542,30 @@ 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 warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", ".+ not supported in 3.x", + DeprecationWarning) + warnings.filterwarnings("ignore", ".+ is renamed to imp.reload", + DeprecationWarning) + warnings.filterwarnings("ignore", "integer argument expected, got float", + DeprecationWarning) + warnings.filterwarnings("ignore", "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_class.py =================================================================== --- Lib/test/test_class.py (revision 77734) +++ Lib/test/test_class.py (working copy) @@ -1,7 +1,7 @@ "Test the functionality of Python classes implementing operators." import unittest - +import warnings from test import test_support testmeths = [ @@ -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,15 @@ hash(a.f) def test_main(): - test_support.run_unittest(ClassTests) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", ".+slice__ has been removed", + DeprecationWarning) + warnings.filterwarnings("ignore", "classic int division", + DeprecationWarning) + warnings.filterwarnings("ignore", "<> not supported", + DeprecationWarning) + test_support.run_unittest(ClassTests) if __name__=='__main__': test_main() Index: Lib/test/test_coercion.py =================================================================== --- Lib/test/test_coercion.py (revision 77734) +++ Lib/test/test_coercion.py (working copy) @@ -223,8 +223,11 @@ infix_results[key] = res - -process_infix_results() +with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "classic int division", + DeprecationWarning) + process_infix_results() # now infix_results has two lists of results for every pairing. prefix_binops = [ 'divmod' ] @@ -337,11 +340,14 @@ raise exc def test_main(): - warnings.filterwarnings("ignore", - r'complex divmod\(\), // and % are deprecated', - DeprecationWarning, - r'test.test_coercion$') - run_unittest(CoercionTest) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", + "complex divmod.., // and % are deprecated", + DeprecationWarning) + warnings.filterwarnings("ignore", "classic .+ division", + DeprecationWarning) + run_unittest(CoercionTest) if __name__ == "__main__": test_main() Index: Lib/test/test_complex_args.py =================================================================== --- Lib/test/test_complex_args.py (revision 77734) +++ Lib/test/test_complex_args.py (working copy) @@ -1,23 +1,31 @@ import unittest from test import test_support +import textwrap +import warnings 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 +34,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 +58,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 +82,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 +106,17 @@ 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 warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "tuple parameter unpacking " + "has been removed", SyntaxWarning) + warnings.filterwarnings("ignore", "parenthesized argument names " + "are invalid", SyntaxWarning) + test_support.run_unittest(ComplexArgsTestCase) if __name__ == "__main__": test_main() Index: Lib/test/test_ctypes.py =================================================================== --- Lib/test/test_ctypes.py (revision 77734) +++ Lib/test/test_ctypes.py (working copy) @@ -4,12 +4,19 @@ #Skip tests if _ctypes module does not exist import_module('_ctypes') +import warnings import ctypes.test def test_main(): skipped, testcases = ctypes.test.get_tests(ctypes.test, "test_*.py", verbosity=0) suites = [unittest.makeSuite(t) for t in testcases] - run_unittest(unittest.TestSuite(suites)) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "buffer.. not supported", + DeprecationWarning) + warnings.filterwarnings("ignore", "classic long division", + DeprecationWarning) + run_unittest(unittest.TestSuite(suites)) if __name__ == "__main__": test_main() Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 77734) +++ Lib/test/test_descr.py (working copy) @@ -4618,9 +4618,19 @@ def test_main(): - # Run all local test cases, with PTypesLongInitTest first. - test_support.run_unittest(PTypesLongInitTest, OperatorsTest, - ClassPropertiesAndMethods, DictProxyTests) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "classic .+ division", + DeprecationWarning) + warnings.filterwarnings("ignore", "coerce.. not supported", + DeprecationWarning) + warnings.filterwarnings("ignore", "Overriding __cmp__ ", + DeprecationWarning) + warnings.filterwarnings("ignore", ".+slice__ has been removed", + DeprecationWarning) + # Run all local test cases, with PTypesLongInitTest first. + test_support.run_unittest(PTypesLongInitTest, OperatorsTest, + ClassPropertiesAndMethods, DictProxyTests) if __name__ == "__main__": test_main() Index: Lib/test/test_distutils.py =================================================================== --- Lib/test/test_distutils.py (revision 77734) +++ Lib/test/test_distutils.py (working copy) @@ -7,10 +7,16 @@ import distutils.tests import test.test_support +import warnings def test_main(): - test.test_support.run_unittest(distutils.tests.test_suite()) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "distutils.sysconfig.+ is " + "deprecated. Use the APIs provided by " + "the sysconfig module instead", + DeprecationWarning) + test.test_support.run_unittest(distutils.tests.test_suite()) test.test_support.reap_children() Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 77734) +++ Lib/test/test_doctest.py (working copy) @@ -2421,7 +2421,13 @@ 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 warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "backquote not supported", + SyntaxWarning) + warnings.filterwarnings("ignore", "execfile.. not supported", + DeprecationWarning) + test_support.run_doctest(test_doctest, verbosity=True) import trace, sys def test_coverage(coverdir): Index: Lib/test/test_exceptions.py =================================================================== --- Lib/test/test_exceptions.py (revision 77734) +++ Lib/test/test_exceptions.py (working copy) @@ -7,7 +7,7 @@ import warnings from test.test_support import TESTFN, unlink, run_unittest, captured_output -from test.test_pep352 import ignore_message_warning +from test.test_pep352 import ignore_deprecation_warnings # XXX This is not really enough, each *operation* should be tested! @@ -17,6 +17,7 @@ # Reloading the built-in exceptions module failed prior to Py2.2, while it # should act the same as reloading built-in sys. try: + from imp import reload import exceptions reload(exceptions) except ImportError, e: @@ -108,11 +109,11 @@ self.assertRaises(ValueError, chr, 10000) self.raise_catch(ZeroDivisionError, "ZeroDivisionError") - try: x = 1/0 + try: x = 1 // 0 except ZeroDivisionError: pass self.raise_catch(Exception, "Exception") - try: x = 1/0 + try: x = 1 // 0 except Exception, e: pass def testSyntaxErrorMessage(self): @@ -197,6 +198,7 @@ self.assertEqual(WindowsError(1001, "message").errno, 22) self.assertEqual(WindowsError(1001, "message").winerror, 1001) + @ignore_deprecation_warnings def testAttributes(self): # test that exception attributes are happy @@ -274,34 +276,32 @@ except NameError: pass - with warnings.catch_warnings(): - ignore_message_warning() - for exc, args, expected in exceptionList: - try: - raise exc(*args) - except BaseException, e: - if type(e) is not exc: - raise - # Verify module name - self.assertEquals(type(e).__module__, 'exceptions') - # Verify no ref leaks in Exc_str() - s = str(e) - for checkArgName in expected: - self.assertEquals(repr(getattr(e, checkArgName)), - repr(expected[checkArgName]), - 'exception "%s", attribute "%s"' % - (repr(e), checkArgName)) - - # test for pickling support - for p in pickle, cPickle: - for protocol in range(p.HIGHEST_PROTOCOL + 1): - new = p.loads(p.dumps(e, protocol)) - for checkArgName in expected: - got = repr(getattr(new, checkArgName)) - want = repr(expected[checkArgName]) - self.assertEquals(got, want, - 'pickled "%r", attribute "%s"' % - (e, checkArgName)) + for exc, args, expected in exceptionList: + try: + raise exc(*args) + except BaseException, e: + if type(e) is not exc: + raise + # Verify module name + self.assertEquals(type(e).__module__, 'exceptions') + # Verify no ref leaks in Exc_str() + s = str(e) + for checkArgName in expected: + self.assertEquals(repr(getattr(e, checkArgName)), + repr(expected[checkArgName]), + 'exception "%s", attribute "%s"' % + (repr(e), checkArgName)) + + # test for pickling support + for p in pickle, cPickle: + for protocol in range(p.HIGHEST_PROTOCOL + 1): + new = p.loads(p.dumps(e, protocol)) + for checkArgName in expected: + got = repr(getattr(new, checkArgName)) + want = repr(expected[checkArgName]) + self.assertEquals(got, want, + 'pickled "%r", attribute "%s"' % + (e, checkArgName)) def testDeprecatedMessageAttribute(self): @@ -331,6 +331,7 @@ with self.assertRaises(AttributeError): exc.message + @ignore_deprecation_warnings def testPickleMessageAttribute(self): # Pickling with message attribute must work, as well. e = Exception("foo") @@ -338,9 +339,7 @@ f.message = "bar" for p in pickle, cPickle: ep = p.loads(p.dumps(e)) - with warnings.catch_warnings(): - ignore_message_warning() - self.assertEqual(ep.message, "foo") + self.assertEqual(ep.message, "foo") fp = p.loads(p.dumps(f)) self.assertEqual(fp.message, "bar") @@ -349,7 +348,12 @@ # going through the 'args' attribute. args = (1, 2, 3) exc = BaseException(*args) - self.assertEqual(exc[:], args) + self.assertEqual(exc.args[:], args) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "__getslice__ not supported for " + "exception classes", DeprecationWarning) + self.assertEqual(exc[:], args) def testKeywordArgs(self): # test that builtin exception don't take keyword args, Index: Lib/test/test_grammar.py =================================================================== --- Lib/test/test_grammar.py (revision 77734) +++ Lib/test/test_grammar.py (working copy) @@ -11,6 +11,7 @@ from test.test_support import run_unittest, check_syntax_error import unittest import sys +import warnings # testing import * from sys 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,19 @@ def test_main(): - run_unittest(TokenTests, GrammarTests) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "backquote not supported", + SyntaxWarning) + warnings.filterwarnings("ignore", "tuple parameter unpacking has been removed", + SyntaxWarning) + warnings.filterwarnings("ignore", "parenthesized argument names are invalid", + SyntaxWarning) + warnings.filterwarnings("ignore", "classic int division", + DeprecationWarning) + warnings.filterwarnings("ignore", ".+ not supported in 3.x", + DeprecationWarning) + run_unittest(TokenTests, GrammarTests) if __name__ == '__main__': test_main() Index: Lib/test/test_multiprocessing.py =================================================================== --- Lib/test/test_multiprocessing.py (revision 77734) +++ Lib/test/test_multiprocessing.py (working copy) @@ -19,6 +19,7 @@ import logging from test import test_support from StringIO import StringIO +import warnings _multiprocessing = test_support.import_module('_multiprocessing') @@ -1991,7 +1992,11 @@ loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases) - run(suite) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", ".+slice__ has been removed", + DeprecationWarning) + run(suite) ThreadsMixin.pool.terminate() ProcessesMixin.pool.terminate() Index: Lib/test/test_opcodes.py =================================================================== --- Lib/test/test_opcodes.py (revision 77734) +++ Lib/test/test_opcodes.py (working copy) @@ -2,6 +2,7 @@ from test.test_support import run_unittest import unittest +import warnings class OpcodeTest(unittest.TestCase): @@ -9,7 +10,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 +111,14 @@ def test_main(): - run_unittest(OpcodeTest) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "exceptions must derive from " + "BaseException", DeprecationWarning) + warnings.filterwarnings("ignore", "catching classes that don't " + "inherit from BaseException is not allowed", + DeprecationWarning) + run_unittest(OpcodeTest) if __name__ == '__main__': test_main() Index: Lib/test/test_peepholer.py =================================================================== --- Lib/test/test_peepholer.py (revision 77734) +++ Lib/test/test_peepholer.py (working copy) @@ -205,18 +205,24 @@ def test_main(verbose=None): import sys from test import test_support + import warnings 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 warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "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_pep352.py =================================================================== --- Lib/test/test_pep352.py (revision 77734) +++ Lib/test/test_pep352.py (working copy) @@ -6,12 +6,23 @@ import os from platform import system as platform_system -def ignore_message_warning(): - """Ignore the DeprecationWarning for BaseException.message.""" - warnings.resetwarnings() - warnings.filterwarnings("ignore", "BaseException.message", - DeprecationWarning) - +DEPRECATION_WARNINGS = ( + "BaseException.message has been deprecated", + "exceptions must derive from BaseException", + "catching classes that don't inherit from BaseException is not allowed", + "__getitem__ not supported for exception classes", +) + +# Silence Py3k and other deprecation warnings +def ignore_deprecation_warnings(func): + """Ignore the known DeprecationWarnings.""" + def wrapper(*args, **kw): + with warnings.catch_warnings(): + warnings.resetwarnings() + for text in DEPRECATION_WARNINGS: + warnings.filterwarnings("ignore", text, DeprecationWarning) + return func(*args, **kw) + return wrapper class ExceptionClassTests(unittest.TestCase): @@ -21,14 +32,12 @@ def test_builtins_new_style(self): self.assertTrue(issubclass(Exception, object)) + @ignore_deprecation_warnings def verify_instance_interface(self, ins): - with warnings.catch_warnings(): - ignore_message_warning() - for attr in ("args", "message", "__str__", "__repr__", - "__getitem__"): - self.assertTrue(hasattr(ins, attr), - "%s missing %s attribute" % - (ins.__class__.__name__, attr)) + for attr in ("args", "message", "__str__", "__repr__", "__getitem__"): + self.assertTrue(hasattr(ins, attr), + "%s missing %s attribute" % + (ins.__class__.__name__, attr)) def test_inheritance(self): # Make sure the inheritance hierarchy matches the documentation @@ -91,43 +100,39 @@ self.assertEqual(given, expected, "%s: %s != %s" % (test_name, given, expected)) + @ignore_deprecation_warnings def test_interface_single_arg(self): # Make sure interface works properly when given a single argument arg = "spam" exc = Exception(arg) - with warnings.catch_warnings(): - ignore_message_warning() - results = ([len(exc.args), 1], [exc.args[0], arg], - [exc.message, arg], - [str(exc), str(arg)], [unicode(exc), unicode(arg)], - [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0], - arg]) - self.interface_test_driver(results) + results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg], + [str(exc), str(arg)], [unicode(exc), unicode(arg)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)], + [exc[0], arg]) + self.interface_test_driver(results) + @ignore_deprecation_warnings def test_interface_multi_arg(self): # Make sure interface correct when multiple arguments given arg_count = 3 args = tuple(range(arg_count)) exc = Exception(*args) - with warnings.catch_warnings(): - ignore_message_warning() - results = ([len(exc.args), arg_count], [exc.args, args], - [exc.message, ''], [str(exc), str(args)], - [unicode(exc), unicode(args)], - [repr(exc), exc.__class__.__name__ + repr(exc.args)], - [exc[-1], args[-1]]) - self.interface_test_driver(results) + results = ([len(exc.args), arg_count], [exc.args, args], + [exc.message, ''], [str(exc), str(args)], + [unicode(exc), unicode(args)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)], + [exc[-1], args[-1]]) + self.interface_test_driver(results) + @ignore_deprecation_warnings def test_interface_no_arg(self): # Make sure that with no args that interface is correct exc = Exception() - with warnings.catch_warnings(): - ignore_message_warning() - results = ([len(exc.args), 0], [exc.args, tuple()], - [exc.message, ''], - [str(exc), ''], [unicode(exc), u''], - [repr(exc), exc.__class__.__name__ + '()'], [True, True]) - self.interface_test_driver(results) + results = ([len(exc.args), 0], [exc.args, tuple()], + [exc.message, ''], + [str(exc), ''], [unicode(exc), u''], + [repr(exc), exc.__class__.__name__ + '()'], [True, True]) + self.interface_test_driver(results) def test_message_deprecation(self): @@ -179,6 +184,7 @@ self.fail("TypeError expected when catching %s as specified in a " "tuple" % type(object_)) + @ignore_deprecation_warnings def test_raise_classic(self): # Raising a classic class is okay (for now). class ClassicClass: Index: Lib/test/test_richcmp.py =================================================================== --- Lib/test/test_richcmp.py (revision 77734) +++ Lib/test/test_richcmp.py (working copy) @@ -2,6 +2,7 @@ import unittest from test import test_support +import warnings import operator @@ -330,7 +331,13 @@ 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 warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "dict inequality comparisons " + "not supported in 3.x", DeprecationWarning) + test_support.run_unittest(DictTest) + if __name__ == "__main__": test_main() Index: Lib/test/test_scope.py =================================================================== --- Lib/test/test_scope.py (revision 77734) +++ Lib/test/test_scope.py (working copy) @@ -321,10 +321,16 @@ self.assertEqual(makeReturner2(a=11)()['a'], 11) - def makeAddPair((a, b)): - def addPair((c, d)): - return (a + c, b + d) - return addPair + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "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 +477,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_sort.py =================================================================== --- Lib/test/test_sort.py (revision 77734) +++ Lib/test/test_sort.py (working copy) @@ -2,6 +2,7 @@ import random import sys import unittest +import warnings verbose = test_support.verbose nerrors = 0 @@ -185,7 +186,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 +208,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 +275,21 @@ 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 warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "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_struct.py =================================================================== --- Lib/test/test_struct.py (revision 77734) +++ Lib/test/test_struct.py (working copy) @@ -471,7 +471,7 @@ 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) @@ -507,7 +507,11 @@ def test_main(): - run_unittest(StructTest) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "buffer.. not supported", + DeprecationWarning) + run_unittest(StructTest) if __name__ == '__main__': test_main() Index: Lib/test/test_syntax.py =================================================================== --- Lib/test/test_syntax.py (revision 77734) +++ Lib/test/test_syntax.py (working copy) @@ -552,7 +552,11 @@ def test_main(): test_support.run_unittest(SyntaxTestCase) from test import test_syntax - test_support.run_doctest(test_syntax, verbosity=True) + with warnings.catch_warnings(): + # Silence Py3k warning + warnings.filterwarnings("ignore", "backquote not supported", + SyntaxWarning) + test_support.run_doctest(test_syntax, verbosity=True) if __name__ == "__main__": test_main() Index: Lib/test/test_types.py =================================================================== --- Lib/test/test_types.py (revision 77734) +++ Lib/test/test_types.py (working copy) @@ -4,6 +4,7 @@ import unittest import sys import locale +import warnings class TypesTests(unittest.TestCase): @@ -710,7 +711,13 @@ self.assertRaises(ValueError, format, 0, ',' + code) def test_main(): - run_unittest(TypesTests) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", "buffer.. not supported", + DeprecationWarning) + warnings.filterwarnings("ignore", "classic long division", + DeprecationWarning) + run_unittest(TypesTests) if __name__ == '__main__': test_main() Index: Lib/test/test_userlist.py =================================================================== --- Lib/test/test_userlist.py (revision 77734) +++ Lib/test/test_userlist.py (working copy) @@ -2,6 +2,7 @@ from UserList import UserList from test import test_support, list_tests +import warnings class UserListTest(list_tests.CommonTest): type2test = UserList @@ -53,7 +54,11 @@ self.assertEqual(iter(T((1,2))).next(), "0!!!") def test_main(): - test_support.run_unittest(UserListTest) + with warnings.catch_warnings(): + # Silence Py3k warnings + warnings.filterwarnings("ignore", ".+slice__ has been removed", + DeprecationWarning) + test_support.run_unittest(UserListTest) if __name__ == "__main__": test_main() Index: Lib/test/test_userstring.py =================================================================== --- Lib/test/test_userstring.py (revision 77734) +++ Lib/test/test_userstring.py (working copy) @@ -136,8 +136,11 @@ def test_main(): with warnings.catch_warnings(): + # Silence Py3k warnings warnings.filterwarnings("ignore", ".*MutableString", DeprecationWarning) + warnings.filterwarnings("ignore", ".+slice__ has been removed", + DeprecationWarning) test_support.run_unittest(UserStringTest, MutableStringTest) if __name__ == "__main__":