Index: Lib/test/mapping_tests.py =================================================================== --- Lib/test/mapping_tests.py (revision 77734) +++ 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,18 @@ #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 + # Silence Py3k warning + with test_support.check_warnings(): + 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/seq_tests.py =================================================================== --- Lib/test/seq_tests.py (revision 77734) +++ Lib/test/seq_tests.py (working copy) @@ -4,6 +4,7 @@ import unittest import sys +import test_support # Various iterables # This is used for checking the constructor (here and in test_deque.py) @@ -196,7 +197,9 @@ self.assertEqual(a[ -pow(2,128L): 3 ], self.type2test([0,1,2])) self.assertEqual(a[ 3: pow(2,145L) ], self.type2test([3,4])) - self.assertRaises(TypeError, u.__getslice__) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertRaises(TypeError, u.__getslice__) def test_contains(self): u = self.type2test([0, 1, 2]) Index: Lib/test/test_array.py =================================================================== --- Lib/test/test_array.py (revision 77734) +++ Lib/test/test_array.py (working copy) @@ -749,7 +749,9 @@ def test_buffer(self): a = array.array(self.typecode, self.example) - b = buffer(a) + # Silence Py3k warning + with test_support.check_warnings(): + b = buffer(a) self.assertEqual(b[0], a.tostring()[0]) def test_weakref(self): Index: Lib/test/test_bigmem.py =================================================================== --- Lib/test/test_bigmem.py (revision 77734) +++ 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,9 @@ @precisionbigmemtest(size=_1G, memuse=4) def test_repeat(self, size): try: - b = buffer("AAAA")*size + # Silence Py3k warning + with test_support.check_warnings(): + b = buffer("AAAA")*size except MemoryError: pass # acceptable on 32-bit else: Index: Lib/test/test_bool.py =================================================================== --- Lib/test/test_bool.py (revision 77734) +++ Lib/test/test_bool.py (working copy) @@ -91,10 +91,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: @@ -168,8 +168,8 @@ self.assertIs(hasattr([], "wobble"), False) def test_callable(self): - self.assertIs(callable(len), True) - self.assertIs(callable(1), False) + self.assertTrue(hasattr(len, '__call__'), True) + self.assertFalse(hasattr(1, '__call__'), False) def test_isinstance(self): self.assertIs(isinstance(True, bool), True) @@ -184,8 +184,12 @@ 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) + # Silence Py3k warning + with test_support.check_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) @@ -257,8 +261,10 @@ 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) + # Silence Py3k warning + with test_support.check_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_bsddb3.py =================================================================== --- Lib/test/test_bsddb3.py (revision 77734) +++ Lib/test/test_bsddb3.py (working copy) @@ -8,10 +8,12 @@ import time import unittest from test.test_support import (requires, verbose, run_unittest, unlink, rmtree, - import_module) + import_module, check_warnings) # Skip test if _bsddb module was not built. import_module('_bsddb') +# Silence Py3k warning +import_module('bsddb', deprecated=True) # When running as a script instead of within the regrtest framework, skip the # requires test, since it's obvious we want to run them. @@ -64,8 +66,10 @@ print >>sys.stderr, db.DB_VERSION_STRING print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix() try: - run_unittest(test_all.suite(module_prefix='bsddb.test.', - timing_check=TimingCheck)) + # Silence Py3k warning + with check_warnings(): + run_unittest(test_all.suite(module_prefix='bsddb.test.', + timing_check=TimingCheck)) finally: # The only reason to remove db_home is in case if there is an old # one lying around. This might be by a different user, so just Index: Lib/test/test_call.py =================================================================== --- Lib/test/test_call.py (revision 77734) +++ Lib/test/test_call.py (working copy) @@ -12,7 +12,9 @@ self.assertRaises(TypeError, {}.has_key) def test_varargs1(self): - {}.has_key(0) + # Silence Py3k warning + with test_support.check_warnings(): + {}.has_key(0) def test_varargs2(self): self.assertRaises(TypeError, {}.has_key, 0, 1) @@ -24,11 +26,15 @@ pass def test_varargs1_ext(self): - {}.has_key(*(0,)) + # Silence Py3k warning + with test_support.check_warnings(): + {}.has_key(*(0,)) def test_varargs2_ext(self): try: - {}.has_key(*(1, 2)) + # Silence Py3k warning + with test_support.check_warnings(): + {}.has_key(*(1, 2)) except TypeError: pass else: Index: Lib/test/test_cgi.py =================================================================== --- Lib/test/test_cgi.py (revision 77734) +++ Lib/test/test_cgi.py (working copy) @@ -1,4 +1,4 @@ -from test.test_support import run_unittest +from test.test_support import run_unittest, check_warnings import cgi import os import sys @@ -104,7 +104,7 @@ def norm(list): if type(list) == type([]): - list.sort() + list.sort(key=str) return list def first_elts(list): @@ -345,14 +345,16 @@ self.assertEqual(result, v) def test_deprecated_parse_qs(self): - # this func is moved to urlparse, this is just a sanity check - self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']}, - cgi.parse_qs('a=A1&b=B2&B=B3')) + with check_warnings(): + # this func is moved to urlparse, this is just a sanity check + self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']}, + cgi.parse_qs('a=A1&b=B2&B=B3')) def test_deprecated_parse_qsl(self): - # this func is moved to urlparse, this is just a sanity check - self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')], - cgi.parse_qsl('a=A1&b=B2&B=B3')) + with check_warnings(): + # this func is moved to urlparse, this is just a sanity check + self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')], + cgi.parse_qsl('a=A1&b=B2&B=B3')) def test_parse_header(self): self.assertEqual( Index: Lib/test/test_collections.py =================================================================== --- Lib/test/test_collections.py (revision 77734) +++ Lib/test/test_collections.py (working copy) @@ -510,8 +510,10 @@ [('a', 3), ('b', 2), ('c', 1)]) self.assertEqual(c['b'], 2) self.assertEqual(c['z'], 0) - self.assertEqual(c.has_key('c'), True) - self.assertEqual(c.has_key('z'), False) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertEqual(c.has_key('c'), True) + self.assertEqual(c.has_key('z'), False) self.assertEqual(c.__contains__('c'), True) self.assertEqual(c.__contains__('z'), False) self.assertEqual(c.get('b', 10), 2) Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (revision 77734) +++ 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): @@ -141,7 +142,9 @@ self.assertEqual(f(5), 0) def test_complex_args(self): - + # Silence Py3k warning + with test_support.check_warnings(): + exec textwrap.dedent(''' def comp_args((a, b)): return a,b self.assertEqual(comp_args((1, 2)), (1, 2)) @@ -159,6 +162,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/test_decimal.py =================================================================== --- Lib/test/test_decimal.py (revision 77734) +++ Lib/test/test_decimal.py (working copy) @@ -31,7 +31,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_warnings) import random try: import threading @@ -202,7 +203,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: @@ -361,8 +362,10 @@ myexceptions = self.getexceptions() self.context.clear_flags() - myexceptions.sort() - theirexceptions.sort() + # Silence Py3k warning + with check_warnings(): + myexceptions.sort() + theirexceptions.sort() self.assertEqual(result, ans, 'Incorrect answer for ' + s + ' -- got ' + result) @@ -617,12 +620,14 @@ ('//', '__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__')) + # Silence Py3k warning + with check_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)) @@ -1194,8 +1199,10 @@ self.assertEqual(a, b) # with None - self.assertFalse(Decimal(1) < None) - self.assertTrue(Decimal(1) > None) + # Silence Py3k warning + with check_warnings(): + self.assertFalse(Decimal(1) < None) + self.assertTrue(Decimal(1) > None) def test_copy_and_deepcopy_methods(self): d = Decimal('43.24') @@ -1704,11 +1711,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() + + # Silence Py3k warning + with check_warnings(): + expected_flags.sort() + new_flags.sort() self.assertEqual(ans, new_ans, "operation produces different answers depending on flags set: " + Index: Lib/test/test_dict.py =================================================================== --- Lib/test/test_dict.py (revision 77734) +++ Lib/test/test_dict.py (working copy) @@ -33,8 +33,12 @@ self.assertEqual(d.keys(), []) d = {'a': 1, 'b': 2} k = d.keys() - self.assertTrue(d.has_key('a')) - self.assertTrue(d.has_key('b')) + self.assertTrue('a' in d) + self.assertTrue('b' in d) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertTrue(d.has_key('a')) + self.assertTrue(d.has_key('b')) self.assertRaises(TypeError, d.keys, None) @@ -57,14 +61,16 @@ def test_has_key(self): d = {} - self.assertTrue(not d.has_key('a')) + self.assertTrue('a' not in d) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertTrue(not d.has_key('a')) + self.assertRaises(TypeError, d.has_key) d = {'a': 1, 'b': 2} k = d.keys() k.sort() self.assertEqual(k, ['a', 'b']) - self.assertRaises(TypeError, d.has_key) - def test_contains(self): d = {} self.assertNotIn('a', d) @@ -396,8 +402,6 @@ self.assertRaises(Exc, repr, d) def test_le(self): - self.assertTrue(not ({} < {})) - self.assertTrue(not ({1: 2} < {1L: 2L})) class Exc(Exception): pass @@ -409,12 +413,18 @@ d1 = {BadCmp(): 1} d2 = {1: 1} - try: - d1 < d2 - except Exc: - pass - else: - self.fail("< didn't raise Exc") + + # Silence Py3k warning + with test_support.check_warnings(): + self.assertTrue(not ({} < {})) + self.assertTrue(not ({1: 2} < {1L: 2L})) + + try: + d1 < d2 + except Exc: + pass + else: + self.fail("< didn't raise Exc") def test_missing(self): # Make sure dict doesn't have a __missing__ method @@ -502,7 +512,9 @@ 'd.pop(x2)', 'd.update({x2: 2})']: try: - exec stmt in locals() + # Silence Py3k warning + with test_support.check_warnings(): + exec stmt in locals() except CustomException: pass else: @@ -550,7 +562,7 @@ # Bug #3537: if an empty but presized dict with a size larger # than 7 was in the freelist, it triggered an assertion failure try: - d = {'a': 1/0, 'b': None, 'c': None, 'd': None, 'e': None, + d = {'a': 1 // 0, 'b': None, 'c': None, 'd': None, 'e': None, 'f': None, 'g': None, 'h': None} except ZeroDivisionError: pass Index: Lib/test/test_file2k.py =================================================================== --- Lib/test/test_file2k.py (revision 77734) +++ Lib/test/test_file2k.py (working copy) @@ -34,13 +34,17 @@ def testAttributes(self): # verify expected attributes exist f = self.f - softspace = f.softspace + # Silence Py3k warning + with test_support.check_warnings(): + softspace = f.softspace f.name # merely shouldn't blow up f.mode # ditto f.closed # ditto - # verify softspace is writable - f.softspace = softspace # merely shouldn't blow up + # Silence Py3k warning + with test_support.check_warnings(): + # verify softspace is writable + f.softspace = softspace # merely shouldn't blow up # verify the others aren't for attr in 'name', 'mode', 'closed': @@ -98,7 +102,8 @@ def testMethods(self): methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'tell', 'truncate', - 'write', 'xreadlines', '__iter__'] + 'write', '__iter__'] + deprecated_methods = ['xreadlines'] if sys.platform.startswith('atheos'): methods.remove('truncate') @@ -110,13 +115,18 @@ method = getattr(self.f, methodname) # should raise on closed file self.assertRaises(ValueError, method) + # Silence Py3k warning + with test_support.check_warnings(): + for methodname in deprecated_methods: + method = getattr(self.f, methodname) + self.assertRaises(ValueError, method) self.assertRaises(ValueError, self.f.writelines, []) # file is closed, __exit__ shouldn't do anything self.assertEquals(self.f.__exit__(None, None, None), None) # it must also return None if an exception was given try: - 1/0 + 1 // 0 except: self.assertEquals(self.f.__exit__(*sys.exc_info()), None) @@ -182,12 +192,12 @@ try: f = open(TESTFN, bad_mode) except ValueError, msg: - if msg[0] != 0: + if msg.args[0] != 0: s = str(msg) if s.find(TESTFN) != -1 or s.find(bad_mode) == -1: self.fail("bad error message for invalid mode: %s" % s) - # if msg[0] == 0, we're probably on Windows where there may be - # no obvious way to discover why open() failed. + # if msg.args[0] == 0, we're probably on Windows where there may + # be no obvious way to discover why open() failed. else: f.close() self.fail("no error for invalid mode: %s" % bad_mode) Index: Lib/test/test_heapq.py =================================================================== --- Lib/test/test_heapq.py (revision 77734) +++ Lib/test/test_heapq.py (working copy) @@ -356,7 +356,8 @@ 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_warnings(): + 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_importhooks.py =================================================================== --- Lib/test/test_importhooks.py (revision 77734) +++ Lib/test/test_importhooks.py (working copy) @@ -180,7 +180,7 @@ self.assertFalse(hasattr(reloadmodule,'reloaded')) TestImporter.modules['reloadmodule'] = (False, reload_co) - reload(reloadmodule) + imp.reload(reloadmodule) self.assertTrue(hasattr(reloadmodule,'reloaded')) import hooktestpackage.oldabs @@ -247,9 +247,11 @@ for n in sys.modules.keys(): if n.startswith(parent): del sys.modules[n] - for mname in mnames: - m = __import__(mname, globals(), locals(), ["__dummy__"]) - m.__loader__ # to make sure we actually handled the import + # Silence Py3k warning + with test_support.check_warnings(): + for mname in mnames: + m = __import__(mname, globals(), locals(), ["__dummy__"]) + m.__loader__ # to make sure we actually handled the import def test_main(): Index: Lib/test/test_inspect.py =================================================================== --- Lib/test/test_inspect.py (revision 77734) +++ Lib/test/test_inspect.py (working copy) @@ -4,10 +4,11 @@ import inspect import datetime -from test.test_support import TESTFN, run_unittest +from test.test_support import TESTFN, run_unittest, check_warnings -from test import inspect_fodder as mod -from test import inspect_fodder2 as mod2 +with check_warnings(): + from test import inspect_fodder as mod + from test import inspect_fodder2 as mod2 # C module for test_findsource_binary import unicodedata @@ -29,7 +30,7 @@ import __builtin__ try: - 1/0 + 1 // 0 except: tb = sys.exc_traceback @@ -167,7 +168,7 @@ self.assertEqual(git.tr[1][1:], (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0)) self.assertEqual(git.tr[2][1:], (modfile, 18, 'eggs', - [' q = y / 0\n'], 0)) + [' q = y // 0\n'], 0)) def test_frame(self): args, varargs, varkw, locals = inspect.getargvalues(mod.fr) @@ -418,11 +419,13 @@ self.assertArgSpecEquals(A.m, ['self']) def test_getargspec_sublistofone(self): - def sublistOfOne((foo,)): return 1 - self.assertArgSpecEquals(sublistOfOne, [['foo']]) + # Silence Py3k warning + with check_warnings(): + 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_iter.py =================================================================== --- Lib/test/test_iter.py (revision 77734) +++ 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_warnings # Test result of triple loop (too big to inline) TRIPLETS = [(0, 0, 0), (0, 0, 1), (0, 0, 2), @@ -395,7 +396,12 @@ pass # Test map()'s use of iterators. - def test_builtin_map(self): + def test_deprecated_builtin_map(self): + # Silence Py3k warning + with check_warnings(): + self._test_builtin_map() + + 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)) @@ -506,7 +512,12 @@ self.assertEqual(zip(x, y), expected) # Test reduces()'s use of iterators. - def test_builtin_reduce(self): + def test_deprecated_builtin_reduce(self): + # Silence Py3k warning + with check_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/test_long.py =================================================================== --- Lib/test/test_long.py (revision 77734) +++ Lib/test/test_long.py (working copy) @@ -575,11 +575,13 @@ 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)) + # Silence Py3k warning + with test_support.check_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 @@ -619,8 +621,10 @@ checkit(x, '*', y) if y: - expected = longx / longy - got = x / y + # Silence Py3k warning + with test_support.check_warnings(): + expected = longx / longy + got = x / y checkit(x, '/', y) expected = longx // longy Index: Lib/test/test_marshal.py =================================================================== --- Lib/test/test_marshal.py (revision 77734) +++ 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) + # Silence Py3k warning + with test_support.check_warnings(): + 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_operator.py =================================================================== --- Lib/test/test_operator.py (revision 77734) +++ Lib/test/test_operator.py (working copy) @@ -192,11 +192,12 @@ class C: pass def check(self, o, v): - self.assertTrue(operator.isCallable(o) == callable(o) == v) - check(self, 4, 0) - check(self, operator.isCallable, 1) - check(self, C, 1) - check(self, C(), 0) + with test_support.check_warnings(): + self.assertTrue(operator.isCallable(o) == callable(o) == v) + check(self, 4, False) + check(self, operator.isCallable, True) + check(self, C, True) + check(self, C(), False) def test_isMappingType(self): self.assertRaises(TypeError, operator.isMappingType) @@ -306,8 +307,10 @@ 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)) + # Silence Py3k warning + with test_support.check_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_repr.py =================================================================== --- Lib/test/test_repr.py (revision 77734) +++ 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_warnings from repr import repr as r # Don't shadow builtin repr from repr import Repr @@ -174,7 +174,9 @@ 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') + # Silence Py3k warning + with check_warnings(): + x = buffer('foo') self.assertTrue(repr(x).startswith(' 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_warnings(): + 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_update_operator(self): try: @@ -1379,20 +1380,20 @@ def test_copy(self): dup = self.set.copy() - dup_list = list(dup); dup_list.sort() - set_list = list(self.set); set_list.sort() + dup_list = list(dup) + set_list = list(self.set) self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertTrue(dup_list[i] is set_list[i]) + for elt in dup_list: + self.assertTrue(elt in set_list) 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() + dup_list = list(dup) + set_list = list(self.set) self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertEqual(dup_list[i], set_list[i]) + for elt in dup_list: + self.assertTrue(elt in set_list) #------------------------------------------------------------------------------ @@ -1552,7 +1553,7 @@ for cons in (set, frozenset): for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)): for g in (G, I, Ig, S, L, R): - self.assertEqual(sorted(cons(g(s))), sorted(g(s))) + self.assertSameElements(cons(g(s)), g(s)) self.assertRaises(TypeError, cons , X(s)) self.assertRaises(TypeError, cons , N(s)) self.assertRaises(ZeroDivisionError, cons , E(s)) @@ -1567,7 +1568,7 @@ if isinstance(expected, bool): self.assertEqual(actual, expected) else: - self.assertEqual(sorted(actual), sorted(expected)) + self.assertSameElements(actual, expected) self.assertRaises(TypeError, meth, X(s)) self.assertRaises(TypeError, meth, N(s)) self.assertRaises(ZeroDivisionError, meth, E(s)) @@ -1581,7 +1582,7 @@ t = s.copy() getattr(s, methname)(list(g(data))) getattr(t, methname)(g(data)) - self.assertEqual(sorted(s), sorted(t)) + self.assertSameElements(s, t) self.assertRaises(TypeError, getattr(set('january'), methname), X(data)) self.assertRaises(TypeError, getattr(set('january'), methname), N(data)) Index: Lib/test/test_sets.py =================================================================== --- Lib/test/test_sets.py (revision 77734) +++ Lib/test/test_sets.py (working copy) @@ -510,15 +510,17 @@ 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) + # Silence Py3k warning + with test_support.check_warnings(): + 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 +681,20 @@ def test_copy(self): dup = self.set.copy() - dup_list = list(dup); dup_list.sort() - set_list = list(self.set); set_list.sort() + dup_list = list(dup) + set_list = list(self.set) self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertTrue(dup_list[i] is set_list[i]) + for elt in dup_list: + self.assertTrue(elt in set_list) 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() + dup_list = list(dup) + set_list = list(self.set) self.assertEqual(len(dup_list), len(set_list)) - for i in range(len(dup_list)): - self.assertEqual(dup_list[i], set_list[i]) + for elt in dup_list: + self.assertTrue(elt in set_list) #------------------------------------------------------------------------------ Index: Lib/test/test_slice.py =================================================================== --- Lib/test/test_slice.py (revision 77734) +++ Lib/test/test_slice.py (working copy) @@ -115,7 +115,9 @@ tmp.append((i, j, k)) x = X() - x[1:2] = 42 + # Silence Py3k warning + with test_support.check_warnings(): + x[1:2] = 42 self.assertEquals(tmp, [(1, 2, 42)]) def test_pickle(self): Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (revision 77734) +++ Lib/test/test_socket.py (working copy) @@ -123,7 +123,7 @@ self.server_ready.wait() self.client_ready.set() self.clientSetUp() - if not callable(test_func): + if not hasattr(test_func, '__call__'): raise TypeError, "test_func must be a callable function" try: test_func() @@ -282,7 +282,7 @@ orig = sys.getrefcount(__name__) socket.getnameinfo(__name__,0) except TypeError: - if sys.getrefcount(__name__) <> orig: + if sys.getrefcount(__name__) != orig: self.fail("socket.getnameinfo loses a reference") def testInterpreterCrash(self): @@ -1234,7 +1234,9 @@ self.assertEqual(msg, MSG) def _testRecvInto(self): - buf = buffer(MSG) + # Silence Py3k warning + with test_support.check_warnings(): + buf = buffer(MSG) self.serv_conn.send(buf) def testRecvFromInto(self): @@ -1245,7 +1247,9 @@ self.assertEqual(msg, MSG) def _testRecvFromInto(self): - buf = buffer(MSG) + # Silence Py3k warning + with test_support.check_warnings(): + buf = buffer(MSG) self.serv_conn.send(buf) Index: Lib/test/test_ssl.py =================================================================== --- Lib/test/test_ssl.py (revision 77734) +++ Lib/test/test_ssl.py (working copy) @@ -808,7 +808,7 @@ if test_support.verbose: sys.stdout.write(pprint.pformat(cert) + '\n') sys.stdout.write("Connection cipher is " + str(cipher) + '.\n') - if not cert.has_key('subject'): + if 'subject' not in cert: raise test_support.TestFailed( "No subject field in certificate: %s." % pprint.pformat(cert)) @@ -970,7 +970,9 @@ # now fetch the same data from the HTTPS server url = 'https://127.0.0.1:%d/%s' % ( server.port, os.path.split(CERTFILE)[1]) - f = urllib.urlopen(url) + # Silence Py3k warning + with test_support.check_warnings(): + f = urllib.urlopen(url) dlen = f.info().getheader("content-length") if dlen and (int(dlen) > 0): d2 = f.read(int(dlen)) Index: Lib/test/test_StringIO.py =================================================================== --- Lib/test/test_StringIO.py (revision 77734) +++ 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) + # Silence Py3k warning + with test_support.check_warnings(): + test_support.run_unittest(TestBufferStringIO, TestBuffercStringIO) if __name__ == '__main__': test_main() Index: Lib/test/test_sys.py =================================================================== --- Lib/test/test_sys.py (revision 77734) +++ Lib/test/test_sys.py (working copy) @@ -68,7 +68,9 @@ # Python/pythonrun.c::PyErr_PrintEx() is tricky. def test_exc_clear(self): - self.assertRaises(TypeError, sys.exc_clear, 42) + # Silence Py3k warning + with test.test_support.check_warnings(): + self.assertRaises(TypeError, sys.exc_clear, 42) # Verify that exc_info is present and matches exc, then clear it, and # check that it worked. @@ -78,7 +80,9 @@ self.assertTrue(value is exc) self.assertTrue(traceback is not None) - sys.exc_clear() + # Silence Py3k warning + with test.test_support.check_warnings(): + sys.exc_clear() typ, value, traceback = sys.exc_info() self.assertTrue(typ is None) @@ -483,7 +487,9 @@ # bool check(True, size(h + 'l')) # buffer - check(buffer(''), size(h + '2P2Pil')) + # Silence Py3k warning + with test.test_support.check_warnings(): + check(buffer(''), size(h + '2P2Pil')) # builtin_function_or_method check(len, size(h + '3P')) # bytearray Index: Lib/test/test_tarfile.py =================================================================== --- Lib/test/test_tarfile.py (revision 77734) +++ Lib/test/test_tarfile.py (working copy) @@ -712,7 +712,9 @@ return os.path.isfile(name) tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") - tar.add(tempdir, arcname="empty_dir", exclude=exclude) + # Silence Py3k warning + with test_support.check_warnings(): + tar.add(tempdir, arcname="empty_dir", exclude=exclude) tar.close() tar = tarfile.open(tmpname, "r") Index: Lib/test/test_undocumented_details.py =================================================================== --- Lib/test/test_undocumented_details.py (revision 77734) +++ Lib/test/test_undocumented_details.py (working copy) @@ -1,4 +1,4 @@ -from test.test_support import run_unittest, have_unicode +from test.test_support import run_unittest, check_warnings import unittest import sys @@ -33,7 +33,9 @@ self.assertTrue(g_cell != h_cell) def test_main(): - run_unittest(TestImplementationComparisons) + # Silence Py3k warnings + with check_warnings(): + run_unittest(TestImplementationComparisons) if __name__ == '__main__': test_main() Index: Lib/test/test_unittest.py =================================================================== --- Lib/test/test_unittest.py (revision 77734) +++ Lib/test/test_unittest.py (working copy) @@ -2909,13 +2909,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 @@ -3056,7 +3057,7 @@ try: self.assertRaises(KeyError, lambda: None) except self.failureException as e: - self.assertIn("KeyError not raised", e) + self.assertIn("KeyError not raised", e.args) else: self.fail("assertRaises() didn't fail") try: @@ -3073,7 +3074,7 @@ with self.assertRaises(KeyError): pass except self.failureException as e: - self.assertIn("KeyError not raised", e) + self.assertIn("KeyError not raised", e.args) else: self.fail("assertRaises() didn't fail") try: @@ -3591,6 +3592,9 @@ def __eq__(self, other): return self.path == other.path + # Silence Py3k warning + __hash__ = None + loader._get_module_from_name = lambda name: Module(name) def loadTestsFromModule(module, use_load_tests): if use_load_tests: Index: Lib/test/test_univnewlines2k.py =================================================================== --- Lib/test/test_univnewlines2k.py (revision 77734) +++ Lib/test/test_univnewlines2k.py (working copy) @@ -80,7 +80,9 @@ def test_execfile(self): namespace = {} - execfile(test_support.TESTFN, namespace) + # Silence Py3k warning + with test_support.check_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_userdict.py =================================================================== --- Lib/test/test_userdict.py (revision 77734) +++ Lib/test/test_userdict.py (working copy) @@ -45,7 +45,9 @@ # Test __repr__ self.assertEqual(str(u0), str(d0)) self.assertEqual(repr(u1), repr(d1)) - self.assertEqual(`u2`, `d2`) + # Silence Py3k warning + with test_support.check_warnings(): + self.assertEqual(eval('`u2`'), eval('`d2`')) # Test __cmp__ and __len__ all = [d0, d1, d2, u, u0, u1, u2, uu, uu0, uu1, uu2] @@ -95,12 +97,14 @@ # 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) + # Silence Py3k warning + with test_support.check_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_weakref.py =================================================================== --- Lib/test/test_weakref.py (revision 77734) +++ 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,9 @@ p.append(12) self.assertEqual(len(L), 1) self.assertTrue(p, "proxy for non-empty UserList should be true") - p[:] = [2, 3] + # Silence Py3k warning + with test_support.check_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 +184,12 @@ ## 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]) + # Silence Py3k warning + with test_support.check_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 +835,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 +857,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.assertTrue(o in dict) + self.assertTrue(34 not in dict) def test_weak_keyed_iters(self): dict, objects = self.make_weak_keyed_dict() @@ -866,8 +870,8 @@ objects2 = list(objects) for wr in refs: ob = wr() - self.assertTrue(dict.has_key(ob)) self.assertIn(ob, dict) + self.assertTrue(ob in dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) self.assertEqual(len(objects2), 0) @@ -877,7 +881,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) @@ -992,13 +995,13 @@ weakdict = klass() o = weakdict.setdefault(key, value1) self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) + self.assertTrue(key in weakdict) self.assertTrue(weakdict.get(key) is value1) self.assertTrue(weakdict[key] is value1) o = weakdict.setdefault(key, value2) self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) + self.assertTrue(key in weakdict) self.assertTrue(weakdict.get(key) is value1) self.assertTrue(weakdict[key] is value1) @@ -1012,20 +1015,20 @@ 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)) for k in weakdict.keys(): - self.assertTrue(dict.has_key(k), + self.assertTrue(k in 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)) for k in dict.keys(): - self.assertTrue(weakdict.has_key(k), + self.assertTrue(k in weakdict, "original key disappeared in weak dict") v = dict[k] self.assertTrue(v is weakdict[k]) Index: Lib/test/test_zipimport_support.py =================================================================== --- Lib/test/test_zipimport_support.py (revision 77734) +++ Lib/test/test_zipimport_support.py (working copy) @@ -168,8 +168,11 @@ 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_warnings(): + for obj in known_good_tests: + _run_object_doctest(obj, test_zipped_doctest) def test_doctest_main_issue4197(self): test_src = textwrap.dedent("""\