Index: Lib/email/test/test_email.py =================================================================== --- Lib/email/test/test_email.py (revision 77549) +++ Lib/email/test/test_email.py (working copy) @@ -1055,7 +1055,7 @@ sign = '-' else: sign = '+' - tzoffset = ' %s%04d' % (sign, tzsecs / 36) + tzoffset = ' %s%04d' % (sign, tzsecs // 36) container['Date'] = time.strftime( '%a, %d %b %Y %H:%M:%S', time.localtime(now)) + tzoffset Index: Lib/email/test/test_email_renamed.py =================================================================== --- Lib/email/test/test_email_renamed.py (revision 77549) +++ Lib/email/test/test_email_renamed.py (working copy) @@ -1053,7 +1053,7 @@ sign = '-' else: sign = '+' - tzoffset = ' %s%04d' % (sign, tzsecs / 36) + tzoffset = ' %s%04d' % (sign, tzsecs // 36) container['Date'] = time.strftime( '%a, %d %b %Y %H:%M:%S', time.localtime(now)) + tzoffset Index: Lib/test/infinite_reload.py =================================================================== --- Lib/test/infinite_reload.py (revision 77549) +++ Lib/test/infinite_reload.py (working copy) @@ -3,5 +3,6 @@ # reload()ing. This module is imported by test_import.py:test_infinite_reload # to make sure this doesn't happen any more. +import imp import infinite_reload -reload(infinite_reload) +imp.reload(infinite_reload) Index: Lib/test/inspect_fodder.py =================================================================== --- Lib/test/inspect_fodder.py (revision 77549) +++ Lib/test/inspect_fodder.py (working copy) @@ -15,7 +15,7 @@ fr = inspect.currentframe() st = inspect.stack() p = x - q = y / 0 + q = y // 0 # line 20 class StupidGit: Index: Lib/test/test_anydbm.py =================================================================== --- Lib/test/test_anydbm.py (revision 77549) +++ Lib/test/test_anydbm.py (working copy) @@ -5,12 +5,14 @@ import os import unittest -import anydbm import glob from test import test_support _fname = test_support.TESTFN +# Silence Py3k warning +anydbm = test_support.import_module('anydbm', deprecated=True) + def _delete_files(): # we don't know the precise name the underlying database uses # so we use glob to locate all names Index: Lib/test/test_binop.py =================================================================== --- Lib/test/test_binop.py (revision 77549) +++ Lib/test/test_binop.py (working copy) @@ -207,6 +207,9 @@ """Compare two Rats for inequality.""" return not self == other + # Silence Py3k warning + __hash__ = None + class RatTestCase(unittest.TestCase): """Unit tests for Rat class and its support utilities.""" Index: Lib/test/test_bsddb.py =================================================================== --- Lib/test/test_bsddb.py (revision 77549) +++ Lib/test/test_bsddb.py (working copy) @@ -10,8 +10,10 @@ # Skip test if _bsddb wasn't built. test_support.import_module('_bsddb') -import bsddb -import dbhash # Just so we know it's imported +# Silence Py3k warning +bsddb = test_support.import_module('bsddb', deprecated=True) +# Just so we know it's imported: +test_support.import_module('dbhash', deprecated=True) class TestBSDDB(unittest.TestCase): Index: Lib/test/test_capi.py =================================================================== --- Lib/test/test_capi.py (revision 77549) +++ Lib/test/test_capi.py (working copy) @@ -55,7 +55,7 @@ context = foo() context.l = [] context.n = 2 #submits per thread - context.nThreads = n / context.n + context.nThreads = n // context.n context.nFinished = 0 context.lock = threading.Lock() context.event = threading.Event() Index: Lib/test/test_cgi.py =================================================================== --- Lib/test/test_cgi.py (revision 77549) +++ Lib/test/test_cgi.py (working copy) @@ -104,7 +104,7 @@ def norm(list): if type(list) == type([]): - list.sort() + list.sort(key=str) return list def first_elts(list): Index: Lib/test/test_commands.py =================================================================== --- Lib/test/test_commands.py (revision 77549) +++ Lib/test/test_commands.py (working copy) @@ -9,7 +9,10 @@ warnings.filterwarnings('ignore', r".*commands.getstatus.. is deprecated", DeprecationWarning) -from test.test_support import run_unittest, reap_children +from test.test_support import run_unittest, reap_children, import_module + +# Silence Py3k warning +import_module('commands', deprecated=True) from commands import * # The module says: Index: Lib/test/test_compiler.py =================================================================== --- Lib/test/test_compiler.py (revision 77549) +++ Lib/test/test_compiler.py (working copy) @@ -75,7 +75,7 @@ def testTryExceptFinally(self): # Test that except and finally clauses in one try stmt are recognized - c = compiler.compile("try:\n 1/0\nexcept:\n e = 1\nfinally:\n f = 1", + c = compiler.compile("try:\n 1//0\nexcept:\n e = 1\nfinally:\n f = 1", "", "exec") dct = {} exec c in dct Index: Lib/test/test_copy.py =================================================================== --- Lib/test/test_copy.py (revision 77549) +++ Lib/test/test_copy.py (working copy) @@ -661,7 +661,7 @@ v = copy.deepcopy(u) self.assertNotEqual(v, u) self.assertEqual(len(v), 2) - (x, y), (z, t) = sorted(v.items(), key=lambda (k, v): k.i) + (x, y), (z, t) = sorted(v.items(), key=lambda k: k[0].i) self.assertFalse(x is a) self.assertEqual(x.i, a.i) self.assertTrue(y is b) Index: Lib/test/test_descrtut.py =================================================================== --- Lib/test/test_descrtut.py (revision 77549) +++ Lib/test/test_descrtut.py (working copy) @@ -66,7 +66,7 @@ statement or the built-in function eval(): >>> def sorted(seq): - ... seq.sort() + ... seq.sort(key=str) ... return seq >>> print sorted(a.keys()) [1, 2] Index: Lib/test/test_file.py =================================================================== --- Lib/test/test_file.py (revision 77549) +++ Lib/test/test_file.py (working copy) @@ -127,7 +127,7 @@ 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) Index: Lib/test/test_fractions.py =================================================================== --- Lib/test/test_fractions.py (revision 77549) +++ Lib/test/test_fractions.py (working copy) @@ -43,6 +43,10 @@ assert False, "__sub__ should not be invoked for comparisons" __rsub__ = __sub__ + # Silence Py3k warning + def __hash__(self): + assert False, "__hash__ should not be invoked for comparisons" + class DummyRational(object): """Test comparison of Fraction with a naive rational implementation.""" @@ -76,6 +80,11 @@ def __float__(self): assert False, "__float__ should not be invoked" + # Silence Py3k warning + def __hash__(self): + assert False, "__hash__ should not be invoked for comparisons" + + class GcdTest(unittest.TestCase): def testMisc(self): Index: Lib/test/test_ftplib.py =================================================================== --- Lib/test/test_ftplib.py (revision 77549) +++ Lib/test/test_ftplib.py (working copy) @@ -100,7 +100,7 @@ sock.listen(5) sock.settimeout(2) ip, port = sock.getsockname()[:2] - ip = ip.replace('.', ','); p1 = port / 256; p2 = port % 256 + ip = ip.replace('.', ','); p1, p2 = divmod(port, 256) self.push('227 entering passive mode (%s,%d,%d)' %(ip, p1, p2)) conn, addr = sock.accept() self.dtp = self.dtp_handler(conn, baseclass=self) Index: Lib/test/test_functools.py =================================================================== --- Lib/test/test_functools.py (revision 77549) +++ Lib/test/test_functools.py (working copy) @@ -116,7 +116,7 @@ def test_error_propagation(self): def f(x, y): - x / y + x // y self.assertRaises(ZeroDivisionError, self.thetype(f, 1, 0)) self.assertRaises(ZeroDivisionError, self.thetype(f, 1), 0) self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0) Index: Lib/test/test_gzip.py =================================================================== --- Lib/test/test_gzip.py (revision 77549) +++ Lib/test/test_gzip.py (working copy) @@ -246,11 +246,11 @@ self.fail("__enter__ on a closed file didn't raise an exception") try: with gzip.GzipFile(self.filename, "wb") as f: - 1/0 + 1 // 0 except ZeroDivisionError: pass else: - self.fail("1/0 didn't raise an exception") + self.fail("1 // 0 didn't raise an exception") def test_zero_padded_file(self): with gzip.GzipFile(self.filename, "wb") as f: Index: Lib/test/test_hotshot.py =================================================================== --- Lib/test/test_hotshot.py (revision 77549) +++ Lib/test/test_hotshot.py (working copy) @@ -1,5 +1,3 @@ -import hotshot -import hotshot.log import os import pprint import unittest @@ -9,6 +7,8 @@ from test import test_support +# Silence Py3k warning +hotshot = test_support.import_module('hotshot', deprecated=True) from hotshot.log import ENTER, EXIT, LINE Index: Lib/test/test_import.py =================================================================== --- Lib/test/test_import.py (revision 77549) +++ Lib/test/test_import.py (working copy) @@ -7,6 +7,7 @@ import py_compile import warnings import marshal +from imp import reload from test.test_support import (unlink, TESTFN, unload, run_unittest, check_warnings, TestFailed, EnvironmentVarGuard) @@ -56,11 +57,10 @@ f.close() try: - try: - mod = __import__(TESTFN) - except ImportError, err: - self.fail("import from %s failed: %s" % (ext, err)) - + mod = __import__(TESTFN) + except ImportError, err: + self.fail("import from %s failed: %s" % (ext, err)) + else: self.assertEquals(mod.a, a, "module loaded (%s) but contents invalid" % mod) self.assertEquals(mod.b, b, @@ -69,10 +69,9 @@ os.unlink(source) try: - try: - reload(mod) - except ImportError, err: - self.fail("import from .pyc/.pyo failed: %s" % err) + reload(mod) + except ImportError, err: + self.fail("import from .pyc/.pyo failed: %s" % err) finally: try: os.unlink(pyc) @@ -172,7 +171,7 @@ def test_failing_import_sticks(self): source = TESTFN + os.extsep + "py" f = open(source, "w") - print >> f, "a = 1/0" + print >> f, "a = 1 // 0" f.close() # New in 2.4, we shouldn't be able to import that no matter how often Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (revision 77549) +++ Lib/test/test_io.py (working copy) @@ -381,11 +381,11 @@ f = None try: with self.open(support.TESTFN, "wb", bufsize) as f: - 1/0 + 1 // 0 except ZeroDivisionError: self.assertEqual(f.closed, True) else: - self.fail("1/0 didn't raise an exception") + self.fail("1 // 0 didn't raise an exception") # issue 5008 def test_append_mode_tell(self): Index: Lib/test/test_itertools.py =================================================================== --- Lib/test/test_itertools.py (revision 77549) +++ Lib/test/test_itertools.py (working copy) @@ -9,6 +9,7 @@ import random import copy import pickle +from functools import reduce maxsize = test_support.MAX_Py_ssize_t minsize = -maxsize-1 @@ -122,7 +123,7 @@ values = [5*x-12 for x in range(n)] for r in range(n+2): result = list(combinations(values, r)) - self.assertEqual(len(result), 0 if r>n else fact(n) / fact(r) / fact(n-r)) # right number of combs + self.assertEqual(len(result), 0 if r>n else fact(n) // fact(r) // fact(n-r)) # right number of combs self.assertEqual(len(result), len(set(result))) # no repeats self.assertEqual(result, sorted(result)) # lexicographic order for c in result: @@ -178,7 +179,7 @@ def numcombs(n, r): if not n: return 0 if r else 1 - return fact(n+r-1) / fact(r)/ fact(n-1) + return fact(n+r-1) // fact(r) // fact(n-1) for n in range(7): values = [5*x-12 for x in range(n)] @@ -257,7 +258,7 @@ values = [5*x-12 for x in range(n)] for r in range(n+2): result = list(permutations(values, r)) - self.assertEqual(len(result), 0 if r>n else fact(n) / fact(n-r)) # right number of perms + self.assertEqual(len(result), 0 if r>n else fact(n) // fact(n-r)) # right number of perms self.assertEqual(len(result), len(set(result))) # no repeats self.assertEqual(result, sorted(result)) # lexicographic order for p in result: @@ -288,9 +289,9 @@ # Check size self.assertEquals(len(prod), n**r) - self.assertEquals(len(cwr), (fact(n+r-1) / fact(r)/ fact(n-1)) if n else (not r)) - self.assertEquals(len(perm), 0 if r>n else fact(n) / fact(n-r)) - self.assertEquals(len(comb), 0 if r>n else fact(n) / fact(r) / fact(n-r)) + self.assertEquals(len(cwr), (fact(n+r-1) // fact(r) // fact(n-1)) if n else (not r)) + self.assertEquals(len(perm), 0 if r>n else fact(n) // fact(n-r)) + self.assertEquals(len(comb), 0 if r>n else fact(n) // fact(r) // fact(n-r)) # Check lexicographic order without repeated tuples self.assertEquals(prod, sorted(set(prod))) @@ -543,7 +544,8 @@ [range(1000), range(0), range(3000,3050), range(1200), range(1500)], [range(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)], ]: - target = map(None, *args) + target = [tuple([arg[i] if i < len(arg) else None for arg in args]) + for i in range(max(map(len, args)))] self.assertEqual(list(izip_longest(*args)), target) self.assertEqual(list(izip_longest(*args, **{})), target) target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X' @@ -555,7 +557,8 @@ self.assertEqual(list(izip_longest([])), zip([])) self.assertEqual(list(izip_longest('abcdef')), zip('abcdef')) - self.assertEqual(list(izip_longest('abc', 'defg', **{})), map(None, 'abc', 'defg')) # empty keyword dict + self.assertEqual(list(izip_longest('abc', 'defg', **{})), + zip(list('abc') + [None], 'defg')) # empty keyword dict self.assertRaises(TypeError, izip_longest, 3) self.assertRaises(TypeError, izip_longest, range(3), 3) @@ -1431,7 +1434,7 @@ # is differencing with a range so that consecutive numbers all appear in # same group. >>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28] ->>> for k, g in groupby(enumerate(data), lambda (i,x):i-x): +>>> for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]): ... print map(operator.itemgetter(1), g) ... [1] Index: Lib/test/test_linuxaudiodev.py =================================================================== --- Lib/test/test_linuxaudiodev.py (revision 77549) +++ Lib/test/test_linuxaudiodev.py (working copy) @@ -4,12 +4,13 @@ from test.test_support import findfile, run_unittest import errno -linuxaudiodev = test_support.import_module('linuxaudiodev', deprecated=True) import sys -import sunaudio import audioop import unittest +linuxaudiodev = test_support.import_module('linuxaudiodev', deprecated=True) +sunaudio = test_support.import_module('sunaudio', deprecated=True) + SND_FORMAT_MULAW_8 = 1 class LinuxAudioDevTests(unittest.TestCase): Index: Lib/test/test_mailbox.py =================================================================== --- Lib/test/test_mailbox.py (revision 77549) +++ Lib/test/test_mailbox.py (working copy) @@ -5,7 +5,6 @@ import socket import email import email.message -import rfc822 import re import StringIO from test import test_support @@ -17,6 +16,8 @@ except ImportError: pass +# Silence Py3k warning +rfc822 = test_support.import_module('rfc822') class TestBase(unittest.TestCase): Index: Lib/test/test_multibytecodec_support.py =================================================================== --- Lib/test/test_multibytecodec_support.py (revision 77549) +++ Lib/test/test_multibytecodec_support.py (working copy) @@ -307,7 +307,7 @@ continue unich = unichrs(data[1]) - if ord(unich) == 0xfffd or urt_wa.has_key(unich): + if ord(unich) == 0xfffd or unich in urt_wa: continue urt_wa[unich] = csetch Index: Lib/test/test_multifile.py =================================================================== --- Lib/test/test_multifile.py (revision 77549) +++ Lib/test/test_multifile.py (working copy) @@ -1,5 +1,5 @@ from test import test_support -import mimetools +mimetools = test_support.import_module("mimetools", deprecated=True) multifile = test_support.import_module('multifile', deprecated=True) import cStringIO Index: Lib/test/test_mutants.py =================================================================== --- Lib/test/test_mutants.py (revision 77549) +++ Lib/test/test_mutants.py (working copy) @@ -210,7 +210,7 @@ # Tim sez: "luck of the draw; crashes with or without for me." print >> f - return `"machiavelli"` + return repr("machiavelli") def __hash__(self): return 0 Index: Lib/test/test_optparse.py =================================================================== --- Lib/test/test_optparse.py (revision 77549) +++ Lib/test/test_optparse.py (working copy) @@ -26,12 +26,6 @@ from optparse import _match_abbrev from optparse import _parse_num -# Do the right thing with boolean values for all known Python versions. -try: - True, False -except NameError: - (True, False) = (1, 0) - retype = type(re.compile('')) class InterceptedError(Exception): Index: Lib/test/test_ossaudiodev.py =================================================================== --- Lib/test/test_ossaudiodev.py (revision 77549) +++ Lib/test/test_ossaudiodev.py (working copy) @@ -71,7 +71,7 @@ self.fail("dsp.%s not read-only" % attr) # Compute expected running time of sound sample (in seconds). - expected_time = float(len(data)) / (ssize/8) / nchannels / rate + expected_time = float(len(data)) / (ssize//8) / nchannels / rate # set parameters based on .au file headers dsp.setparameters(AFMT_S16_NE, nchannels, rate) Index: Lib/test/test_pkgimport.py =================================================================== --- Lib/test/test_pkgimport.py (revision 77549) +++ Lib/test/test_pkgimport.py (working copy) @@ -6,14 +6,14 @@ def __init__(self, *args, **kw): self.package_name = 'PACKAGE_' - while sys.modules.has_key(self.package_name): + while self.package_name in sys.modules: self.package_name += random.choose(string.letters) self.module_name = self.package_name + '.foo' unittest.TestCase.__init__(self, *args, **kw) def remove_modules(self): for module_name in (self.package_name, self.module_name): - if sys.modules.has_key(module_name): + if module_name in sys.modules: del sys.modules[module_name] def setUp(self): @@ -52,7 +52,7 @@ try: __import__(self.module_name) except SyntaxError: pass else: raise RuntimeError, 'Failed to induce SyntaxError' - self.assertTrue(not sys.modules.has_key(self.module_name) and + self.assertTrue(self.module_name not in sys.modules and not hasattr(sys.modules[self.package_name], 'foo')) # ...make up a variable name that isn't bound in __builtins__ Index: Lib/test/test_pyclbr.py =================================================================== --- Lib/test/test_pyclbr.py (revision 77549) +++ Lib/test/test_pyclbr.py (working copy) @@ -2,7 +2,7 @@ Test cases for pyclbr.py Nick Mathewson ''' -from test.test_support import run_unittest +from test.test_support import run_unittest, import_module import sys from types import ClassType, FunctionType, MethodType, BuiltinFunctionType import pyclbr @@ -13,6 +13,8 @@ # This next line triggers an error on old versions of pyclbr. +# Silence Py3k warning +import_module('commands', deprecated=True) from commands import getstatus # Here we test the python class browser code. @@ -40,11 +42,11 @@ def assertHaskey(self, obj, key, ignore): - ''' succeed iff obj.has_key(key) or key in ignore. ''' + ''' succeed iff key in obj or key in ignore. ''' if key in ignore: return - if not obj.has_key(key): - print >>sys.stderr, "***",key - self.assertTrue(obj.has_key(key)) + if key not in obj: + print >>sys.stderr, "***", key + self.assertTrue(key in obj) def assertEqualsOrIgnored(self, a, b, ignore): ''' succeed iff a == b or a in ignore or b in ignore ''' @@ -149,7 +151,9 @@ def test_easy(self): self.checkModule('pyclbr') self.checkModule('doctest', ignore=("DocTestCase",)) - self.checkModule('rfc822') + # Silence Py3k warning + rfc822 = import_module('rfc822', deprecated=True) + self.checkModule('rfc822', rfc822) self.checkModule('difflib') def test_decorators(self): Index: Lib/test/test_pyexpat.py =================================================================== --- Lib/test/test_pyexpat.py (revision 77549) +++ Lib/test/test_pyexpat.py (working copy) @@ -554,7 +554,7 @@ self.n=0 parser.Parse(xml1, 0) - parser.buffer_size /= 2 + parser.buffer_size //= 2 self.assertEquals(parser.buffer_size, 1024) parser.Parse(xml2, 1) self.assertEquals(self.n, 4) Index: Lib/test/test_queue.py =================================================================== --- Lib/test/test_queue.py (revision 77549) +++ Lib/test/test_queue.py (working copy) @@ -7,7 +7,8 @@ import unittest from test import test_support -QUEUE_SIZE = 5 +QUEUE_SIZE = LAST = 5 +FULL = LAST+1 # A thread to run a function that unclogs a blocked Queue. class _TriggerThread(threading.Thread): @@ -102,21 +103,21 @@ q.put(i) self.assertTrue(not q.empty(), "Queue should not be empty") self.assertTrue(not q.full(), "Queue should not be full") - q.put("last") + q.put(LAST) self.assertTrue(q.full(), "Queue should be full") try: - q.put("full", block=0) + q.put(FULL, block=0) self.fail("Didn't appear to block with a full queue") except Queue.Full: pass try: - q.put("full", timeout=0.01) + q.put(FULL, timeout=0.01) self.fail("Didn't appear to time-out with a full queue") except Queue.Full: pass # Test a blocking put - self.do_blocking_test(q.put, ("full",), q.get, ()) - self.do_blocking_test(q.put, ("full", True, 10), q.get, ()) + self.do_blocking_test(q.put, (FULL,), q.get, ()) + self.do_blocking_test(q.put, (FULL, True, 10), q.get, ()) # Empty it for i in range(QUEUE_SIZE): q.get() Index: Lib/test/test_random.py =================================================================== --- Lib/test/test_random.py (revision 77549) +++ Lib/test/test_random.py (working copy) @@ -6,6 +6,7 @@ import pickle import warnings from math import log, exp, sqrt, pi, fsum, sin +from functools import reduce from test import test_support class TestBasicOps(unittest.TestCase): Index: Lib/test/test_rfc822.py =================================================================== --- Lib/test/test_rfc822.py (revision 77549) +++ Lib/test/test_rfc822.py (working copy) @@ -46,9 +46,9 @@ continue i = i + 1 self.assertEqual(mn, n, - "Un-expected name: %s != %s" % (`mn`, `n`)) + "Un-expected name: %r != %r" % (mn, n)) self.assertEqual(ma, a, - "Un-expected address: %s != %s" % (`ma`, `a`)) + "Un-expected address: %r != %r" % (ma, a)) if mn == n and ma == a: pass else: Index: Lib/test/test_shelve.py =================================================================== --- Lib/test/test_shelve.py (revision 77549) +++ Lib/test/test_shelve.py (working copy) @@ -4,6 +4,8 @@ import glob from test import test_support +test_support.import_module('anydbm', deprecated=True) + class TestCase(unittest.TestCase): fn = "shelftemp" + os.extsep + "db" Index: Lib/test/test_site.py =================================================================== --- Lib/test/test_site.py (revision 77549) +++ Lib/test/test_site.py (working copy) @@ -258,7 +258,7 @@ site.abs__file__() for module in (sys, os, __builtin__): try: - self.assertTrue(os.path.isabs(module.__file__), `module`) + self.assertTrue(os.path.isabs(module.__file__), repr(module)) except AttributeError: continue # We could try everything in sys.modules; however, when regrtest.py @@ -310,7 +310,7 @@ def test_sitecustomize_executed(self): # If sitecustomize is available, it should have been imported. - if not sys.modules.has_key("sitecustomize"): + if "sitecustomize" not in sys.modules: try: import sitecustomize except ImportError: Index: Lib/test/test_threadsignals.py =================================================================== --- Lib/test/test_threadsignals.py (revision 77549) +++ Lib/test/test_threadsignals.py (working copy) @@ -14,7 +14,7 @@ signalled_all=thread.allocate_lock() -def registerSignals((for_usr1, for_usr2, for_alrm)): +def registerSignals(for_usr1, for_usr2, for_alrm): usr1 = signal.signal(signal.SIGUSR1, for_usr1) usr2 = signal.signal(signal.SIGUSR2, for_usr2) alrm = signal.signal(signal.SIGALRM, for_alrm) @@ -74,11 +74,11 @@ signal.SIGUSR2 : {'tripped': 0, 'tripped_by': 0 }, signal.SIGALRM : {'tripped': 0, 'tripped_by': 0 } } - oldsigs = registerSignals((handle_signals, handle_signals, handle_signals)) + oldsigs = registerSignals(handle_signals, handle_signals, handle_signals) try: run_unittest(ThreadSignals) finally: - registerSignals(oldsigs) + registerSignals(*oldsigs) if __name__ == '__main__': test_main() Index: Lib/test/test_traceback.py =================================================================== --- Lib/test/test_traceback.py (revision 77549) +++ Lib/test/test_traceback.py (working copy) @@ -4,6 +4,7 @@ from StringIO import StringIO import sys import unittest +from imp import reload from test.test_support import run_unittest, is_jython, Error import traceback @@ -148,7 +149,7 @@ def test_format_exception_only_bad__str__(self): class X(Exception): def __str__(self): - 1/0 + 1 // 0 err = traceback.format_exception_only(X, X()) self.assertEqual(len(err), 1) str_value = '' % X.__name__ Index: Lib/test/test_trace.py =================================================================== --- Lib/test/test_trace.py (revision 77549) +++ Lib/test/test_trace.py (working copy) @@ -401,7 +401,7 @@ we're testing, so that the 'exception' trace event fires.""" if self.raiseOnEvent == 'exception': x = 0 - y = 1/x + y = 1 // x else: return 1 Index: Lib/test/test_transformer.py =================================================================== --- Lib/test/test_transformer.py (revision 77549) +++ Lib/test/test_transformer.py (working copy) @@ -1,5 +1,8 @@ import unittest from test import test_support + +# Silence Py3k warning +test_support.import_module('compiler', deprecated=True) from compiler import transformer, ast from compiler import compile Index: Lib/test/test_unittest.py =================================================================== --- Lib/test/test_unittest.py (revision 77549) +++ Lib/test/test_unittest.py (working copy) @@ -3056,7 +3056,7 @@ try: self.assertRaises(KeyError, lambda: None) except self.failureException as e: - self.assert_("KeyError not raised" in e, str(e)) + self.assert_("KeyError not raised" in e.args, str(e)) else: self.fail("assertRaises() didn't fail") try: @@ -3073,7 +3073,7 @@ with self.assertRaises(KeyError): pass except self.failureException as e: - self.assert_("KeyError not raised" in e, str(e)) + self.assert_("KeyError not raised" in e.args, str(e)) else: self.fail("assertRaises() didn't fail") try: @@ -3591,6 +3591,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_urllib2_localnet.py =================================================================== --- Lib/test/test_urllib2_localnet.py (revision 77549) +++ Lib/test/test_urllib2_localnet.py (working copy) @@ -1,6 +1,5 @@ #!/usr/bin/env python -import mimetools import threading import urlparse import urllib2 @@ -8,6 +7,7 @@ import unittest import hashlib from test import test_support +mimetools = test_support.import_module('mimetools', deprecated=True) # Loopback http server infrastructure @@ -154,13 +154,13 @@ if len(self._users) == 0: return True - if not request_handler.headers.has_key('Proxy-Authorization'): + if 'Proxy-Authorization' not in request_handler.headers: return self._return_auth_challenge(request_handler) else: auth_dict = self._create_auth_dict( request_handler.headers['Proxy-Authorization'] ) - if self._users.has_key(auth_dict["username"]): + if auth_dict["username"] in self._users: password = self._users[ auth_dict["username"] ] else: return self._return_auth_challenge(request_handler) Index: Lib/test/test_urllibnet.py =================================================================== --- Lib/test/test_urllibnet.py (revision 77549) +++ Lib/test/test_urllibnet.py (working copy) @@ -7,7 +7,7 @@ import urllib import sys import os -import mimetools +mimetools = test_support.import_module("mimetools", deprecated=True) def _open_with_retry(func, host, *args, **kwargs): Index: Lib/test/test_whichdb.py =================================================================== --- Lib/test/test_whichdb.py (revision 77549) +++ Lib/test/test_whichdb.py (working copy) @@ -7,11 +7,13 @@ import test.test_support import unittest import whichdb -import anydbm import glob _fname = test.test_support.TESTFN +# Silence Py3k warning +anydbm = test.test_support.import_module('anydbm', deprecated=True) + def _delete_files(): # we don't know the precise name the underlying database uses # so we use glob to locate all names @@ -37,8 +39,9 @@ # we define a new test method for each # candidate database module. try: - mod = __import__(name) - except ImportError: + # Silence Py3k warning + mod = test.test_support.import_module(name, deprecated=True) + except unittest.SkipTest: continue def test_whichdb_name(self, name=name, mod=mod): Index: Lib/test/test_with.py =================================================================== --- Lib/test/test_with.py (revision 77549) +++ Lib/test/test_with.py (working copy) @@ -520,7 +520,7 @@ self.assertRaises(AssertionError, falseAsBool) def failAsBool(): - with cm(lambda: 1//0): + with cm(lambda: 1 // 0): self.fail("Should NOT see this") self.assertRaises(ZeroDivisionError, failAsBool) @@ -628,7 +628,7 @@ def __exit__(self, t, v, tb): return True try: with AfricanSwallow(): - 1/0 + 1 // 0 except ZeroDivisionError: self.fail("ZeroDivisionError should have been swallowed") @@ -638,7 +638,7 @@ def __exit__(self, t, v, tb): return False try: with EuropeanSwallow(): - 1/0 + 1 // 0 except ZeroDivisionError: pass else: Index: Lib/test/test_wsgiref.py =================================================================== --- Lib/test/test_wsgiref.py (revision 77549) +++ Lib/test/test_wsgiref.py (working copy) @@ -432,10 +432,10 @@ env = handler.environ from os import environ for k,v in environ.items(): - if not empty.has_key(k): + if k not in empty: self.assertEqual(env[k],v) for k,v in empty.items(): - self.assertTrue(env.has_key(k)) + self.assertTrue(k in env) def testEnviron(self): h = TestHandler(X="Y") @@ -448,7 +448,7 @@ h = BaseCGIHandler(None,None,None,{}) h.setup_environ() for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors': - self.assertTrue(h.environ.has_key(key)) + self.assertTrue(key in h.environ) def testScheme(self): h=TestHandler(HTTPS="on"); h.setup_environ() Index: Lib/test/test_xml_etree_c.py =================================================================== --- Lib/test/test_xml_etree_c.py (revision 77549) +++ Lib/test/test_xml_etree_c.py (working copy) @@ -35,7 +35,7 @@ """ def check_method(method): - if not callable(method): + if not hasattr(method, '__call__'): print method, "not callable" def serialize(ET, elem, encoding=None): Index: Lib/test/test_xml_etree.py =================================================================== --- Lib/test/test_xml_etree.py (revision 77549) +++ Lib/test/test_xml_etree.py (working copy) @@ -37,7 +37,7 @@ """ def check_method(method): - if not callable(method): + if not hasattr(method, '__call__'): print method, "not callable" def serialize(ET, elem, encoding=None): Index: Lib/test/test_xmllib.py =================================================================== --- Lib/test/test_xmllib.py (revision 77549) +++ Lib/test/test_xmllib.py (working copy) @@ -15,13 +15,10 @@ nsdoc = "" -import warnings -warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*", - DeprecationWarning, r'xmllib$') - from test import test_support import unittest -import xmllib +# Silence Py3k warning +xmllib = test_support.import_module('xmllib', deprecated=True) class XMLParserTestCase(unittest.TestCase): Index: Lib/test/test_xpickle.py =================================================================== --- Lib/test/test_xpickle.py (revision 77549) +++ Lib/test/test_xpickle.py (working copy) @@ -25,7 +25,7 @@ mod_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "pickletester.py")) pickletester = types.ModuleType("test.pickletester") -execfile(mod_path, pickletester.__dict__, pickletester.__dict__) +exec compile(open(mod_path).read(), mod_path, 'exec') in pickletester.__dict__ AbstractPickleTests = pickletester.AbstractPickleTests if pickletester.__name__ in sys.modules: raise RuntimeError("Did not expect to find test.pickletester loaded")