mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
Merged revisions 79539 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79539 | florent.xicluna | 2010-04-01 01:01:03 +0300 (Thu, 01 Apr 2010) | 2 lines Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests. ........
This commit is contained in:
parent
cc436eb6e8
commit
1d55ec329a
20 changed files with 98 additions and 149 deletions
|
@ -1,6 +1,5 @@
|
|||
"""Unit tests for contextlib.py, and other context managers."""
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
import decimal
|
||||
|
@ -139,7 +138,7 @@ class NestedTestCase(unittest.TestCase):
|
|||
with nested(a(), b()) as (x, y):
|
||||
state.append(x)
|
||||
state.append(y)
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.assertEqual(state, [1, 4, 2, 5, 6, 3])
|
||||
else:
|
||||
|
@ -160,7 +159,7 @@ class NestedTestCase(unittest.TestCase):
|
|||
pass
|
||||
try:
|
||||
with nested(a(), b()) as (x, y):
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.assertEqual((x, y), (1, 2))
|
||||
except Exception:
|
||||
|
@ -181,7 +180,7 @@ class NestedTestCase(unittest.TestCase):
|
|||
pass
|
||||
try:
|
||||
with nested(a(), b()):
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.fail("Didn't swallow ZeroDivisionError")
|
||||
|
||||
|
@ -247,7 +246,7 @@ class ClosingTestCase(unittest.TestCase):
|
|||
try:
|
||||
with closing(x) as y:
|
||||
self.assertEqual(x, y)
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.assertEqual(state, [1])
|
||||
else:
|
||||
|
@ -268,7 +267,7 @@ class FileContextTestCase(unittest.TestCase):
|
|||
with open(tfn, "r") as f:
|
||||
self.failIf(f.closed)
|
||||
self.assertEqual(f.read(), "Booh\n")
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.failUnless(f.closed)
|
||||
else:
|
||||
|
@ -289,7 +288,7 @@ class LockContextTestCase(unittest.TestCase):
|
|||
try:
|
||||
with lock:
|
||||
self.failUnless(locked())
|
||||
1/0
|
||||
1 // 0
|
||||
except ZeroDivisionError:
|
||||
self.failIf(locked())
|
||||
else:
|
||||
|
@ -333,5 +332,6 @@ class LockContextTestCase(unittest.TestCase):
|
|||
def test_main():
|
||||
test_support.run_unittest(__name__)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue