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.
........
diff --git a/Lib/test/infinite_reload.py b/Lib/test/infinite_reload.py
index bfbec91..841ccad 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 823559b..afde2e2 100644
--- a/Lib/test/inspect_fodder.py
+++ b/Lib/test/inspect_fodder.py
@@ -15,7 +15,7 @@
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 8ab9973..2177b66 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -133,6 +133,7 @@
# 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 @@
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 b3d9a62..541f07f 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -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."""
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index c7ec50f..e5b8365 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -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",
"<string>", "exec")
dct = {}
exec c in dct
diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py
index c455e6b..157b9f4 100644
--- a/Lib/test/test_descrtut.py
+++ b/Lib/test/test_descrtut.py
@@ -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]
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 0907744..3ae0435 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -582,11 +582,14 @@
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 d77fb42..5ee037d 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -118,7 +118,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)
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index c48497d..1c2ceeb 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -90,7 +90,8 @@
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 6666685..31f8f70 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -119,7 +119,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)
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index f8cef6a..58dda40 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 @@
f1(*(), **{})
def f2(one_argument): pass
def f3(two, arguments): pass
- def f4(two, (compound, (argument, list))): pass
- def f5((compound, first), two): pass
+ # Silence Py3k warning
+ exec('def f4(two, (compound, (argument, list))): pass')
+ exec('def f5((compound, first), two): pass')
self.assertEquals(f2.func_code.co_varnames, ('one_argument',))
self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments'))
if sys.platform.startswith('java'):
@@ -172,7 +174,8 @@
def v0(*rest): pass
def v1(a, *rest): pass
def v2(a, b, *rest): pass
- def v3(a, (b, c), *rest): return a, b, c, rest
+ # Silence Py3k warning
+ exec('def v3(a, (b, c), *rest): return a, b, c, rest')
f1()
f2(1)
@@ -277,9 +280,10 @@
d22v(*(1, 2, 3, 4))
d22v(1, 2, *(3, 4, 5))
d22v(1, *(2, 3), **{'d': 4})
- def d31v((x)): pass
+ # Silence Py3k warning
+ exec('def d31v((x)): pass')
+ exec('def d32v((x,)): pass')
d31v(1)
- def d32v((x,)): pass
d32v((1,))
# keyword arguments after *arglist
@@ -474,7 +478,7 @@
continue
except:
raise
- if count > 2 or big_hippo <> 1:
+ if count > 2 or big_hippo != 1:
self.fail("continue then break in try/except in loop broken!")
test_inner()
@@ -536,7 +540,7 @@
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 @@
import warnings
warnings.filterwarnings("ignore", "global statement", module="<string>")
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 @@
x = (1 == 1)
if 1 == 1: pass
if 1 != 1: pass
- if 1 <> 1: pass
if 1 < 1: pass
if 1 > 1: pass
if 1 <= 1: pass
@@ -686,7 +689,10 @@
if 1 is not 1: pass
if 1 in (): pass
if 1 not in (): pass
- if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass
+ if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1: pass
+ # Silence Py3k warning
+ if eval('1 <> 1'): pass
+ if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass
def testBinaryMaskOps(self):
x = 1 & 1
@@ -769,9 +775,10 @@
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 @@
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 5d23b29..bbf21ce 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -7,6 +7,7 @@
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 @@
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)
+ imp.reload(mod)
+ except ImportError, err:
+ self.fail("import from .pyc/.pyo failed: %s" % err)
finally:
try:
os.unlink(pyc)
@@ -159,7 +158,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
@@ -205,7 +204,7 @@
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 643ecce..c4f7399 100644
--- a/Lib/test/test_importhooks.py
+++ b/Lib/test/test_importhooks.py
@@ -180,7 +180,7 @@
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 @@
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 300d143..9be8f79 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -119,7 +119,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)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 5cfa472..0d471d2 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -248,11 +248,11 @@
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 2ba1e8e..de71fda 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -7,6 +7,7 @@
import random
import copy
import pickle
+from functools import reduce
maxsize = test_support.MAX_Py_ssize_t
minsize = -maxsize-1
@@ -112,7 +113,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:
@@ -176,7 +177,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:
@@ -370,7 +371,10 @@
[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 @@
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 @@
# 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 a219450..69c381e 100644
--- a/Lib/test/test_mutants.py
+++ b/Lib/test/test_mutants.py
@@ -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
diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py
index d7d1673..36bd3ff 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 @@
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 @@
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 2fad442..4ab4d89 100644
--- a/Lib/test/test_optparse.py
+++ b/Lib/test/test_optparse.py
@@ -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):
diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py
index 8c45bb5..2fa9962 100644
--- a/Lib/test/test_ossaudiodev.py
+++ b/Lib/test/test_ossaudiodev.py
@@ -44,7 +44,8 @@
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 @@
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 @@
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 c87c342..5e02b1b 100644
--- a/Lib/test/test_pkgimport.py
+++ b/Lib/test/test_pkgimport.py
@@ -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,8 +52,8 @@
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 9ea44d7..0628a57 100644
--- a/Lib/test/test_pyexpat.py
+++ b/Lib/test/test_pyexpat.py
@@ -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)
diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py
index e0eb8f4..cecb0a1 100644
--- a/Lib/test/test_queue.py
+++ b/Lib/test/test_queue.py
@@ -102,21 +102,23 @@
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 937bb4c..50d45f2 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -6,6 +6,7 @@
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 1094816..8c683fb 100644
--- a/Lib/test/test_repr.py
+++ b/Lib/test/test_repr.py
@@ -8,7 +8,7 @@
import shutil
import unittest
-from test.test_support import run_unittest
+from test.test_support import run_unittest, _check_py3k_warnings
from repr import repr as r # Don't shadow builtin repr
from repr import Repr
@@ -174,7 +174,8 @@
def test_buffer(self):
# XXX doesn't test buffers with no b_base or read-write buffers (see
# bufferobject.c). The test is fairly incomplete too. Sigh.
- x = buffer('foo')
+ with _check_py3k_warnings():
+ x = buffer('foo')
self.failUnless(repr(x).startswith('<read-only buffer for 0x'))
def test_cell(self):
diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py
index afbc984..a05325d 100644
--- a/Lib/test/test_rfc822.py
+++ b/Lib/test/test_rfc822.py
@@ -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:
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 026cb89..4a05196 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -196,7 +196,7 @@
site.abs__file__()
for module in (sys, os, __builtin__):
try:
- self.failUnless(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
@@ -248,7 +248,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:
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 980606d..fd6fb2b 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -75,7 +75,8 @@
self.assert_(value is exc)
self.assert_(traceback is not None)
- sys.exc_clear()
+ with test.test_support._check_py3k_warnings():
+ sys.exc_clear()
typ, value, traceback = sys.exc_info()
self.assert_(typ is None)
@@ -498,7 +499,8 @@
# bool
check(True, size(h + 'l'))
# buffer
- check(buffer(''), size(h + '2P2Pil'))
+ with test.test_support._check_py3k_warnings():
+ check(buffer(''), size(h + '2P2Pil'))
# builtin_function_or_method
check(len, size(h + '3P'))
# bytearray
diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py
index 1f10fe7..286c2e4 100644
--- a/Lib/test/test_threadsignals.py
+++ b/Lib/test/test_threadsignals.py
@@ -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()
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index ea75a9e..8e3d483 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -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
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 6ef70a6..8b93844 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -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
@@ -158,7 +159,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 = '<unprintable %s object>' % X.__name__
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index bfeb06b..1364bef 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -529,7 +529,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)
@@ -637,7 +637,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")
@@ -647,7 +647,7 @@
def __exit__(self, t, v, tb): return False
try:
with EuropeanSwallow():
- 1/0
+ 1 // 0
except ZeroDivisionError:
pass
else:
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 1f46a3e..0d76595 100755
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -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.failUnless(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.assert_(h.environ.has_key(key))
+ self.assertTrue(key in h.environ)
def testScheme(self):
h=TestHandler(HTTPS="on"); h.setup_environ()
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 65c99f1..2e24ed1 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -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):
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
index 7ddd44b..7c57000 100644
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -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):