#7092: Silence more py3k warnings. Patch by Florent Xicluna.
This commit is contained in:
parent
17ae2ba78f
commit
dde5b94875
|
@ -367,11 +367,11 @@ class StructureTestCase(unittest.TestCase):
|
||||||
_fields_ = [("d", c_int), ("e", c_int), ("f", c_int)]
|
_fields_ = [("d", c_int), ("e", c_int), ("f", c_int)]
|
||||||
|
|
||||||
z = Z(1, 2, 3, 4, 5, 6)
|
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))
|
(1, 2, 3, 4, 5, 6))
|
||||||
z = Z(1)
|
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))
|
(1, 0, 0, 0, 0, 0))
|
||||||
self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7))
|
self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7))
|
||||||
|
|
||||||
class PointerMemberTestCase(unittest.TestCase):
|
class PointerMemberTestCase(unittest.TestCase):
|
||||||
|
|
|
@ -1055,7 +1055,7 @@ This is the dingus fish.
|
||||||
sign = '-'
|
sign = '-'
|
||||||
else:
|
else:
|
||||||
sign = '+'
|
sign = '+'
|
||||||
tzoffset = ' %s%04d' % (sign, tzsecs / 36)
|
tzoffset = ' %s%04d' % (sign, tzsecs // 36)
|
||||||
container['Date'] = time.strftime(
|
container['Date'] = time.strftime(
|
||||||
'%a, %d %b %Y %H:%M:%S',
|
'%a, %d %b %Y %H:%M:%S',
|
||||||
time.localtime(now)) + tzoffset
|
time.localtime(now)) + tzoffset
|
||||||
|
|
|
@ -1053,7 +1053,7 @@ This is the dingus fish.
|
||||||
sign = '-'
|
sign = '-'
|
||||||
else:
|
else:
|
||||||
sign = '+'
|
sign = '+'
|
||||||
tzoffset = ' %s%04d' % (sign, tzsecs / 36)
|
tzoffset = ' %s%04d' % (sign, tzsecs // 36)
|
||||||
container['Date'] = time.strftime(
|
container['Date'] = time.strftime(
|
||||||
'%a, %d %b %Y %H:%M:%S',
|
'%a, %d %b %Y %H:%M:%S',
|
||||||
time.localtime(now)) + tzoffset
|
time.localtime(now)) + tzoffset
|
||||||
|
|
|
@ -231,7 +231,7 @@ class ColNamesTests(unittest.TestCase):
|
||||||
|
|
||||||
sqlite.converters["FOO"] = lambda x: "[%s]" % x
|
sqlite.converters["FOO"] = lambda x: "[%s]" % x
|
||||||
sqlite.converters["BAR"] = 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"
|
sqlite.converters["B1B1"] = lambda x: "MARKER"
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
@ -38,7 +38,7 @@ def func_returnnull():
|
||||||
def func_returnblob():
|
def func_returnblob():
|
||||||
return buffer("blob")
|
return buffer("blob")
|
||||||
def func_raiseexception():
|
def func_raiseexception():
|
||||||
5/0
|
5 // 0
|
||||||
|
|
||||||
def func_isstring(v):
|
def func_isstring(v):
|
||||||
return type(v) is unicode
|
return type(v) is unicode
|
||||||
|
@ -67,7 +67,7 @@ class AggrNoFinalize:
|
||||||
|
|
||||||
class AggrExceptionInInit:
|
class AggrExceptionInInit:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
5/0
|
5 // 0
|
||||||
|
|
||||||
def step(self, x):
|
def step(self, x):
|
||||||
pass
|
pass
|
||||||
|
@ -80,7 +80,7 @@ class AggrExceptionInStep:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def step(self, x):
|
def step(self, x):
|
||||||
5/0
|
5 // 0
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
return 42
|
return 42
|
||||||
|
@ -93,7 +93,7 @@ class AggrExceptionInFinalize:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
5/0
|
5 // 0
|
||||||
|
|
||||||
class AggrCheckType:
|
class AggrCheckType:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
# reload()ing. This module is imported by test_import.py:test_infinite_reload
|
# reload()ing. This module is imported by test_import.py:test_infinite_reload
|
||||||
# to make sure this doesn't happen any more.
|
# to make sure this doesn't happen any more.
|
||||||
|
|
||||||
|
import imp
|
||||||
import infinite_reload
|
import infinite_reload
|
||||||
reload(infinite_reload)
|
imp.reload(infinite_reload)
|
||||||
|
|
|
@ -15,7 +15,7 @@ def eggs(x, y):
|
||||||
fr = inspect.currentframe()
|
fr = inspect.currentframe()
|
||||||
st = inspect.stack()
|
st = inspect.stack()
|
||||||
p = x
|
p = x
|
||||||
q = y / 0
|
q = y // 0
|
||||||
|
|
||||||
# line 20
|
# line 20
|
||||||
class StupidGit:
|
class StupidGit:
|
||||||
|
|
|
@ -159,6 +159,7 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
import unittest
|
import unittest
|
||||||
|
import imp
|
||||||
|
|
||||||
|
|
||||||
# Ignore ImportWarnings that only occur in the source tree,
|
# Ignore ImportWarnings that only occur in the source tree,
|
||||||
|
@ -955,7 +956,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
indirect_test()
|
indirect_test()
|
||||||
else:
|
else:
|
||||||
def run_the_test():
|
def run_the_test():
|
||||||
reload(the_module)
|
imp.reload(the_module)
|
||||||
|
|
||||||
deltas = []
|
deltas = []
|
||||||
nwarmup, ntracked, fname = huntrleaks
|
nwarmup, ntracked, fname = huntrleaks
|
||||||
|
|
|
@ -207,6 +207,9 @@ class Rat(object):
|
||||||
"""Compare two Rats for inequality."""
|
"""Compare two Rats for inequality."""
|
||||||
return not self == other
|
return not self == other
|
||||||
|
|
||||||
|
# Silence Py3k warning
|
||||||
|
__hash__ = None
|
||||||
|
|
||||||
class RatTestCase(unittest.TestCase):
|
class RatTestCase(unittest.TestCase):
|
||||||
"""Unit tests for Rat class and its support utilities."""
|
"""Unit tests for Rat class and its support utilities."""
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TestPendingCalls(unittest.TestCase):
|
||||||
context = foo()
|
context = foo()
|
||||||
context.l = []
|
context.l = []
|
||||||
context.n = 2 #submits per thread
|
context.n = 2 #submits per thread
|
||||||
context.nThreads = n / context.n
|
context.nThreads = n // context.n
|
||||||
context.nFinished = 0
|
context.nFinished = 0
|
||||||
context.lock = threading.Lock()
|
context.lock = threading.Lock()
|
||||||
context.event = threading.Event()
|
context.event = threading.Event()
|
||||||
|
|
|
@ -75,7 +75,7 @@ class CompilerTest(unittest.TestCase):
|
||||||
|
|
||||||
def testTryExceptFinally(self):
|
def testTryExceptFinally(self):
|
||||||
# Test that except and finally clauses in one try stmt are recognized
|
# 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")
|
"<string>", "exec")
|
||||||
dct = {}
|
dct = {}
|
||||||
exec c in dct
|
exec c in dct
|
||||||
|
|
|
@ -661,7 +661,7 @@ class TestCopy(unittest.TestCase):
|
||||||
v = copy.deepcopy(u)
|
v = copy.deepcopy(u)
|
||||||
self.assertNotEqual(v, u)
|
self.assertNotEqual(v, u)
|
||||||
self.assertEqual(len(v), 2)
|
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 pair: pair[0].i)
|
||||||
self.assertFalse(x is a)
|
self.assertFalse(x is a)
|
||||||
self.assertEqual(x.i, a.i)
|
self.assertEqual(x.i, a.i)
|
||||||
self.assertTrue(y is b)
|
self.assertTrue(y is b)
|
||||||
|
|
|
@ -66,7 +66,7 @@ dictionaries, such as the locals/globals dictionaries for the exec
|
||||||
statement or the built-in function eval():
|
statement or the built-in function eval():
|
||||||
|
|
||||||
>>> def sorted(seq):
|
>>> def sorted(seq):
|
||||||
... seq.sort()
|
... seq.sort(key=str)
|
||||||
... return seq
|
... return seq
|
||||||
>>> print sorted(a.keys())
|
>>> print sorted(a.keys())
|
||||||
[1, 2]
|
[1, 2]
|
||||||
|
|
|
@ -127,7 +127,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
self.assertEquals(self.f.__exit__(None, None, None), None)
|
self.assertEquals(self.f.__exit__(None, None, None), None)
|
||||||
# it must also return None if an exception was given
|
# it must also return None if an exception was given
|
||||||
try:
|
try:
|
||||||
1/0
|
1 // 0
|
||||||
except:
|
except:
|
||||||
self.assertEquals(self.f.__exit__(*sys.exc_info()), None)
|
self.assertEquals(self.f.__exit__(*sys.exc_info()), None)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,9 @@ class DummyFloat(object):
|
||||||
assert False, "__sub__ should not be invoked for comparisons"
|
assert False, "__sub__ should not be invoked for comparisons"
|
||||||
__rsub__ = __sub__
|
__rsub__ = __sub__
|
||||||
|
|
||||||
|
# Silence Py3k warning
|
||||||
|
__hash__ = None
|
||||||
|
|
||||||
|
|
||||||
class DummyRational(object):
|
class DummyRational(object):
|
||||||
"""Test comparison of Fraction with a naive rational implementation."""
|
"""Test comparison of Fraction with a naive rational implementation."""
|
||||||
|
@ -76,6 +79,10 @@ class DummyRational(object):
|
||||||
def __float__(self):
|
def __float__(self):
|
||||||
assert False, "__float__ should not be invoked"
|
assert False, "__float__ should not be invoked"
|
||||||
|
|
||||||
|
# Silence Py3k warning
|
||||||
|
__hash__ = None
|
||||||
|
|
||||||
|
|
||||||
class GcdTest(unittest.TestCase):
|
class GcdTest(unittest.TestCase):
|
||||||
|
|
||||||
def testMisc(self):
|
def testMisc(self):
|
||||||
|
|
|
@ -100,7 +100,8 @@ class DummyFTPHandler(asynchat.async_chat):
|
||||||
sock.listen(5)
|
sock.listen(5)
|
||||||
sock.settimeout(2)
|
sock.settimeout(2)
|
||||||
ip, port = sock.getsockname()[: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))
|
self.push('227 entering passive mode (%s,%d,%d)' %(ip, p1, p2))
|
||||||
conn, addr = sock.accept()
|
conn, addr = sock.accept()
|
||||||
self.dtp = self.dtp_handler(conn, baseclass=self)
|
self.dtp = self.dtp_handler(conn, baseclass=self)
|
||||||
|
|
|
@ -116,7 +116,7 @@ class TestPartial(unittest.TestCase):
|
||||||
|
|
||||||
def test_error_propagation(self):
|
def test_error_propagation(self):
|
||||||
def f(x, y):
|
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)
|
self.assertRaises(ZeroDivisionError, self.thetype(f, 1), 0)
|
||||||
self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
|
self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
|
||||||
|
|
|
@ -246,11 +246,11 @@ class TestGzip(unittest.TestCase):
|
||||||
self.fail("__enter__ on a closed file didn't raise an exception")
|
self.fail("__enter__ on a closed file didn't raise an exception")
|
||||||
try:
|
try:
|
||||||
with gzip.GzipFile(self.filename, "wb") as f:
|
with gzip.GzipFile(self.filename, "wb") as f:
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
pass
|
pass
|
||||||
else:
|
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):
|
def test_zero_padded_file(self):
|
||||||
with gzip.GzipFile(self.filename, "wb") as f:
|
with gzip.GzipFile(self.filename, "wb") as f:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
import py_compile
|
import py_compile
|
||||||
import warnings
|
import warnings
|
||||||
import marshal
|
import marshal
|
||||||
|
import imp
|
||||||
from test.test_support import (unlink, TESTFN, unload, run_unittest,
|
from test.test_support import (unlink, TESTFN, unload, run_unittest,
|
||||||
check_warnings, TestFailed, EnvironmentVarGuard)
|
check_warnings, TestFailed, EnvironmentVarGuard)
|
||||||
|
|
||||||
|
@ -56,11 +57,10 @@ class ImportTest(unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
mod = __import__(TESTFN)
|
||||||
mod = __import__(TESTFN)
|
except ImportError, err:
|
||||||
except ImportError, err:
|
self.fail("import from %s failed: %s" % (ext, err))
|
||||||
self.fail("import from %s failed: %s" % (ext, err))
|
else:
|
||||||
|
|
||||||
self.assertEquals(mod.a, a,
|
self.assertEquals(mod.a, a,
|
||||||
"module loaded (%s) but contents invalid" % mod)
|
"module loaded (%s) but contents invalid" % mod)
|
||||||
self.assertEquals(mod.b, b,
|
self.assertEquals(mod.b, b,
|
||||||
|
@ -69,10 +69,9 @@ class ImportTest(unittest.TestCase):
|
||||||
os.unlink(source)
|
os.unlink(source)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
imp.reload(mod)
|
||||||
reload(mod)
|
except ImportError, err:
|
||||||
except ImportError, err:
|
self.fail("import from .pyc/.pyo failed: %s" % err)
|
||||||
self.fail("import from .pyc/.pyo failed: %s" % err)
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
os.unlink(pyc)
|
os.unlink(pyc)
|
||||||
|
@ -121,7 +120,7 @@ class ImportTest(unittest.TestCase):
|
||||||
|
|
||||||
def testImpModule(self):
|
def testImpModule(self):
|
||||||
# Verify that the imp module can correctly load and find .py files
|
# Verify that the imp module can correctly load and find .py files
|
||||||
import imp, os
|
|
||||||
# XXX (ncoghlan): It would be nice to use test_support.CleanImport
|
# XXX (ncoghlan): It would be nice to use test_support.CleanImport
|
||||||
# here, but that breaks because the os module registers some
|
# here, but that breaks because the os module registers some
|
||||||
# handlers in copy_reg on import. Since CleanImport doesn't
|
# handlers in copy_reg on import. Since CleanImport doesn't
|
||||||
|
@ -172,7 +171,7 @@ class ImportTest(unittest.TestCase):
|
||||||
def test_failing_import_sticks(self):
|
def test_failing_import_sticks(self):
|
||||||
source = TESTFN + os.extsep + "py"
|
source = TESTFN + os.extsep + "py"
|
||||||
f = open(source, "w")
|
f = open(source, "w")
|
||||||
print >> f, "a = 1/0"
|
print >> f, "a = 1 // 0"
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# New in 2.4, we shouldn't be able to import that no matter how often
|
# New in 2.4, we shouldn't be able to import that no matter how often
|
||||||
|
@ -218,7 +217,7 @@ class ImportTest(unittest.TestCase):
|
||||||
print >> f, "b = 20//0"
|
print >> f, "b = 20//0"
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.assertRaises(ZeroDivisionError, reload, mod)
|
self.assertRaises(ZeroDivisionError, imp.reload, mod)
|
||||||
|
|
||||||
# But we still expect the module to be in sys.modules.
|
# But we still expect the module to be in sys.modules.
|
||||||
mod = sys.modules.get(TESTFN)
|
mod = sys.modules.get(TESTFN)
|
||||||
|
|
|
@ -387,11 +387,11 @@ class IOTest(unittest.TestCase):
|
||||||
f = None
|
f = None
|
||||||
try:
|
try:
|
||||||
with self.open(support.TESTFN, "wb", bufsize) as f:
|
with self.open(support.TESTFN, "wb", bufsize) as f:
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
self.assertEqual(f.closed, True)
|
self.assertEqual(f.closed, True)
|
||||||
else:
|
else:
|
||||||
self.fail("1/0 didn't raise an exception")
|
self.fail("1 // 0 didn't raise an exception")
|
||||||
|
|
||||||
# issue 5008
|
# issue 5008
|
||||||
def test_append_mode_tell(self):
|
def test_append_mode_tell(self):
|
||||||
|
|
|
@ -9,6 +9,7 @@ import operator
|
||||||
import random
|
import random
|
||||||
import copy
|
import copy
|
||||||
import pickle
|
import pickle
|
||||||
|
from functools import reduce
|
||||||
maxsize = test_support.MAX_Py_ssize_t
|
maxsize = test_support.MAX_Py_ssize_t
|
||||||
minsize = -maxsize-1
|
minsize = -maxsize-1
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ class TestBasicOps(unittest.TestCase):
|
||||||
values = [5*x-12 for x in range(n)]
|
values = [5*x-12 for x in range(n)]
|
||||||
for r in range(n+2):
|
for r in range(n+2):
|
||||||
result = list(combinations(values, r))
|
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(len(result), len(set(result))) # no repeats
|
||||||
self.assertEqual(result, sorted(result)) # lexicographic order
|
self.assertEqual(result, sorted(result)) # lexicographic order
|
||||||
for c in result:
|
for c in result:
|
||||||
|
@ -178,7 +179,7 @@ class TestBasicOps(unittest.TestCase):
|
||||||
def numcombs(n, r):
|
def numcombs(n, r):
|
||||||
if not n:
|
if not n:
|
||||||
return 0 if r else 1
|
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):
|
for n in range(7):
|
||||||
values = [5*x-12 for x in range(n)]
|
values = [5*x-12 for x in range(n)]
|
||||||
|
@ -257,7 +258,7 @@ class TestBasicOps(unittest.TestCase):
|
||||||
values = [5*x-12 for x in range(n)]
|
values = [5*x-12 for x in range(n)]
|
||||||
for r in range(n+2):
|
for r in range(n+2):
|
||||||
result = list(permutations(values, r))
|
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(len(result), len(set(result))) # no repeats
|
||||||
self.assertEqual(result, sorted(result)) # lexicographic order
|
self.assertEqual(result, sorted(result)) # lexicographic order
|
||||||
for p in result:
|
for p in result:
|
||||||
|
@ -288,9 +289,9 @@ class TestBasicOps(unittest.TestCase):
|
||||||
|
|
||||||
# Check size
|
# Check size
|
||||||
self.assertEquals(len(prod), n**r)
|
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(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(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(comb), 0 if r>n else fact(n) // fact(r) // fact(n-r))
|
||||||
|
|
||||||
# Check lexicographic order without repeated tuples
|
# Check lexicographic order without repeated tuples
|
||||||
self.assertEquals(prod, sorted(set(prod)))
|
self.assertEquals(prod, sorted(set(prod)))
|
||||||
|
@ -543,7 +544,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(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)],
|
[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)
|
||||||
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'
|
target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
|
||||||
|
@ -555,7 +559,8 @@ class TestBasicOps(unittest.TestCase):
|
||||||
self.assertEqual(list(izip_longest([])), zip([]))
|
self.assertEqual(list(izip_longest([])), zip([]))
|
||||||
self.assertEqual(list(izip_longest('abcdef')), zip('abcdef'))
|
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, 3)
|
||||||
self.assertRaises(TypeError, izip_longest, range(3), 3)
|
self.assertRaises(TypeError, izip_longest, range(3), 3)
|
||||||
|
|
||||||
|
@ -1431,7 +1436,7 @@ Samuele
|
||||||
# is differencing with a range so that consecutive numbers all appear in
|
# is differencing with a range so that consecutive numbers all appear in
|
||||||
# same group.
|
# same group.
|
||||||
>>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
|
>>> 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)
|
... print map(operator.itemgetter(1), g)
|
||||||
...
|
...
|
||||||
[1]
|
[1]
|
||||||
|
|
|
@ -307,7 +307,7 @@ class TestBase_Mapping(unittest.TestCase):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
unich = unichrs(data[1])
|
unich = unichrs(data[1])
|
||||||
if ord(unich) == 0xfffd or urt_wa.has_key(unich):
|
if ord(unich) == 0xfffd or unich in urt_wa:
|
||||||
continue
|
continue
|
||||||
urt_wa[unich] = csetch
|
urt_wa[unich] = csetch
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ class Machiavelli:
|
||||||
# Tim sez: "luck of the draw; crashes with or without for me."
|
# Tim sez: "luck of the draw; crashes with or without for me."
|
||||||
print >> f
|
print >> f
|
||||||
|
|
||||||
return `"machiavelli"`
|
return repr("machiavelli")
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -26,12 +26,6 @@ from optparse import make_option, Option, IndentedHelpFormatter, \
|
||||||
from optparse import _match_abbrev
|
from optparse import _match_abbrev
|
||||||
from optparse import _parse_num
|
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(''))
|
retype = type(re.compile(''))
|
||||||
|
|
||||||
class InterceptedError(Exception):
|
class InterceptedError(Exception):
|
||||||
|
|
|
@ -45,7 +45,8 @@ class OSSAudioDevTests(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
dsp = ossaudiodev.open('w')
|
dsp = ossaudiodev.open('w')
|
||||||
except IOError, msg:
|
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 unittest.SkipTest(msg)
|
raise unittest.SkipTest(msg)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ class OSSAudioDevTests(unittest.TestCase):
|
||||||
self.fail("dsp.%s not read-only" % attr)
|
self.fail("dsp.%s not read-only" % attr)
|
||||||
|
|
||||||
# Compute expected running time of sound sample (in seconds).
|
# 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
|
# set parameters based on .au file headers
|
||||||
dsp.setparameters(AFMT_S16_NE, nchannels, rate)
|
dsp.setparameters(AFMT_S16_NE, nchannels, rate)
|
||||||
|
@ -162,7 +163,8 @@ def test_main():
|
||||||
try:
|
try:
|
||||||
dsp = ossaudiodev.open('w')
|
dsp = ossaudiodev.open('w')
|
||||||
except (ossaudiodev.error, IOError), msg:
|
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 unittest.SkipTest(msg)
|
raise unittest.SkipTest(msg)
|
||||||
raise
|
raise
|
||||||
dsp.close()
|
dsp.close()
|
||||||
|
|
|
@ -6,14 +6,14 @@ class TestImport(unittest.TestCase):
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
self.package_name = 'PACKAGE_'
|
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.package_name += random.choose(string.letters)
|
||||||
self.module_name = self.package_name + '.foo'
|
self.module_name = self.package_name + '.foo'
|
||||||
unittest.TestCase.__init__(self, *args, **kw)
|
unittest.TestCase.__init__(self, *args, **kw)
|
||||||
|
|
||||||
def remove_modules(self):
|
def remove_modules(self):
|
||||||
for module_name in (self.package_name, self.module_name):
|
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]
|
del sys.modules[module_name]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -52,8 +52,8 @@ class TestImport(unittest.TestCase):
|
||||||
try: __import__(self.module_name)
|
try: __import__(self.module_name)
|
||||||
except SyntaxError: pass
|
except SyntaxError: pass
|
||||||
else: raise RuntimeError, 'Failed to induce SyntaxError'
|
else: raise RuntimeError, 'Failed to induce SyntaxError'
|
||||||
self.assertTrue(not sys.modules.has_key(self.module_name) and
|
self.assertNotIn(self.module_name, sys.modules)
|
||||||
not hasattr(sys.modules[self.package_name], 'foo'))
|
self.assertFalse(hasattr(sys.modules[self.package_name], 'foo'))
|
||||||
|
|
||||||
# ...make up a variable name that isn't bound in __builtins__
|
# ...make up a variable name that isn't bound in __builtins__
|
||||||
var = 'a'
|
var = 'a'
|
||||||
|
|
|
@ -554,7 +554,7 @@ class ChardataBufferTest(unittest.TestCase):
|
||||||
|
|
||||||
self.n=0
|
self.n=0
|
||||||
parser.Parse(xml1, 0)
|
parser.Parse(xml1, 0)
|
||||||
parser.buffer_size /= 2
|
parser.buffer_size //= 2
|
||||||
self.assertEquals(parser.buffer_size, 1024)
|
self.assertEquals(parser.buffer_size, 1024)
|
||||||
parser.Parse(xml2, 1)
|
parser.Parse(xml2, 1)
|
||||||
self.assertEquals(self.n, 4)
|
self.assertEquals(self.n, 4)
|
||||||
|
|
|
@ -102,21 +102,23 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
q.put(i)
|
q.put(i)
|
||||||
self.assertTrue(not q.empty(), "Queue should not be empty")
|
self.assertTrue(not q.empty(), "Queue should not be empty")
|
||||||
self.assertTrue(not q.full(), "Queue should not be full")
|
self.assertTrue(not q.full(), "Queue should not be full")
|
||||||
q.put("last")
|
last = 2 * QUEUE_SIZE
|
||||||
|
full = 3 * 2 * QUEUE_SIZE
|
||||||
|
q.put(last)
|
||||||
self.assertTrue(q.full(), "Queue should be full")
|
self.assertTrue(q.full(), "Queue should be full")
|
||||||
try:
|
try:
|
||||||
q.put("full", block=0)
|
q.put(full, block=0)
|
||||||
self.fail("Didn't appear to block with a full queue")
|
self.fail("Didn't appear to block with a full queue")
|
||||||
except Queue.Full:
|
except Queue.Full:
|
||||||
pass
|
pass
|
||||||
try:
|
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")
|
self.fail("Didn't appear to time-out with a full queue")
|
||||||
except Queue.Full:
|
except Queue.Full:
|
||||||
pass
|
pass
|
||||||
# Test a blocking put
|
# Test a blocking put
|
||||||
self.do_blocking_test(q.put, ("full",), q.get, ())
|
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, True, 10), q.get, ())
|
||||||
# Empty it
|
# Empty it
|
||||||
for i in range(QUEUE_SIZE):
|
for i in range(QUEUE_SIZE):
|
||||||
q.get()
|
q.get()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import time
|
||||||
import pickle
|
import pickle
|
||||||
import warnings
|
import warnings
|
||||||
from math import log, exp, sqrt, pi, fsum, sin
|
from math import log, exp, sqrt, pi, fsum, sin
|
||||||
|
from functools import reduce
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
class TestBasicOps(unittest.TestCase):
|
class TestBasicOps(unittest.TestCase):
|
||||||
|
|
|
@ -46,9 +46,9 @@ class MessageTestCase(unittest.TestCase):
|
||||||
continue
|
continue
|
||||||
i = i + 1
|
i = i + 1
|
||||||
self.assertEqual(mn, n,
|
self.assertEqual(mn, n,
|
||||||
"Un-expected name: %s != %s" % (`mn`, `n`))
|
"Un-expected name: %r != %r" % (mn, n))
|
||||||
self.assertEqual(ma, a,
|
self.assertEqual(ma, a,
|
||||||
"Un-expected address: %s != %s" % (`ma`, `a`))
|
"Un-expected address: %r != %r" % (ma, a))
|
||||||
if mn == n and ma == a:
|
if mn == n and ma == a:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -266,7 +266,7 @@ class ImportSideEffectTests(unittest.TestCase):
|
||||||
site.abs__file__()
|
site.abs__file__()
|
||||||
for module in (sys, os, __builtin__):
|
for module in (sys, os, __builtin__):
|
||||||
try:
|
try:
|
||||||
self.assertTrue(os.path.isabs(module.__file__), `module`)
|
self.assertTrue(os.path.isabs(module.__file__), repr(module))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
# We could try everything in sys.modules; however, when regrtest.py
|
# We could try everything in sys.modules; however, when regrtest.py
|
||||||
|
@ -318,7 +318,7 @@ class ImportSideEffectTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_sitecustomize_executed(self):
|
def test_sitecustomize_executed(self):
|
||||||
# If sitecustomize is available, it should have been imported.
|
# If sitecustomize is available, it should have been imported.
|
||||||
if not sys.modules.has_key("sitecustomize"):
|
if "sitecustomize" not in sys.modules:
|
||||||
try:
|
try:
|
||||||
import sitecustomize
|
import sitecustomize
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
|
@ -14,7 +14,7 @@ process_pid = os.getpid()
|
||||||
signalled_all=thread.allocate_lock()
|
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)
|
usr1 = signal.signal(signal.SIGUSR1, for_usr1)
|
||||||
usr2 = signal.signal(signal.SIGUSR2, for_usr2)
|
usr2 = signal.signal(signal.SIGUSR2, for_usr2)
|
||||||
alrm = signal.signal(signal.SIGALRM, for_alrm)
|
alrm = signal.signal(signal.SIGALRM, for_alrm)
|
||||||
|
@ -74,11 +74,11 @@ def test_main():
|
||||||
signal.SIGUSR2 : {'tripped': 0, 'tripped_by': 0 },
|
signal.SIGUSR2 : {'tripped': 0, 'tripped_by': 0 },
|
||||||
signal.SIGALRM : {'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:
|
try:
|
||||||
run_unittest(ThreadSignals)
|
run_unittest(ThreadSignals)
|
||||||
finally:
|
finally:
|
||||||
registerSignals(oldsigs)
|
registerSignals(*oldsigs)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -401,7 +401,7 @@ class RaisingTraceFuncTestCase(unittest.TestCase):
|
||||||
we're testing, so that the 'exception' trace event fires."""
|
we're testing, so that the 'exception' trace event fires."""
|
||||||
if self.raiseOnEvent == 'exception':
|
if self.raiseOnEvent == 'exception':
|
||||||
x = 0
|
x = 0
|
||||||
y = 1/x
|
y = 1 // x
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from _testcapi import traceback_print
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
from imp import reload
|
||||||
from test.test_support import run_unittest, is_jython, Error
|
from test.test_support import run_unittest, is_jython, Error
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -148,7 +149,7 @@ def test():
|
||||||
def test_format_exception_only_bad__str__(self):
|
def test_format_exception_only_bad__str__(self):
|
||||||
class X(Exception):
|
class X(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
1/0
|
1 // 0
|
||||||
err = traceback.format_exception_only(X, X())
|
err = traceback.format_exception_only(X, X())
|
||||||
self.assertEqual(len(err), 1)
|
self.assertEqual(len(err), 1)
|
||||||
str_value = '<unprintable %s object>' % X.__name__
|
str_value = '<unprintable %s object>' % X.__name__
|
||||||
|
|
|
@ -520,7 +520,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
||||||
self.assertRaises(AssertionError, falseAsBool)
|
self.assertRaises(AssertionError, falseAsBool)
|
||||||
|
|
||||||
def failAsBool():
|
def failAsBool():
|
||||||
with cm(lambda: 1//0):
|
with cm(lambda: 1 // 0):
|
||||||
self.fail("Should NOT see this")
|
self.fail("Should NOT see this")
|
||||||
self.assertRaises(ZeroDivisionError, failAsBool)
|
self.assertRaises(ZeroDivisionError, failAsBool)
|
||||||
|
|
||||||
|
@ -628,7 +628,7 @@ class ExitSwallowsExceptionTestCase(unittest.TestCase):
|
||||||
def __exit__(self, t, v, tb): return True
|
def __exit__(self, t, v, tb): return True
|
||||||
try:
|
try:
|
||||||
with AfricanSwallow():
|
with AfricanSwallow():
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
self.fail("ZeroDivisionError should have been swallowed")
|
self.fail("ZeroDivisionError should have been swallowed")
|
||||||
|
|
||||||
|
@ -638,7 +638,7 @@ class ExitSwallowsExceptionTestCase(unittest.TestCase):
|
||||||
def __exit__(self, t, v, tb): return False
|
def __exit__(self, t, v, tb): return False
|
||||||
try:
|
try:
|
||||||
with EuropeanSwallow():
|
with EuropeanSwallow():
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -432,10 +432,10 @@ class HandlerTests(TestCase):
|
||||||
env = handler.environ
|
env = handler.environ
|
||||||
from os import environ
|
from os import environ
|
||||||
for k,v in environ.items():
|
for k,v in environ.items():
|
||||||
if not empty.has_key(k):
|
if k not in empty:
|
||||||
self.assertEqual(env[k],v)
|
self.assertEqual(env[k],v)
|
||||||
for k,v in empty.items():
|
for k,v in empty.items():
|
||||||
self.assertTrue(env.has_key(k))
|
self.assertIn(k, env)
|
||||||
|
|
||||||
def testEnviron(self):
|
def testEnviron(self):
|
||||||
h = TestHandler(X="Y")
|
h = TestHandler(X="Y")
|
||||||
|
@ -448,7 +448,7 @@ class HandlerTests(TestCase):
|
||||||
h = BaseCGIHandler(None,None,None,{})
|
h = BaseCGIHandler(None,None,None,{})
|
||||||
h.setup_environ()
|
h.setup_environ()
|
||||||
for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors':
|
for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors':
|
||||||
self.assertTrue(h.environ.has_key(key))
|
self.assertIn(key, h.environ)
|
||||||
|
|
||||||
def testScheme(self):
|
def testScheme(self):
|
||||||
h=TestHandler(HTTPS="on"); h.setup_environ()
|
h=TestHandler(HTTPS="on"); h.setup_environ()
|
||||||
|
|
|
@ -37,7 +37,7 @@ def sanity():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def check_method(method):
|
def check_method(method):
|
||||||
if not callable(method):
|
if not hasattr(method, '__call__'):
|
||||||
print method, "not callable"
|
print method, "not callable"
|
||||||
|
|
||||||
def serialize(ET, elem, encoding=None):
|
def serialize(ET, elem, encoding=None):
|
||||||
|
|
|
@ -35,7 +35,7 @@ def sanity():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def check_method(method):
|
def check_method(method):
|
||||||
if not callable(method):
|
if not hasattr(method, '__call__'):
|
||||||
print method, "not callable"
|
print method, "not callable"
|
||||||
|
|
||||||
def serialize(ET, elem, encoding=None):
|
def serialize(ET, elem, encoding=None):
|
||||||
|
|
|
@ -25,7 +25,7 @@ from test import test_support
|
||||||
mod_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
mod_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||||
"pickletester.py"))
|
"pickletester.py"))
|
||||||
pickletester = types.ModuleType("test.pickletester")
|
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
|
AbstractPickleTests = pickletester.AbstractPickleTests
|
||||||
if pickletester.__name__ in sys.modules:
|
if pickletester.__name__ in sys.modules:
|
||||||
raise RuntimeError("Did not expect to find test.pickletester loaded")
|
raise RuntimeError("Did not expect to find test.pickletester loaded")
|
||||||
|
|
Loading…
Reference in New Issue