Commit 3efafd77 authored by Ezio Melotti's avatar Ezio Melotti

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.
........
parent 5ff2745f
......@@ -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
......
......@@ -367,10 +367,10 @@ 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),
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),
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))
......
......@@ -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
......
......@@ -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
......
......@@ -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):
......
......@@ -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):
......
......@@ -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)
......@@ -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:
......
......@@ -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
......
......@@ -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."""
......
......@@ -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",
"<string>", "exec")
dct = {}
exec c in dct
......
......@@ -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]
......
......@@ -582,6 +582,9 @@ class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
type2test = Dict
def test_main():
with test_support._check_py3k_warnings(
('dict(.has_key..| inequality comparisons) not supported in 3.x',
DeprecationWarning)):
test_support.run_unittest(
DictTest,
GeneralMappingTests,
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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="<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 @@ 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,6 +955,12 @@ hello world
def test_main():
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__':
......
......@@ -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)
......@@ -55,12 +56,11 @@ class ImportTest(unittest.TestCase):
print >> f, "b =", b
f.close()
try:
try:
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,8 +69,7 @@ class ImportTest(unittest.TestCase):
os.unlink(source)
try:
try:
reload(mod)
imp.reload(mod)
except ImportError, err:
self.fail("import from .pyc/.pyo failed: %s" % err)
finally:
......@@ -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)
......
......@@ -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,6 +247,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
for n in sys.modules.keys():
if n.startswith(parent):
del sys.modules[n]
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
......
......@@ -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)
......
......@@ -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):
......
......@@ -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]
......
......@@ -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
......
# 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,6 +104,11 @@ class OpcodeTest(unittest.TestCase):
def test_main():
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__':
......
......@@ -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):
......
......@@ -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()
......
......@@ -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'
......
......@@ -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)
......
......@@ -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()
......
......@@ -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):
......
......@@ -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,6 +174,7 @@ 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.
with _check_py3k_warnings():
x = buffer('foo')
self.failUnless(repr(x).startswith('<read-only buffer for 0x'))
......
......@@ -46,9 +46,9 @@ class MessageTestCase(unittest.TestCase):
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:
......
......@@ -196,7 +196,7 @@ class ImportSideEffectTests(unittest.TestCase):
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 @@ class ImportSideEffectTests(unittest.TestCase):
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:
......
......@@ -75,6 +75,7 @@ class SysModuleTest(unittest.TestCase):
self.assert_(value is exc)
self.assert_(traceback is not None)
with test.test_support._check_py3k_warnings():
sys.exc_clear()
typ, value, traceback = sys.exc_info()
......@@ -498,6 +499,7 @@ class SizeofTest(unittest.TestCase):
# bool
check(True, size(h + 'l'))
# buffer
with test.test_support._check_py3k_warnings():
check(buffer(''), size(h + '2P2Pil'))
# builtin_function_or_method
check(len, size(h + '3P'))
......
......@@ -14,7 +14,7 @@ process_pid = os.getpid()
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 @@ def test_main():
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()
......@@ -401,7 +401,7 @@ class RaisingTraceFuncTestCase(unittest.TestCase):
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
......
......@@ -4,6 +4,7 @@ from _testcapi import traceback_print
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():
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__
......
......@@ -529,7 +529,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
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 @@ class ExitSwallowsExceptionTestCase(unittest.TestCase):
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 @@ class ExitSwallowsExceptionTestCase(unittest.TestCase):
def __exit__(self, t, v, tb): return False
try:
with EuropeanSwallow():
1/0
1 // 0
except ZeroDivisionError:
pass
else:
......
......@@ -432,10 +432,10 @@ class HandlerTests(TestCase):
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 @@ class HandlerTests(TestCase):
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()
......
......@@ -37,7 +37,7 @@ def sanity():
"""
def check_method(method):
if not callable(method):
if not hasattr(method, '__call__'):
print method, "not callable"
def serialize(ET, elem, encoding=None):
......
......@@ -35,7 +35,7 @@ def sanity():
"""
def check_method(method):
if not callable(method):
if not hasattr(method, '__call__'):
print method, "not callable"
def serialize(ET, elem, encoding=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment