From 3efafd77498def137f4afbcf2abee9aa2aed460a Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Mon, 2 Aug 2010 18:40:55 +0000 Subject: [PATCH] Merged revisions 77942,79023 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77942 | ezio.melotti | 2010-02-03 07:37:26 +0200 (Wed, 03 Feb 2010) | 1 line #7092: Silence more py3k warnings. Patch by Florent Xicluna. ........ r79023 | ezio.melotti | 2010-03-17 15:52:48 +0200 (Wed, 17 Mar 2010) | 1 line #7092: silence some more py3k warnings. ........ --- Lib/ctypes/test/test_pep3118.py | 2 +- Lib/ctypes/test/test_structures.py | 8 ++--- Lib/email/test/test_email.py | 2 +- Lib/email/test/test_email_renamed.py | 2 +- Lib/sqlite3/test/types.py | 2 +- Lib/sqlite3/test/userfunctions.py | 8 ++--- Lib/test/infinite_reload.py | 3 +- Lib/test/inspect_fodder.py | 2 +- Lib/test/regrtest.py | 3 +- Lib/test/test_binop.py | 3 ++ Lib/test/test_compiler.py | 2 +- Lib/test/test_descrtut.py | 2 +- Lib/test/test_dict.py | 13 ++++---- Lib/test/test_file.py | 2 +- Lib/test/test_ftplib.py | 3 +- Lib/test/test_functools.py | 2 +- Lib/test/test_grammar.py | 45 ++++++++++++++++++---------- Lib/test/test_import.py | 21 +++++++------ Lib/test/test_importhooks.py | 9 +++--- Lib/test/test_inspect.py | 2 +- Lib/test/test_io.py | 4 +-- Lib/test/test_itertools.py | 15 ++++++---- Lib/test/test_mutants.py | 2 +- Lib/test/test_opcodes.py | 11 +++++-- Lib/test/test_optparse.py | 6 ---- Lib/test/test_ossaudiodev.py | 8 +++-- Lib/test/test_pkgimport.py | 8 ++--- Lib/test/test_pyexpat.py | 2 +- Lib/test/test_queue.py | 12 ++++---- Lib/test/test_random.py | 1 + Lib/test/test_repr.py | 5 ++-- Lib/test/test_rfc822.py | 4 +-- Lib/test/test_site.py | 4 +-- Lib/test/test_sys.py | 6 ++-- Lib/test/test_threadsignals.py | 6 ++-- Lib/test/test_trace.py | 2 +- Lib/test/test_traceback.py | 3 +- Lib/test/test_with.py | 6 ++-- Lib/test/test_wsgiref.py | 6 ++-- Lib/test/test_xml_etree.py | 2 +- Lib/test/test_xml_etree_c.py | 2 +- 41 files changed, 143 insertions(+), 108 deletions(-) diff --git a/Lib/ctypes/test/test_pep3118.py b/Lib/ctypes/test/test_pep3118.py index 4ff2c3ed367..d3550cc85a0 100644 --- a/Lib/ctypes/test/test_pep3118.py +++ b/Lib/ctypes/test/test_pep3118.py @@ -24,7 +24,7 @@ class memoryview(object): else: size = sizeof(ob) for dim in self.shape: - size /= dim + size //= dim self.itemsize = size self.strides = None self.readonly = False diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index d4541a9e94d..35bea62761a 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -367,11 +367,11 @@ class StructureTestCase(unittest.TestCase): _fields_ = [("d", c_int), ("e", c_int), ("f", c_int)] z = Z(1, 2, 3, 4, 5, 6) - self.failUnlessEqual((z.a, z.b, z.c, z.d, z.e, z.f), - (1, 2, 3, 4, 5, 6)) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 2, 3, 4, 5, 6)) z = Z(1) - self.failUnlessEqual((z.a, z.b, z.c, z.d, z.e, z.f), - (1, 0, 0, 0, 0, 0)) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 0, 0, 0, 0, 0)) self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7)) class PointerMemberTestCase(unittest.TestCase): diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 5458e718d83..bf5272e6f4e 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1086,7 +1086,7 @@ This is the dingus fish. 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 diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py index 307501f5f48..22bbe663335 100644 --- a/Lib/email/test/test_email_renamed.py +++ b/Lib/email/test/test_email_renamed.py @@ -1044,7 +1044,7 @@ This is the dingus fish. 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 diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py index 471425d6042..4a469e788c4 100644 --- a/Lib/sqlite3/test/types.py +++ b/Lib/sqlite3/test/types.py @@ -226,7 +226,7 @@ class ColNamesTests(unittest.TestCase): sqlite.converters["FOO"] = lambda x: "[%s]" % x sqlite.converters["BAR"] = lambda x: "<%s>" % x - sqlite.converters["EXC"] = lambda x: 5/0 + sqlite.converters["EXC"] = lambda x: 5 // 0 sqlite.converters["B1B1"] = lambda x: "MARKER" def tearDown(self): diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py index 8a1130de88f..42559e325fc 100644 --- a/Lib/sqlite3/test/userfunctions.py +++ b/Lib/sqlite3/test/userfunctions.py @@ -38,7 +38,7 @@ def func_returnnull(): def func_returnblob(): return buffer("blob") def func_raiseexception(): - 5/0 + 5 // 0 def func_isstring(v): return type(v) is unicode @@ -67,7 +67,7 @@ class AggrNoFinalize: class AggrExceptionInInit: def __init__(self): - 5/0 + 5 // 0 def step(self, x): pass @@ -80,7 +80,7 @@ class AggrExceptionInStep: pass def step(self, x): - 5/0 + 5 // 0 def finalize(self): return 42 @@ -93,7 +93,7 @@ class AggrExceptionInFinalize: pass def finalize(self): - 5/0 + 5 // 0 class AggrCheckType: def __init__(self): diff --git a/Lib/test/infinite_reload.py b/Lib/test/infinite_reload.py index bfbec91b0a1..841ccad0b98 100644 --- a/Lib/test/infinite_reload.py +++ b/Lib/test/infinite_reload.py @@ -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) diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py index 823559bb351..afde2e2514b 100644 --- a/Lib/test/inspect_fodder.py +++ b/Lib/test/inspect_fodder.py @@ -15,7 +15,7 @@ def eggs(x, y): fr = inspect.currentframe() st = inspect.stack() p = x - q = y / 0 + q = y // 0 # line 20 class StupidGit: diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 8ab9973cedb..2177b66e1a8 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -133,6 +133,7 @@ import warnings # keep a reference to the ascii module to workaround #7140 bug # (see issue #7027) import encodings.ascii +import imp # I see no other way to suppress these warnings; # putting them in test_grammar.py has no effect: @@ -657,7 +658,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks): indirect_test() else: def run_the_test(): - reload(the_module) + imp.reload(the_module) deltas = [] nwarmup, ntracked, fname = huntrleaks diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py index b3d9a625ffe..541f07f5073 100644 --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -207,6 +207,9 @@ class Rat(object): """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.""" diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index c7ec50fe51a..e5b8365ef9b 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -75,7 +75,7 @@ class CompilerTest(unittest.TestCase): 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 diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index c455e6b7106..157b9f4fe9c 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -66,7 +66,7 @@ dictionaries, such as the locals/globals dictionaries for the exec statement or the built-in function eval(): >>> def sorted(seq): - ... seq.sort() + ... seq.sort(key=str) ... return seq >>> print sorted(a.keys()) [1, 2] diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 0907744ab5f..3ae0435940d 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -582,11 +582,14 @@ class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol): type2test = Dict def test_main(): - test_support.run_unittest( - DictTest, - GeneralMappingTests, - SubclassMappingTests, - ) + with test_support._check_py3k_warnings( + ('dict(.has_key..| inequality comparisons) not supported in 3.x', + DeprecationWarning)): + test_support.run_unittest( + DictTest, + GeneralMappingTests, + SubclassMappingTests, + ) if __name__ == "__main__": test_main() diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index d77fb423544..5ee037dce30 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -118,7 +118,7 @@ class AutoFileTests(unittest.TestCase): 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) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index c48497de343..1c2ceeb8728 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -90,7 +90,8 @@ class DummyFTPHandler(asynchat.async_chat): 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 = DummyDTPHandler(conn, baseclass=self) diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 6666685587c..31f8f7037df 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -119,7 +119,7 @@ class TestPartial(unittest.TestCase): 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) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index f8cef6ac94f..58dda405105 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -8,7 +8,8 @@ # regression test, the filterwarnings() call has been added to # regrtest.py. -from test.test_support import run_unittest, check_syntax_error +from test.test_support import (run_unittest, check_syntax_error, + _check_py3k_warnings) import unittest import sys # testing import * @@ -152,8 +153,9 @@ class GrammarTests(unittest.TestCase): 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 @@ class GrammarTests(unittest.TestCase): 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 @@ class GrammarTests(unittest.TestCase): 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 @@ hello world 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() @@ -536,7 +540,7 @@ hello world if z != 2: self.fail('exec u\'z=1+1\'')""" g = {} exec 'z = 1' in g - if g.has_key('__builtins__'): del g['__builtins__'] + if '__builtins__' in g: del g['__builtins__'] if g != {'z': 1}: self.fail('exec \'z = 1\' in g') g = {} l = {} @@ -544,8 +548,8 @@ hello world import warnings warnings.filterwarnings("ignore", "global statement", module="") exec 'global a; a = 1; b = 2' in g, l - if g.has_key('__builtins__'): del g['__builtins__'] - if l.has_key('__builtins__'): del l['__builtins__'] + if '__builtins__' in g: del g['__builtins__'] + if '__builtins__' in l: del l['__builtins__'] if (g, l) != ({'a':1}, {'b':2}): self.fail('exec ... in g (%s), l (%s)' %(g,l)) @@ -677,7 +681,6 @@ hello world 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 @@ hello world 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 @@ -769,9 +775,10 @@ hello world x = {'one': 1, 'two': 2,} x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} - 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' @@ -948,7 +955,13 @@ hello world def test_main(): - run_unittest(TokenTests, GrammarTests) + with _check_py3k_warnings( + ("backquote not supported", SyntaxWarning), + ("tuple parameter unpacking has been removed", SyntaxWarning), + ("parenthesized argument names are invalid", SyntaxWarning), + ("classic int division", DeprecationWarning), + (".+ not supported in 3.x", DeprecationWarning)): + run_unittest(TokenTests, GrammarTests) if __name__ == '__main__': test_main() diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 5d23b290d1f..bbf21ceb8fa 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -7,6 +7,7 @@ import sys import py_compile import warnings import marshal +import imp from test.test_support import (unlink, TESTFN, unload, run_unittest, check_warnings, TestFailed) @@ -56,11 +57,10 @@ class ImportTest(unittest.TestCase): 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 @@ class ImportTest(unittest.TestCase): os.unlink(source) try: - try: - reload(mod) - except ImportError, err: - self.fail("import from .pyc/.pyo failed: %s" % err) + imp.reload(mod) + except ImportError, err: + self.fail("import from .pyc/.pyo failed: %s" % err) finally: try: os.unlink(pyc) @@ -159,7 +158,7 @@ class ImportTest(unittest.TestCase): 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 @@ -205,7 +204,7 @@ class ImportTest(unittest.TestCase): print >> f, "b = 20//0" f.close() - self.assertRaises(ZeroDivisionError, reload, mod) + self.assertRaises(ZeroDivisionError, imp.reload, mod) # But we still expect the module to be in sys.modules. mod = sys.modules.get(TESTFN) diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py index 643ecce53a5..c4f739950aa 100644 --- a/Lib/test/test_importhooks.py +++ b/Lib/test/test_importhooks.py @@ -180,7 +180,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase): self.failIf(hasattr(reloadmodule,'reloaded')) TestImporter.modules['reloadmodule'] = (False, reload_co) - reload(reloadmodule) + imp.reload(reloadmodule) self.failUnless(hasattr(reloadmodule,'reloaded')) import hooktestpackage.oldabs @@ -247,9 +247,10 @@ class ImportHooksTestCase(ImportHooksBaseTestCase): 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 + with test_support._check_py3k_warnings(): + for mname in mnames: + m = __import__(mname, globals(), locals(), ["__dummy__"]) + m.__loader__ # to make sure we actually handled the import def test_main(): diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 300d1436f20..9be8f7981cc 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -119,7 +119,7 @@ class TestInterpreterStack(IsTestBase): 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) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 5cfa472916b..0d471d2fcb0 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -248,11 +248,11 @@ class IOTest(unittest.TestCase): f = None try: with open(test_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): diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 2ba1e8ee414..de71fda5de2 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -7,6 +7,7 @@ import operator import random import copy import pickle +from functools import reduce maxsize = test_support.MAX_Py_ssize_t minsize = -maxsize-1 @@ -112,7 +113,7 @@ class TestBasicOps(unittest.TestCase): 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: @@ -176,7 +177,7 @@ class TestBasicOps(unittest.TestCase): 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: @@ -370,7 +371,10 @@ class TestBasicOps(unittest.TestCase): [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 = map(None, *args) <- this raises a py3k warning + # this is the replacement: + 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' @@ -382,7 +386,8 @@ class TestBasicOps(unittest.TestCase): 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) @@ -1228,7 +1233,7 @@ Samuele # 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] diff --git a/Lib/test/test_mutants.py b/Lib/test/test_mutants.py index a219450b255..69c381e0607 100644 --- a/Lib/test/test_mutants.py +++ b/Lib/test/test_mutants.py @@ -210,7 +210,7 @@ class Machiavelli: # Tim sez: "luck of the draw; crashes with or without for me." print >> f - return `"machiavelli"` + return repr("machiavelli") def __hash__(self): return 0 diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index d7d1673a879..36bd3ff2252 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -1,6 +1,6 @@ # Python test set -- part 2, opcodes -from test.test_support import run_unittest +from test.test_support import run_unittest, _check_py3k_warnings import unittest class OpcodeTest(unittest.TestCase): @@ -9,7 +9,7 @@ class OpcodeTest(unittest.TestCase): 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 @@ -104,7 +104,12 @@ class OpcodeTest(unittest.TestCase): def test_main(): - run_unittest(OpcodeTest) + with _check_py3k_warnings(("exceptions must derive from BaseException", + DeprecationWarning), + ("catching classes that don't inherit " + "from BaseException is not allowed", + DeprecationWarning)): + run_unittest(OpcodeTest) if __name__ == '__main__': test_main() diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py index 2fad442f7c0..4ab4d89d9a7 100644 --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -26,12 +26,6 @@ from optparse import make_option, Option, IndentedHelpFormatter, \ 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): diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index 8c45bb58ee6..2fa9962e0bd 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -44,7 +44,8 @@ class OSSAudioDevTests(unittest.TestCase): try: dsp = ossaudiodev.open('w') except IOError, msg: - if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): + if msg.args[0] in (errno.EACCES, errno.ENOENT, + errno.ENODEV, errno.EBUSY): raise TestSkipped(msg) raise @@ -70,7 +71,7 @@ class OSSAudioDevTests(unittest.TestCase): 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) @@ -161,7 +162,8 @@ def test_main(): try: dsp = ossaudiodev.open('w') except (ossaudiodev.error, IOError), msg: - if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): + if msg.args[0] in (errno.EACCES, errno.ENOENT, + errno.ENODEV, errno.EBUSY): raise TestSkipped(msg) raise dsp.close() diff --git a/Lib/test/test_pkgimport.py b/Lib/test/test_pkgimport.py index c87c342b75c..5e02b1b6a03 100644 --- a/Lib/test/test_pkgimport.py +++ b/Lib/test/test_pkgimport.py @@ -6,14 +6,14 @@ class TestImport(unittest.TestCase): 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,8 +52,8 @@ class TestImport(unittest.TestCase): try: __import__(self.module_name) except SyntaxError: pass else: raise RuntimeError, 'Failed to induce SyntaxError' - self.assert_(not sys.modules.has_key(self.module_name) and - not hasattr(sys.modules[self.package_name], 'foo')) + self.assertTrue(self.module_name not in sys.modules) + self.assertFalse(hasattr(sys.modules[self.package_name], 'foo')) # ...make up a variable name that isn't bound in __builtins__ var = 'a' diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 9ea44d7935c..0628a57c155 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -554,7 +554,7 @@ class ChardataBufferTest(unittest.TestCase): 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) diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index e0eb8f40cba..cecb0a1f188 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -102,21 +102,23 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin): q.put(i) self.assert_(not q.empty(), "Queue should not be empty") self.assert_(not q.full(), "Queue should not be full") - q.put("last") + last = 2 * QUEUE_SIZE + full = 3 * 2 * QUEUE_SIZE + q.put(last) self.assert_(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() diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 937bb4cf381..50d45f2d9b2 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -6,6 +6,7 @@ import time import pickle import warnings from math import log, exp, sqrt, pi, fsum as msum +from functools import reduce from test import test_support class TestBasicOps(unittest.TestCase): diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index 1094816ae60..8c683fb4e2d 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -8,7 +8,7 @@ import os import shutil import unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, _check_py3k_warnings from repr import repr as r # Don't shadow builtin repr from repr import Repr @@ -174,7 +174,8 @@ class ReprTests(unittest.TestCase): def test_buffer(self): # XXX doesn't test buffers with no b_base or read-write buffers (see # bufferobject.c). The test is fairly incomplete too. Sigh. - x = buffer('foo') + with _check_py3k_warnings(): + x = buffer('foo') self.failUnless(repr(x).startswith('