summaryrefslogtreecommitdiff
path: root/Lib/test/test_py3kwarn.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2008-07-13 12:23:47 +0000
committerNick Coghlan <ncoghlan@gmail.com>2008-07-13 12:23:47 +0000
commit38469e271929399c12d6770d91958d8abac7433a (patch)
treeb347e1d7a9b8176cae5bc57b7f9f5180c7438064 /Lib/test/test_py3kwarn.py
parent3d0b9f095a1ccda7d6c04a9a1d05d245d8b82e26 (diff)
downloadcpython-git-38469e271929399c12d6770d91958d8abac7433a.tar.gz
Make test.test_support.catch_warnings more robust as discussed on python-dev. Also add explicit tests for itto test_warnings.
Diffstat (limited to 'Lib/test/test_py3kwarn.py')
-rw-r--r--Lib/test/test_py3kwarn.py30
1 files changed, 2 insertions, 28 deletions
diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py
index a289cc765d..0d01572088 100644
--- a/Lib/test/test_py3kwarn.py
+++ b/Lib/test/test_py3kwarn.py
@@ -26,41 +26,30 @@ class TestPy3KWarnings(unittest.TestCase):
with catch_warning() as w:
safe_exec("True = False")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("False = True")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
try:
safe_exec("obj.False = True")
except NameError: pass
self.assertWarning(None, w, expected)
- with catch_warning() as w:
try:
safe_exec("obj.True = False")
except NameError: pass
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("def False(): pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("def True(): pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("class False: pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("class True: pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("def f(True=43): pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("def f(False=None): pass")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("f(False=True)")
self.assertWarning(None, w, expected)
- with catch_warning() as w:
safe_exec("f(True=1)")
self.assertWarning(None, w, expected)
@@ -69,25 +58,20 @@ class TestPy3KWarnings(unittest.TestCase):
expected = 'type inequality comparisons not supported in 3.x'
with catch_warning() as w:
self.assertWarning(int < str, w, expected)
- with catch_warning() as w:
self.assertWarning(type < object, w, expected)
def test_object_inequality_comparisons(self):
expected = 'comparing unequal types not supported in 3.x'
with catch_warning() as w:
self.assertWarning(str < [], w, expected)
- with catch_warning() as w:
self.assertWarning(object() < (1, 2), w, expected)
def test_dict_inequality_comparisons(self):
expected = 'dict inequality comparisons not supported in 3.x'
with catch_warning() as w:
self.assertWarning({} < {2:3}, w, expected)
- with catch_warning() as w:
self.assertWarning({} <= {}, w, expected)
- with catch_warning() as w:
self.assertWarning({} > {2:3}, w, expected)
- with catch_warning() as w:
self.assertWarning({2:3} >= {}, w, expected)
def test_cell_inequality_comparisons(self):
@@ -100,7 +84,6 @@ class TestPy3KWarnings(unittest.TestCase):
cell1, = f(1).func_closure
with catch_warning() as w:
self.assertWarning(cell0 == cell1, w, expected)
- with catch_warning() as w:
self.assertWarning(cell0 < cell1, w, expected)
def test_code_inequality_comparisons(self):
@@ -111,11 +94,8 @@ class TestPy3KWarnings(unittest.TestCase):
pass
with catch_warning() as w:
self.assertWarning(f.func_code < g.func_code, w, expected)
- with catch_warning() as w:
self.assertWarning(f.func_code <= g.func_code, w, expected)
- with catch_warning() as w:
self.assertWarning(f.func_code >= g.func_code, w, expected)
- with catch_warning() as w:
self.assertWarning(f.func_code > g.func_code, w, expected)
def test_builtin_function_or_method_comparisons(self):
@@ -125,11 +105,8 @@ class TestPy3KWarnings(unittest.TestCase):
meth = {}.get
with catch_warning() as w:
self.assertWarning(func < meth, w, expected)
- with catch_warning() as w:
self.assertWarning(func > meth, w, expected)
- with catch_warning() as w:
self.assertWarning(meth <= func, w, expected)
- with catch_warning() as w:
self.assertWarning(meth >= func, w, expected)
def assertWarning(self, _, warning, expected_message):
@@ -142,11 +119,8 @@ class TestPy3KWarnings(unittest.TestCase):
with catch_warning() as w:
self.assertWarning(lst.sort(cmp=cmp), w, expected)
- with catch_warning() as w:
self.assertWarning(sorted(lst, cmp=cmp), w, expected)
- with catch_warning() as w:
self.assertWarning(lst.sort(cmp), w, expected)
- with catch_warning() as w:
self.assertWarning(sorted(lst, cmp), w, expected)
def test_sys_exc_clear(self):
@@ -229,7 +203,7 @@ class TestStdlibRemovals(unittest.TestCase):
"""Make sure the specified module, when imported, raises a
DeprecationWarning and specifies itself in the message."""
with CleanImport(module_name):
- with catch_warning(record=False) as w:
+ with catch_warning(record=False):
warnings.filterwarnings("error", ".+ removed",
DeprecationWarning)
try:
@@ -290,7 +264,7 @@ class TestStdlibRemovals(unittest.TestCase):
def test_main():
- with catch_warning(record=True):
+ with catch_warning():
warnings.simplefilter("always")
run_unittest(TestPy3KWarnings,
TestStdlibRemovals)