mirror of https://github.com/python/cpython
#7092: silence some more py3k warnings.
This commit is contained in:
parent
8b3f1ce591
commit
d80b4bfd0b
|
@ -24,7 +24,7 @@ class memoryview(object):
|
||||||
else:
|
else:
|
||||||
size = sizeof(ob)
|
size = sizeof(ob)
|
||||||
for dim in self.shape:
|
for dim in self.shape:
|
||||||
size /= dim
|
size //= dim
|
||||||
self.itemsize = size
|
self.itemsize = size
|
||||||
self.strides = None
|
self.strides = None
|
||||||
self.readonly = False
|
self.readonly = False
|
||||||
|
|
|
@ -660,11 +660,14 @@ class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
|
||||||
type2test = Dict
|
type2test = Dict
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(
|
with test_support.check_py3k_warnings(
|
||||||
DictTest,
|
('dict(.has_key..| inequality comparisons) not supported in 3.x',
|
||||||
GeneralMappingTests,
|
DeprecationWarning)):
|
||||||
SubclassMappingTests,
|
test_support.run_unittest(
|
||||||
)
|
DictTest,
|
||||||
|
GeneralMappingTests,
|
||||||
|
SubclassMappingTests,
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -34,13 +34,15 @@ class AutoFileTests(unittest.TestCase):
|
||||||
def testAttributes(self):
|
def testAttributes(self):
|
||||||
# verify expected attributes exist
|
# verify expected attributes exist
|
||||||
f = self.f
|
f = self.f
|
||||||
softspace = f.softspace
|
with test_support.check_py3k_warnings():
|
||||||
|
softspace = f.softspace
|
||||||
f.name # merely shouldn't blow up
|
f.name # merely shouldn't blow up
|
||||||
f.mode # ditto
|
f.mode # ditto
|
||||||
f.closed # ditto
|
f.closed # ditto
|
||||||
|
|
||||||
# verify softspace is writable
|
with test_support.check_py3k_warnings():
|
||||||
f.softspace = softspace # merely shouldn't blow up
|
# verify softspace is writable
|
||||||
|
f.softspace = softspace # merely shouldn't blow up
|
||||||
|
|
||||||
# verify the others aren't
|
# verify the others aren't
|
||||||
for attr in 'name', 'mode', 'closed':
|
for attr in 'name', 'mode', 'closed':
|
||||||
|
@ -100,7 +102,8 @@ class AutoFileTests(unittest.TestCase):
|
||||||
def testMethods(self):
|
def testMethods(self):
|
||||||
methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
|
methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
|
||||||
'readline', 'readlines', 'seek', 'tell', 'truncate',
|
'readline', 'readlines', 'seek', 'tell', 'truncate',
|
||||||
'write', 'xreadlines', '__iter__']
|
'write', '__iter__']
|
||||||
|
deprecated_methods = ['xreadlines']
|
||||||
if sys.platform.startswith('atheos'):
|
if sys.platform.startswith('atheos'):
|
||||||
methods.remove('truncate')
|
methods.remove('truncate')
|
||||||
|
|
||||||
|
@ -112,13 +115,17 @@ class AutoFileTests(unittest.TestCase):
|
||||||
method = getattr(self.f, methodname)
|
method = getattr(self.f, methodname)
|
||||||
# should raise on closed file
|
# should raise on closed file
|
||||||
self.assertRaises(ValueError, method)
|
self.assertRaises(ValueError, method)
|
||||||
|
with test_support.check_py3k_warnings():
|
||||||
|
for methodname in deprecated_methods:
|
||||||
|
method = getattr(self.f, methodname)
|
||||||
|
self.assertRaises(ValueError, method)
|
||||||
self.assertRaises(ValueError, self.f.writelines, [])
|
self.assertRaises(ValueError, self.f.writelines, [])
|
||||||
|
|
||||||
# file is closed, __exit__ shouldn't do anything
|
# file is closed, __exit__ shouldn't do anything
|
||||||
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)
|
||||||
|
|
||||||
|
@ -218,12 +225,12 @@ class OtherFileTests(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
f = open(TESTFN, bad_mode)
|
f = open(TESTFN, bad_mode)
|
||||||
except ValueError, msg:
|
except ValueError, msg:
|
||||||
if msg[0] != 0:
|
if msg.args[0] != 0:
|
||||||
s = str(msg)
|
s = str(msg)
|
||||||
if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
|
if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
|
||||||
self.fail("bad error message for invalid mode: %s" % s)
|
self.fail("bad error message for invalid mode: %s" % s)
|
||||||
# if msg[0] == 0, we're probably on Windows where there may be
|
# if msg.args[0] == 0, we're probably on Windows where there may
|
||||||
# no obvious way to discover why open() failed.
|
# be no obvious way to discover why open() failed.
|
||||||
else:
|
else:
|
||||||
f.close()
|
f.close()
|
||||||
self.fail("no error for invalid mode: %s" % bad_mode)
|
self.fail("no error for invalid mode: %s" % bad_mode)
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
# regression test, the filterwarnings() call has been added to
|
# regression test, the filterwarnings() call has been added to
|
||||||
# regrtest.py.
|
# 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 unittest
|
||||||
import sys
|
import sys
|
||||||
# testing import *
|
# testing import *
|
||||||
|
@ -152,8 +153,9 @@ class GrammarTests(unittest.TestCase):
|
||||||
f1(*(), **{})
|
f1(*(), **{})
|
||||||
def f2(one_argument): pass
|
def f2(one_argument): pass
|
||||||
def f3(two, arguments): pass
|
def f3(two, arguments): pass
|
||||||
def f4(two, (compound, (argument, list))): pass
|
# Silence Py3k warning
|
||||||
def f5((compound, first), two): pass
|
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(f2.func_code.co_varnames, ('one_argument',))
|
||||||
self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments'))
|
self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments'))
|
||||||
if sys.platform.startswith('java'):
|
if sys.platform.startswith('java'):
|
||||||
|
@ -172,7 +174,8 @@ class GrammarTests(unittest.TestCase):
|
||||||
def v0(*rest): pass
|
def v0(*rest): pass
|
||||||
def v1(a, *rest): pass
|
def v1(a, *rest): pass
|
||||||
def v2(a, b, *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()
|
f1()
|
||||||
f2(1)
|
f2(1)
|
||||||
|
@ -277,9 +280,10 @@ class GrammarTests(unittest.TestCase):
|
||||||
d22v(*(1, 2, 3, 4))
|
d22v(*(1, 2, 3, 4))
|
||||||
d22v(1, 2, *(3, 4, 5))
|
d22v(1, 2, *(3, 4, 5))
|
||||||
d22v(1, *(2, 3), **{'d': 4})
|
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)
|
d31v(1)
|
||||||
def d32v((x,)): pass
|
|
||||||
d32v((1,))
|
d32v((1,))
|
||||||
|
|
||||||
# keyword arguments after *arglist
|
# keyword arguments after *arglist
|
||||||
|
@ -474,7 +478,7 @@ hello world
|
||||||
continue
|
continue
|
||||||
except:
|
except:
|
||||||
raise
|
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!")
|
self.fail("continue then break in try/except in loop broken!")
|
||||||
test_inner()
|
test_inner()
|
||||||
|
|
||||||
|
@ -536,7 +540,7 @@ hello world
|
||||||
if z != 2: self.fail('exec u\'z=1+1\'')"""
|
if z != 2: self.fail('exec u\'z=1+1\'')"""
|
||||||
g = {}
|
g = {}
|
||||||
exec 'z = 1' in 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')
|
if g != {'z': 1}: self.fail('exec \'z = 1\' in g')
|
||||||
g = {}
|
g = {}
|
||||||
l = {}
|
l = {}
|
||||||
|
@ -544,8 +548,8 @@ hello world
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings("ignore", "global statement", module="<string>")
|
warnings.filterwarnings("ignore", "global statement", module="<string>")
|
||||||
exec 'global a; a = 1; b = 2' in g, l
|
exec 'global a; a = 1; b = 2' in g, l
|
||||||
if g.has_key('__builtins__'): del g['__builtins__']
|
if '__builtins__' in g: del g['__builtins__']
|
||||||
if l.has_key('__builtins__'): del l['__builtins__']
|
if '__builtins__' in l: del l['__builtins__']
|
||||||
if (g, l) != ({'a':1}, {'b':2}):
|
if (g, l) != ({'a':1}, {'b':2}):
|
||||||
self.fail('exec ... in g (%s), l (%s)' %(g,l))
|
self.fail('exec ... in g (%s), l (%s)' %(g,l))
|
||||||
|
|
||||||
|
@ -677,7 +681,6 @@ hello world
|
||||||
x = (1 == 1)
|
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
|
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 is not 1: pass
|
||||||
if 1 in (): pass
|
if 1 in (): pass
|
||||||
if 1 not 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):
|
def testBinaryMaskOps(self):
|
||||||
x = 1 & 1
|
x = 1 & 1
|
||||||
|
@ -774,9 +780,10 @@ hello world
|
||||||
x = {'one', 'two', 'three'}
|
x = {'one', 'two', 'three'}
|
||||||
x = {2, 3, 4,}
|
x = {2, 3, 4,}
|
||||||
|
|
||||||
x = `x`
|
# Silence Py3k warning
|
||||||
x = `1 or 2 or 3`
|
x = eval('`x`')
|
||||||
self.assertEqual(`1,2`, '(1, 2)')
|
x = eval('`1 or 2 or 3`')
|
||||||
|
self.assertEqual(eval('`1,2`'), '(1, 2)')
|
||||||
|
|
||||||
x = x
|
x = x
|
||||||
x = 'x'
|
x = 'x'
|
||||||
|
@ -988,7 +995,13 @@ hello world
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
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__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -180,7 +180,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
|
||||||
self.assertFalse(hasattr(reloadmodule,'reloaded'))
|
self.assertFalse(hasattr(reloadmodule,'reloaded'))
|
||||||
|
|
||||||
TestImporter.modules['reloadmodule'] = (False, reload_co)
|
TestImporter.modules['reloadmodule'] = (False, reload_co)
|
||||||
reload(reloadmodule)
|
imp.reload(reloadmodule)
|
||||||
self.assertTrue(hasattr(reloadmodule,'reloaded'))
|
self.assertTrue(hasattr(reloadmodule,'reloaded'))
|
||||||
|
|
||||||
import hooktestpackage.oldabs
|
import hooktestpackage.oldabs
|
||||||
|
@ -247,9 +247,10 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
|
||||||
for n in sys.modules.keys():
|
for n in sys.modules.keys():
|
||||||
if n.startswith(parent):
|
if n.startswith(parent):
|
||||||
del sys.modules[n]
|
del sys.modules[n]
|
||||||
for mname in mnames:
|
with test_support.check_py3k_warnings():
|
||||||
m = __import__(mname, globals(), locals(), ["__dummy__"])
|
for mname in mnames:
|
||||||
m.__loader__ # to make sure we actually handled the import
|
m = __import__(mname, globals(), locals(), ["__dummy__"])
|
||||||
|
m.__loader__ # to make sure we actually handled the import
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Python test set -- part 2, opcodes
|
# 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
|
import unittest
|
||||||
|
|
||||||
class OpcodeTest(unittest.TestCase):
|
class OpcodeTest(unittest.TestCase):
|
||||||
|
@ -9,7 +9,7 @@ class OpcodeTest(unittest.TestCase):
|
||||||
n = 0
|
n = 0
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
n = n+i
|
n = n+i
|
||||||
try: 1/0
|
try: 1 // 0
|
||||||
except NameError: pass
|
except NameError: pass
|
||||||
except ZeroDivisionError: pass
|
except ZeroDivisionError: pass
|
||||||
except TypeError: pass
|
except TypeError: pass
|
||||||
|
@ -110,7 +110,12 @@ class OpcodeTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
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__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import unittest
|
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 as r # Don't shadow builtin repr
|
||||||
from repr import Repr
|
from repr import Repr
|
||||||
|
|
||||||
|
@ -174,7 +174,8 @@ class ReprTests(unittest.TestCase):
|
||||||
def test_buffer(self):
|
def test_buffer(self):
|
||||||
# XXX doesn't test buffers with no b_base or read-write buffers (see
|
# XXX doesn't test buffers with no b_base or read-write buffers (see
|
||||||
# bufferobject.c). The test is fairly incomplete too. Sigh.
|
# bufferobject.c). The test is fairly incomplete too. Sigh.
|
||||||
x = buffer('foo')
|
with check_py3k_warnings():
|
||||||
|
x = buffer('foo')
|
||||||
self.assertTrue(repr(x).startswith('<read-only buffer for 0x'))
|
self.assertTrue(repr(x).startswith('<read-only buffer for 0x'))
|
||||||
|
|
||||||
def test_cell(self):
|
def test_cell(self):
|
||||||
|
|
|
@ -1377,21 +1377,17 @@ class TestOnlySetsGenerator(TestOnlySetsInBinaryOps):
|
||||||
class TestCopying(unittest.TestCase):
|
class TestCopying(unittest.TestCase):
|
||||||
|
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
dup = self.set.copy()
|
dup = list(self.set.copy())
|
||||||
dup_list = list(dup); dup_list.sort()
|
self.assertEqual(len(dup), len(self.set))
|
||||||
set_list = list(self.set); set_list.sort()
|
for el in self.set:
|
||||||
self.assertEqual(len(dup_list), len(set_list))
|
self.assertIn(el, dup)
|
||||||
for i in range(len(dup_list)):
|
pos = dup.index(el)
|
||||||
self.assertTrue(dup_list[i] is set_list[i])
|
self.assertIs(el, dup.pop(pos))
|
||||||
|
self.assertFalse(dup)
|
||||||
|
|
||||||
def test_deep_copy(self):
|
def test_deep_copy(self):
|
||||||
dup = copy.deepcopy(self.set)
|
dup = copy.deepcopy(self.set)
|
||||||
##print type(dup), repr(dup)
|
self.assertSetEqual(dup, self.set)
|
||||||
dup_list = list(dup); dup_list.sort()
|
|
||||||
set_list = list(self.set); set_list.sort()
|
|
||||||
self.assertEqual(len(dup_list), len(set_list))
|
|
||||||
for i in range(len(dup_list)):
|
|
||||||
self.assertEqual(dup_list[i], set_list[i])
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1551,7 +1547,7 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
||||||
for cons in (set, frozenset):
|
for cons in (set, frozenset):
|
||||||
for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
|
for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
|
||||||
for g in (G, I, Ig, S, L, R):
|
for g in (G, I, Ig, S, L, R):
|
||||||
self.assertEqual(sorted(cons(g(s))), sorted(g(s)))
|
self.assertSetEqual(cons(g(s)), set(g(s)))
|
||||||
self.assertRaises(TypeError, cons , X(s))
|
self.assertRaises(TypeError, cons , X(s))
|
||||||
self.assertRaises(TypeError, cons , N(s))
|
self.assertRaises(TypeError, cons , N(s))
|
||||||
self.assertRaises(ZeroDivisionError, cons , E(s))
|
self.assertRaises(ZeroDivisionError, cons , E(s))
|
||||||
|
@ -1566,7 +1562,7 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
||||||
if isinstance(expected, bool):
|
if isinstance(expected, bool):
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
else:
|
else:
|
||||||
self.assertEqual(sorted(actual), sorted(expected))
|
self.assertSetEqual(actual, expected)
|
||||||
self.assertRaises(TypeError, meth, X(s))
|
self.assertRaises(TypeError, meth, X(s))
|
||||||
self.assertRaises(TypeError, meth, N(s))
|
self.assertRaises(TypeError, meth, N(s))
|
||||||
self.assertRaises(ZeroDivisionError, meth, E(s))
|
self.assertRaises(ZeroDivisionError, meth, E(s))
|
||||||
|
@ -1580,7 +1576,7 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
||||||
t = s.copy()
|
t = s.copy()
|
||||||
getattr(s, methname)(list(g(data)))
|
getattr(s, methname)(list(g(data)))
|
||||||
getattr(t, methname)(g(data))
|
getattr(t, methname)(g(data))
|
||||||
self.assertEqual(sorted(s), sorted(t))
|
self.assertSetEqual(s, t)
|
||||||
|
|
||||||
self.assertRaises(TypeError, getattr(set('january'), methname), X(data))
|
self.assertRaises(TypeError, getattr(set('january'), methname), X(data))
|
||||||
self.assertRaises(TypeError, getattr(set('january'), methname), N(data))
|
self.assertRaises(TypeError, getattr(set('january'), methname), N(data))
|
||||||
|
|
|
@ -79,7 +79,8 @@ class SysModuleTest(unittest.TestCase):
|
||||||
self.assertTrue(value is exc)
|
self.assertTrue(value is exc)
|
||||||
self.assertTrue(traceback is not None)
|
self.assertTrue(traceback is not None)
|
||||||
|
|
||||||
sys.exc_clear()
|
with test.test_support.check_py3k_warnings():
|
||||||
|
sys.exc_clear()
|
||||||
|
|
||||||
typ, value, traceback = sys.exc_info()
|
typ, value, traceback = sys.exc_info()
|
||||||
self.assertTrue(typ is None)
|
self.assertTrue(typ is None)
|
||||||
|
@ -521,7 +522,8 @@ class SizeofTest(unittest.TestCase):
|
||||||
# bool
|
# bool
|
||||||
check(True, size(h + 'l'))
|
check(True, size(h + 'l'))
|
||||||
# buffer
|
# buffer
|
||||||
check(buffer(''), size(h + '2P2Pil'))
|
with test.test_support.check_py3k_warnings():
|
||||||
|
check(buffer(''), size(h + '2P2Pil'))
|
||||||
# builtin_function_or_method
|
# builtin_function_or_method
|
||||||
check(len, size(h + '3P'))
|
check(len, size(h + '3P'))
|
||||||
# bytearray
|
# bytearray
|
||||||
|
|
Loading…
Reference in New Issue