Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
This commit is contained in:
parent
ad59833649
commit
6257a7bbb2
|
@ -4,7 +4,6 @@ import unittest
|
||||||
from test import test_support as support
|
from test import test_support as support
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
|
|
||||||
|
|
||||||
class NoAll(RuntimeError):
|
class NoAll(RuntimeError):
|
||||||
|
@ -18,9 +17,8 @@ class AllTest(unittest.TestCase):
|
||||||
|
|
||||||
def check_all(self, modname):
|
def check_all(self, modname):
|
||||||
names = {}
|
names = {}
|
||||||
with warnings.catch_warnings():
|
with support.check_warnings((".* (module|package)",
|
||||||
warnings.filterwarnings("ignore", ".* (module|package)",
|
DeprecationWarning), quiet=True):
|
||||||
DeprecationWarning)
|
|
||||||
try:
|
try:
|
||||||
exec "import %s" % modname in names
|
exec "import %s" % modname in names
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -7,7 +7,6 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
@ -4160,21 +4159,12 @@ class TestImportStar(TestCase):
|
||||||
self.assertTrue(hasattr(argparse, name))
|
self.assertTrue(hasattr(argparse, name))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with warnings.catch_warnings():
|
# silence warnings about version argument - these are expected
|
||||||
# silence warnings about version argument - these are expected
|
with test_support.check_warnings(
|
||||||
warnings.filterwarnings(
|
('The "version" argument to ArgumentParser is deprecated.',
|
||||||
action='ignore',
|
DeprecationWarning),
|
||||||
message='The "version" argument to ArgumentParser is deprecated.',
|
('The (format|print)_version method is deprecated',
|
||||||
category=DeprecationWarning)
|
DeprecationWarning)):
|
||||||
warnings.filterwarnings(
|
|
||||||
action='ignore',
|
|
||||||
message='The format_version method is deprecated',
|
|
||||||
category=DeprecationWarning)
|
|
||||||
warnings.filterwarnings(
|
|
||||||
action='ignore',
|
|
||||||
message='The print_version method is deprecated',
|
|
||||||
category=DeprecationWarning)
|
|
||||||
|
|
||||||
test_support.run_unittest(__name__)
|
test_support.run_unittest(__name__)
|
||||||
# Remove global references to avoid looking like we have refleaks.
|
# Remove global references to avoid looking like we have refleaks.
|
||||||
RFile.seen = {}
|
RFile.seen = {}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import copy
|
import copy
|
||||||
import warnings
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.test_support import run_unittest, TestFailed
|
from test.test_support import run_unittest, TestFailed, check_warnings
|
||||||
|
|
||||||
# Fake a number that implements numeric methods through __coerce__
|
# Fake a number that implements numeric methods through __coerce__
|
||||||
class CoerceNumber:
|
class CoerceNumber:
|
||||||
|
@ -223,12 +222,6 @@ def process_infix_results():
|
||||||
infix_results[key] = res
|
infix_results[key] = res
|
||||||
|
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.filterwarnings("ignore", "classic int division",
|
|
||||||
DeprecationWarning)
|
|
||||||
process_infix_results()
|
|
||||||
# now infix_results has two lists of results for every pairing.
|
|
||||||
|
|
||||||
prefix_binops = [ 'divmod' ]
|
prefix_binops = [ 'divmod' ]
|
||||||
prefix_results = [
|
prefix_results = [
|
||||||
[(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)],
|
[(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)],
|
||||||
|
@ -339,11 +332,13 @@ class CoercionTest(unittest.TestCase):
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with warnings.catch_warnings():
|
with check_warnings(("complex divmod.., // and % are deprecated",
|
||||||
warnings.filterwarnings("ignore", "complex divmod.., // and % "
|
DeprecationWarning),
|
||||||
"are deprecated", DeprecationWarning)
|
("classic (int|long) division", DeprecationWarning),
|
||||||
warnings.filterwarnings("ignore", "classic (int|long) division",
|
quiet=True):
|
||||||
DeprecationWarning)
|
process_infix_results()
|
||||||
|
# now infix_results has two lists of results for every pairing.
|
||||||
|
|
||||||
run_unittest(CoercionTest)
|
run_unittest(CoercionTest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -4,12 +4,9 @@
|
||||||
'''
|
'''
|
||||||
import unittest
|
import unittest
|
||||||
import os, tempfile, re
|
import os, tempfile, re
|
||||||
import warnings
|
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', r".*commands.getstatus.. is deprecated",
|
from test.test_support import run_unittest, reap_children, import_module, \
|
||||||
DeprecationWarning)
|
check_warnings
|
||||||
|
|
||||||
from test.test_support import run_unittest, reap_children, import_module
|
|
||||||
|
|
||||||
# Silence Py3k warning
|
# Silence Py3k warning
|
||||||
commands = import_module('commands', deprecated=True)
|
commands = import_module('commands', deprecated=True)
|
||||||
|
@ -59,7 +56,9 @@ class CommandTests(unittest.TestCase):
|
||||||
/\. # and end with the name of the file.
|
/\. # and end with the name of the file.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
self.assertTrue(re.match(pat, commands.getstatus("/."), re.VERBOSE))
|
with check_warnings((".*commands.getstatus.. is deprecated",
|
||||||
|
DeprecationWarning)):
|
||||||
|
self.assertTrue(re.match(pat, commands.getstatus("/."), re.VERBOSE))
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
import unittest, os
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings(
|
|
||||||
"ignore",
|
|
||||||
category=DeprecationWarning,
|
|
||||||
message=".*complex divmod.*are deprecated"
|
|
||||||
)
|
|
||||||
|
|
||||||
from random import random
|
from random import random
|
||||||
from math import atan2, isnan, copysign
|
from math import atan2, isnan, copysign
|
||||||
|
|
||||||
|
@ -464,10 +457,7 @@ class ComplexTest(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
if (fo is not None) and (not fo.closed):
|
if (fo is not None) and (not fo.closed):
|
||||||
fo.close()
|
fo.close()
|
||||||
try:
|
test_support.unlink(test_support.TESTFN)
|
||||||
os.remove(test_support.TESTFN)
|
|
||||||
except (OSError, IOError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_getnewargs(self):
|
def test_getnewargs(self):
|
||||||
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
|
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
|
||||||
|
@ -613,7 +603,9 @@ class ComplexTest(unittest.TestCase):
|
||||||
self.assertEqual('{0:F}'.format(complex(NAN, NAN)), 'NAN+NANj')
|
self.assertEqual('{0:F}'.format(complex(NAN, NAN)), 'NAN+NANj')
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(ComplexTest)
|
with test_support.check_warnings(("complex divmod.., // and % are "
|
||||||
|
"deprecated", DeprecationWarning)):
|
||||||
|
test_support.run_unittest(ComplexTest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
"""Unit tests for contextlib.py, and other context managers."""
|
"""Unit tests for contextlib.py, and other context managers."""
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import threading
|
import threading
|
||||||
from contextlib import * # Tests __all__
|
from contextlib import * # Tests __all__
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import warnings
|
|
||||||
|
|
||||||
class ContextManagerTestCase(unittest.TestCase):
|
class ContextManagerTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -34,16 +32,12 @@ class ContextManagerTestCase(unittest.TestCase):
|
||||||
yield 42
|
yield 42
|
||||||
finally:
|
finally:
|
||||||
state.append(999)
|
state.append(999)
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with woohoo() as x:
|
with woohoo() as x:
|
||||||
self.assertEqual(state, [1])
|
self.assertEqual(state, [1])
|
||||||
self.assertEqual(x, 42)
|
self.assertEqual(x, 42)
|
||||||
state.append(x)
|
state.append(x)
|
||||||
raise ZeroDivisionError()
|
raise ZeroDivisionError()
|
||||||
except ZeroDivisionError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("Expected ZeroDivisionError")
|
|
||||||
self.assertEqual(state, [1, 42, 999])
|
self.assertEqual(state, [1, 42, 999])
|
||||||
|
|
||||||
def test_contextmanager_no_reraise(self):
|
def test_contextmanager_no_reraise(self):
|
||||||
|
@ -144,15 +138,12 @@ class NestedTestCase(unittest.TestCase):
|
||||||
yield 5
|
yield 5
|
||||||
finally:
|
finally:
|
||||||
state.append(6)
|
state.append(6)
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with nested(a(), b()) as (x, y):
|
with nested(a(), b()) as (x, y):
|
||||||
state.append(x)
|
state.append(x)
|
||||||
state.append(y)
|
state.append(y)
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
self.assertEqual(state, [1, 4, 2, 5, 6, 3])
|
||||||
self.assertEqual(state, [1, 4, 2, 5, 6, 3])
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
def test_nested_right_exception(self):
|
def test_nested_right_exception(self):
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
@ -166,15 +157,10 @@ class NestedTestCase(unittest.TestCase):
|
||||||
raise Exception()
|
raise Exception()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with nested(a(), b()) as (x, y):
|
with nested(a(), b()) as (x, y):
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
self.assertEqual((x, y), (1, 2))
|
||||||
self.assertEqual((x, y), (1, 2))
|
|
||||||
except Exception:
|
|
||||||
self.fail("Reraised wrong exception")
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
def test_nested_b_swallows(self):
|
def test_nested_b_swallows(self):
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
@ -189,7 +175,7 @@ class NestedTestCase(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
with nested(a(), b()):
|
with nested(a(), b()):
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
self.fail("Didn't swallow ZeroDivisionError")
|
self.fail("Didn't swallow ZeroDivisionError")
|
||||||
|
|
||||||
|
@ -252,14 +238,11 @@ class ClosingTestCase(unittest.TestCase):
|
||||||
state.append(1)
|
state.append(1)
|
||||||
x = C()
|
x = C()
|
||||||
self.assertEqual(state, [])
|
self.assertEqual(state, [])
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with closing(x) as y:
|
with closing(x) as y:
|
||||||
self.assertEqual(x, y)
|
self.assertEqual(x, y)
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
self.assertEqual(state, [1])
|
||||||
self.assertEqual(state, [1])
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
class FileContextTestCase(unittest.TestCase):
|
class FileContextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -272,20 +255,14 @@ class FileContextTestCase(unittest.TestCase):
|
||||||
f.write("Booh\n")
|
f.write("Booh\n")
|
||||||
self.assertTrue(f.closed)
|
self.assertTrue(f.closed)
|
||||||
f = None
|
f = None
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with open(tfn, "r") as f:
|
with open(tfn, "r") as f:
|
||||||
self.assertFalse(f.closed)
|
self.assertFalse(f.closed)
|
||||||
self.assertEqual(f.read(), "Booh\n")
|
self.assertEqual(f.read(), "Booh\n")
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
self.assertTrue(f.closed)
|
||||||
self.assertTrue(f.closed)
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
test_support.unlink(tfn)
|
||||||
os.remove(tfn)
|
|
||||||
except os.error:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class LockContextTestCase(unittest.TestCase):
|
class LockContextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -294,14 +271,11 @@ class LockContextTestCase(unittest.TestCase):
|
||||||
with lock:
|
with lock:
|
||||||
self.assertTrue(locked())
|
self.assertTrue(locked())
|
||||||
self.assertFalse(locked())
|
self.assertFalse(locked())
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with lock:
|
with lock:
|
||||||
self.assertTrue(locked())
|
self.assertTrue(locked())
|
||||||
1/0
|
1 // 0
|
||||||
except ZeroDivisionError:
|
self.assertFalse(locked())
|
||||||
self.assertFalse(locked())
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
def testWithLock(self):
|
def testWithLock(self):
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
@ -339,8 +313,9 @@ class LockContextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# This is needed to make the test actually run under regrtest.py!
|
# This is needed to make the test actually run under regrtest.py!
|
||||||
def test_main():
|
def test_main():
|
||||||
with warnings.catch_warnings():
|
with test_support.check_warnings(("With-statements now directly support "
|
||||||
warnings.simplefilter('ignore')
|
"multiple context managers",
|
||||||
|
DeprecationWarning)):
|
||||||
test_support.run_unittest(__name__)
|
test_support.run_unittest(__name__)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
# Simple test suite for Cookie.py
|
# Simple test suite for Cookie.py
|
||||||
|
|
||||||
from test.test_support import run_unittest, run_doctest
|
from test.test_support import run_unittest, run_doctest, check_warnings
|
||||||
import unittest
|
import unittest
|
||||||
import Cookie
|
import Cookie
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings("ignore",
|
|
||||||
".* class is insecure.*",
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
class CookieTests(unittest.TestCase):
|
class CookieTests(unittest.TestCase):
|
||||||
# Currently this only tests SimpleCookie
|
# Currently this only tests SimpleCookie
|
||||||
|
@ -76,7 +72,9 @@ class CookieTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(CookieTests)
|
run_unittest(CookieTests)
|
||||||
run_doctest(Cookie)
|
with check_warnings(('.+Cookie class is insecure; do not use it',
|
||||||
|
DeprecationWarning)):
|
||||||
|
run_doctest(Cookie)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -2,7 +2,6 @@ import __builtin__
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
@ -59,15 +58,6 @@ class OperatorsTest(unittest.TestCase):
|
||||||
expr = '%s a' % expr
|
expr = '%s a' % expr
|
||||||
self.unops[name] = expr
|
self.unops[name] = expr
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.original_filters = warnings.filters[:]
|
|
||||||
warnings.filterwarnings("ignore",
|
|
||||||
r'complex divmod\(\), // and % are deprecated$',
|
|
||||||
DeprecationWarning, r'(<string>|%s)$' % __name__)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
warnings.filters = self.original_filters
|
|
||||||
|
|
||||||
def unop_test(self, a, res, expr="len(a)", meth="__len__"):
|
def unop_test(self, a, res, expr="len(a)", meth="__len__"):
|
||||||
d = {'a': a}
|
d = {'a': a}
|
||||||
self.assertEqual(eval(expr, d), res)
|
self.assertEqual(eval(expr, d), res)
|
||||||
|
@ -4622,11 +4612,15 @@ class PTypesLongInitTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with test_support.check_py3k_warnings(
|
deprecations = [(r'complex divmod\(\), // and % are deprecated$',
|
||||||
|
DeprecationWarning)]
|
||||||
|
if sys.py3kwarning:
|
||||||
|
deprecations += [
|
||||||
("classic (int|long) division", DeprecationWarning),
|
("classic (int|long) division", DeprecationWarning),
|
||||||
("coerce.. not supported", DeprecationWarning),
|
("coerce.. not supported", DeprecationWarning),
|
||||||
("Overriding __cmp__ ", DeprecationWarning),
|
("Overriding __cmp__ ", DeprecationWarning),
|
||||||
(".+__(get|set|del)slice__ has been removed", DeprecationWarning)):
|
(".+__(get|set|del)slice__ has been removed", DeprecationWarning)]
|
||||||
|
with test_support.check_warnings(*deprecations):
|
||||||
# Run all local test cases, with PTypesLongInitTest first.
|
# Run all local test cases, with PTypesLongInitTest first.
|
||||||
test_support.run_unittest(PTypesLongInitTest, OperatorsTest,
|
test_support.run_unittest(PTypesLongInitTest, OperatorsTest,
|
||||||
ClassPropertiesAndMethods, DictProxyTests)
|
ClassPropertiesAndMethods, DictProxyTests)
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
Test script for doctest.
|
Test script for doctest.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import doctest
|
import doctest
|
||||||
import warnings
|
|
||||||
|
|
||||||
# NOTE: There are some additional tests relating to interaction with
|
# NOTE: There are some additional tests relating to interaction with
|
||||||
# zipimport in the test_zipimport_support test module.
|
# zipimport in the test_zipimport_support test module.
|
||||||
|
@ -2458,12 +2458,13 @@ def test_main():
|
||||||
test_support.run_doctest(doctest, verbosity=True)
|
test_support.run_doctest(doctest, verbosity=True)
|
||||||
|
|
||||||
from test import test_doctest
|
from test import test_doctest
|
||||||
with test_support.check_py3k_warnings(
|
|
||||||
("backquote not supported", SyntaxWarning),
|
# Ignore all warnings about the use of class Tester in this module.
|
||||||
("execfile.. not supported", DeprecationWarning)):
|
deprecations = [("class Tester is deprecated", DeprecationWarning)]
|
||||||
# Ignore all warnings about the use of class Tester in this module.
|
if sys.py3kwarning:
|
||||||
warnings.filterwarnings("ignore", "class Tester is deprecated",
|
deprecations += [("backquote not supported", SyntaxWarning),
|
||||||
DeprecationWarning)
|
("execfile.. not supported", DeprecationWarning)]
|
||||||
|
with test_support.check_warnings(*deprecations):
|
||||||
# Check the doctest cases defined here:
|
# Check the doctest cases defined here:
|
||||||
test_support.run_doctest(test_doctest, verbosity=True)
|
test_support.run_doctest(test_doctest, verbosity=True)
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import pickle, cPickle
|
import pickle, cPickle
|
||||||
import warnings
|
|
||||||
|
|
||||||
from test.test_support import TESTFN, unlink, run_unittest, captured_output
|
from test.test_support import (TESTFN, unlink, run_unittest, captured_output,
|
||||||
|
check_warnings)
|
||||||
from test.test_pep352 import ignore_deprecation_warnings
|
from test.test_pep352 import ignore_deprecation_warnings
|
||||||
|
|
||||||
# XXX This is not really enough, each *operation* should be tested!
|
# XXX This is not really enough, each *operation* should be tested!
|
||||||
|
@ -308,24 +308,19 @@ class ExceptionTests(unittest.TestCase):
|
||||||
# Accessing BaseException.message and relying on its value set by
|
# Accessing BaseException.message and relying on its value set by
|
||||||
# BaseException.__init__ triggers a deprecation warning.
|
# BaseException.__init__ triggers a deprecation warning.
|
||||||
exc = BaseException("foo")
|
exc = BaseException("foo")
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with check_warnings(("BaseException.message has been deprecated "
|
||||||
warnings.simplefilter('default')
|
"as of Python 2.6", DeprecationWarning)) as w:
|
||||||
self.assertEquals(exc.message, "foo")
|
self.assertEqual(exc.message, "foo")
|
||||||
self.assertEquals(len(w), 1)
|
self.assertEqual(len(w.warnings), 1)
|
||||||
self.assertEquals(w[0].category, DeprecationWarning)
|
|
||||||
self.assertEquals(
|
|
||||||
str(w[0].message),
|
|
||||||
"BaseException.message has been deprecated as of Python 2.6")
|
|
||||||
|
|
||||||
|
|
||||||
def testRegularMessageAttribute(self):
|
def testRegularMessageAttribute(self):
|
||||||
# Accessing BaseException.message after explicitly setting a value
|
# Accessing BaseException.message after explicitly setting a value
|
||||||
# for it does not trigger a deprecation warning.
|
# for it does not trigger a deprecation warning.
|
||||||
exc = BaseException("foo")
|
exc = BaseException("foo")
|
||||||
exc.message = "bar"
|
exc.message = "bar"
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with check_warnings(quiet=True) as w:
|
||||||
self.assertEquals(exc.message, "bar")
|
self.assertEqual(exc.message, "bar")
|
||||||
self.assertEquals(len(w), 0)
|
self.assertEqual(len(w.warnings), 0)
|
||||||
# Deleting the message is supported, too.
|
# Deleting the message is supported, too.
|
||||||
del exc.message
|
del exc.message
|
||||||
with self.assertRaises(AttributeError):
|
with self.assertRaises(AttributeError):
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
from test.test_support import run_unittest, check_syntax_error
|
from test.test_support import run_unittest, check_syntax_error
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings("error", module="<test string>")
|
|
||||||
|
|
||||||
class GlobalTests(unittest.TestCase):
|
class GlobalTests(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -45,7 +44,9 @@ x = 2
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(GlobalTests)
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("error", module="<test string>")
|
||||||
|
run_unittest(GlobalTests)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -213,19 +213,13 @@ class TestVectorsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter('error', RuntimeWarning)
|
warnings.simplefilter('error', RuntimeWarning)
|
||||||
try:
|
with self.assertRaises(RuntimeWarning):
|
||||||
hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
|
hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
|
||||||
except RuntimeWarning:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail('Expected warning about missing block_size')
|
self.fail('Expected warning about missing block_size')
|
||||||
|
|
||||||
MockCrazyHash.block_size = 1
|
MockCrazyHash.block_size = 1
|
||||||
try:
|
with self.assertRaises(RuntimeWarning):
|
||||||
hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
|
hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
|
||||||
except RuntimeWarning:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail('Expected warning about small block_size')
|
self.fail('Expected warning about small block_size')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,6 @@ This is complex because of changes due to PEP 237.
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
|
|
||||||
"<string>")
|
|
||||||
|
|
||||||
class TestHexOctBin(unittest.TestCase):
|
class TestHexOctBin(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ import array
|
||||||
import threading
|
import threading
|
||||||
import random
|
import random
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
import weakref
|
import weakref
|
||||||
import abc
|
import abc
|
||||||
from itertools import cycle, count
|
from itertools import cycle, count
|
||||||
|
|
|
@ -23,14 +23,8 @@ class TestMacostools(unittest.TestCase):
|
||||||
rfp.close()
|
rfp.close()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
test_support.unlink(test_support.TESTFN)
|
||||||
os.unlink(test_support.TESTFN)
|
test_support.unlink(TESTFN2)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
os.unlink(TESTFN2)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def compareData(self):
|
def compareData(self):
|
||||||
fp = open(test_support.TESTFN, 'r')
|
fp = open(test_support.TESTFN, 'r')
|
||||||
|
@ -53,36 +47,25 @@ class TestMacostools(unittest.TestCase):
|
||||||
|
|
||||||
def test_touched(self):
|
def test_touched(self):
|
||||||
# This really only tests that nothing unforeseen happens.
|
# This really only tests that nothing unforeseen happens.
|
||||||
import warnings
|
with test_support.check_warnings(('macostools.touched*',
|
||||||
with warnings.catch_warnings():
|
DeprecationWarning), quiet=True):
|
||||||
warnings.filterwarnings('ignore', 'macostools.touched*',
|
|
||||||
DeprecationWarning)
|
|
||||||
macostools.touched(test_support.TESTFN)
|
macostools.touched(test_support.TESTFN)
|
||||||
|
|
||||||
if sys.maxint < 2**32:
|
if sys.maxint < 2**32:
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
try:
|
test_support.unlink(TESTFN2)
|
||||||
os.unlink(TESTFN2)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
macostools.copy(test_support.TESTFN, TESTFN2)
|
macostools.copy(test_support.TESTFN, TESTFN2)
|
||||||
self.assertEqual(self.compareData(), '')
|
self.assertEqual(self.compareData(), '')
|
||||||
|
|
||||||
if sys.maxint < 2**32:
|
if sys.maxint < 2**32:
|
||||||
def test_mkalias(self):
|
def test_mkalias(self):
|
||||||
try:
|
test_support.unlink(TESTFN2)
|
||||||
os.unlink(TESTFN2)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
macostools.mkalias(test_support.TESTFN, TESTFN2)
|
macostools.mkalias(test_support.TESTFN, TESTFN2)
|
||||||
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
|
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
|
||||||
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
|
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
|
||||||
|
|
||||||
def test_mkalias_relative(self):
|
def test_mkalias_relative(self):
|
||||||
try:
|
test_support.unlink(TESTFN2)
|
||||||
os.unlink(TESTFN2)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
# If the directory doesn't exist, then chances are this is a new
|
# If the directory doesn't exist, then chances are this is a new
|
||||||
# install of Python so don't create it since the user might end up
|
# install of Python so don't create it since the user might end up
|
||||||
# running ``sudo make install`` and creating the directory here won't
|
# running ``sudo make install`` and creating the directory here won't
|
||||||
|
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
import __builtin__
|
import __builtin__
|
||||||
import exceptions
|
import exceptions
|
||||||
import warnings
|
import warnings
|
||||||
from test.test_support import run_unittest
|
from test.test_support import run_unittest, check_warnings
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from platform import system as platform_system
|
from platform import system as platform_system
|
||||||
|
@ -15,14 +15,13 @@ if sys.py3kwarning:
|
||||||
"catching classes that don't inherit from BaseException is not allowed",
|
"catching classes that don't inherit from BaseException is not allowed",
|
||||||
"__get(item|slice)__ not supported for exception classes"])
|
"__get(item|slice)__ not supported for exception classes"])
|
||||||
|
|
||||||
|
_deprecations = [(msg, DeprecationWarning) for msg in DEPRECATION_WARNINGS]
|
||||||
|
|
||||||
# Silence Py3k and other deprecation warnings
|
# Silence Py3k and other deprecation warnings
|
||||||
def ignore_deprecation_warnings(func):
|
def ignore_deprecation_warnings(func):
|
||||||
"""Ignore the known DeprecationWarnings."""
|
"""Ignore the known DeprecationWarnings."""
|
||||||
def wrapper(*args, **kw):
|
def wrapper(*args, **kw):
|
||||||
with warnings.catch_warnings():
|
with check_warnings(*_deprecations, quiet=True):
|
||||||
warnings.resetwarnings()
|
|
||||||
for text in DEPRECATION_WARNINGS:
|
|
||||||
warnings.filterwarnings("ignore", text, DeprecationWarning)
|
|
||||||
return func(*args, **kw)
|
return func(*args, **kw)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -139,16 +138,8 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_message_deprecation(self):
|
def test_message_deprecation(self):
|
||||||
# As of Python 2.6, BaseException.message is deprecated.
|
# As of Python 2.6, BaseException.message is deprecated.
|
||||||
with warnings.catch_warnings():
|
with check_warnings(("", DeprecationWarning)):
|
||||||
warnings.resetwarnings()
|
BaseException().message
|
||||||
warnings.filterwarnings('error')
|
|
||||||
|
|
||||||
try:
|
|
||||||
BaseException().message
|
|
||||||
except DeprecationWarning:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("BaseException.message not deprecated")
|
|
||||||
|
|
||||||
|
|
||||||
class UsageTests(unittest.TestCase):
|
class UsageTests(unittest.TestCase):
|
||||||
|
@ -224,28 +215,19 @@ class UsageTests(unittest.TestCase):
|
||||||
warnings.resetwarnings()
|
warnings.resetwarnings()
|
||||||
warnings.filterwarnings("error")
|
warnings.filterwarnings("error")
|
||||||
str_exc = "spam"
|
str_exc = "spam"
|
||||||
try:
|
with self.assertRaises(DeprecationWarning):
|
||||||
try:
|
try:
|
||||||
raise StandardError
|
raise StandardError
|
||||||
except str_exc:
|
except str_exc:
|
||||||
pass
|
pass
|
||||||
except DeprecationWarning:
|
|
||||||
pass
|
|
||||||
except StandardError:
|
|
||||||
self.fail("catching a string exception did not raise "
|
|
||||||
"DeprecationWarning")
|
|
||||||
# Make sure that even if the string exception is listed in a tuple
|
# Make sure that even if the string exception is listed in a tuple
|
||||||
# that a warning is raised.
|
# that a warning is raised.
|
||||||
try:
|
with self.assertRaises(DeprecationWarning):
|
||||||
try:
|
try:
|
||||||
raise StandardError
|
raise StandardError
|
||||||
except (AssertionError, str_exc):
|
except (AssertionError, str_exc):
|
||||||
pass
|
pass
|
||||||
except DeprecationWarning:
|
|
||||||
pass
|
|
||||||
except StandardError:
|
|
||||||
self.fail("catching a string exception specified in a tuple did "
|
|
||||||
"not raise DeprecationWarning")
|
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.test_support import verbose, run_unittest
|
from test.test_support import verbose, run_unittest, import_module
|
||||||
import re
|
import re
|
||||||
from re import Scanner
|
from re import Scanner
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
|
@ -447,11 +447,8 @@ class ReTests(unittest.TestCase):
|
||||||
import cPickle
|
import cPickle
|
||||||
self.pickle_test(cPickle)
|
self.pickle_test(cPickle)
|
||||||
# old pickles expect the _compile() reconstructor in sre module
|
# old pickles expect the _compile() reconstructor in sre module
|
||||||
import warnings
|
import_module("sre", deprecated=True)
|
||||||
with warnings.catch_warnings():
|
from sre import _compile
|
||||||
warnings.filterwarnings("ignore", "The sre module is deprecated",
|
|
||||||
DeprecationWarning)
|
|
||||||
from sre import _compile
|
|
||||||
|
|
||||||
def pickle_test(self, pickle):
|
def pickle_test(self, pickle):
|
||||||
oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
|
oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
|
||||||
|
|
|
@ -3,13 +3,11 @@
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
|
|
||||||
class TestUntestedModules(unittest.TestCase):
|
class TestUntestedModules(unittest.TestCase):
|
||||||
def test_at_least_import_untested_modules(self):
|
def test_at_least_import_untested_modules(self):
|
||||||
with warnings.catch_warnings():
|
with test_support.check_warnings(quiet=True):
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
import CGIHTTPServer
|
import CGIHTTPServer
|
||||||
import audiodev
|
import audiodev
|
||||||
import bdb
|
import bdb
|
||||||
|
|
|
@ -3,7 +3,6 @@ Test the API of the symtable module.
|
||||||
"""
|
"""
|
||||||
import symtable
|
import symtable
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
|
@ -44,9 +43,8 @@ def find_block(block, name):
|
||||||
|
|
||||||
class SymtableTest(unittest.TestCase):
|
class SymtableTest(unittest.TestCase):
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with test_support.check_warnings(
|
||||||
# Ignore warnings about "from blank import *"
|
("import \* only allowed at module level", SyntaxWarning)):
|
||||||
warnings.simplefilter("ignore", SyntaxWarning)
|
|
||||||
top = symtable.symtable(TEST_CODE, "?", "exec")
|
top = symtable.symtable(TEST_CODE, "?", "exec")
|
||||||
# These correspond to scopes in TEST_CODE
|
# These correspond to scopes in TEST_CODE
|
||||||
Mine = find_block(top, "Mine")
|
Mine = find_block(top, "Mine")
|
||||||
|
|
|
@ -182,10 +182,8 @@ class urlretrieveNetworkTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.requires('network')
|
test_support.requires('network')
|
||||||
from warnings import filterwarnings, catch_warnings
|
with test_support.check_py3k_warnings(
|
||||||
with catch_warnings():
|
("urllib.urlopen.. has been removed", DeprecationWarning)):
|
||||||
filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
|
|
||||||
DeprecationWarning)
|
|
||||||
test_support.run_unittest(URLTimeoutTest,
|
test_support.run_unittest(URLTimeoutTest,
|
||||||
urlopenNetworkTests,
|
urlopenNetworkTests,
|
||||||
urlretrieveNetworkTests)
|
urlretrieveNetworkTests)
|
||||||
|
|
|
@ -168,12 +168,14 @@ class ZipSupportTests(ImportHooksBaseTestCase):
|
||||||
test_zipped_doctest.test_unittest_reportflags,
|
test_zipped_doctest.test_unittest_reportflags,
|
||||||
]
|
]
|
||||||
# Needed for test_DocTestParser and test_debug
|
# Needed for test_DocTestParser and test_debug
|
||||||
with test.test_support.check_py3k_warnings(
|
deprecations = [
|
||||||
("backquote not supported", SyntaxWarning),
|
|
||||||
("execfile.. not supported", DeprecationWarning)):
|
|
||||||
# Ignore all warnings about the use of class Tester in this module.
|
# Ignore all warnings about the use of class Tester in this module.
|
||||||
warnings.filterwarnings("ignore", "class Tester is deprecated",
|
("class Tester is deprecated", DeprecationWarning)]
|
||||||
DeprecationWarning)
|
if sys.py3kwarning:
|
||||||
|
deprecations += [
|
||||||
|
("backquote not supported", SyntaxWarning),
|
||||||
|
("execfile.. not supported", DeprecationWarning)]
|
||||||
|
with test.test_support.check_warnings(*deprecations):
|
||||||
for obj in known_good_tests:
|
for obj in known_good_tests:
|
||||||
_run_object_doctest(obj, test_zipped_doctest)
|
_run_object_doctest(obj, test_zipped_doctest)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue