mirror of
https://github.com/jazzband/contextlib2.git
synced 2026-03-16 21:50:24 +00:00
Make all classes new-style in Python 2, allowing them to be used with ExitStack.
This commit is contained in:
parent
20cdf6eda5
commit
e48fbea5a5
2 changed files with 12 additions and 2 deletions
|
|
@ -179,7 +179,7 @@ class closing(object):
|
|||
self.thing.close()
|
||||
|
||||
|
||||
class _RedirectStream:
|
||||
class _RedirectStream(object):
|
||||
|
||||
_stream = None
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ class redirect_stderr(_RedirectStream):
|
|||
_stream = "stderr"
|
||||
|
||||
|
||||
class suppress:
|
||||
class suppress(object):
|
||||
"""Context manager to suppress specified exceptions
|
||||
|
||||
After the exception is suppressed, execution proceeds with the next
|
||||
|
|
|
|||
|
|
@ -763,6 +763,11 @@ class TestRedirectStream:
|
|||
s = f.getvalue()
|
||||
self.assertEqual(s, "Hello World!\n")
|
||||
|
||||
def test_cm_is_exitstack_compatible(self):
|
||||
with ExitStack() as stack:
|
||||
# This shouldn't raise an exception.
|
||||
stack.enter_context(self.redirect_stream(io.StringIO()))
|
||||
|
||||
|
||||
class TestRedirectStdout(TestRedirectStream, unittest.TestCase):
|
||||
|
||||
|
|
@ -830,6 +835,11 @@ class TestSuppress(unittest.TestCase):
|
|||
1/0
|
||||
self.assertTrue(outer_continued)
|
||||
|
||||
def test_cm_is_exitstack_compatible(self):
|
||||
with ExitStack() as stack:
|
||||
# This shouldn't raise an exception.
|
||||
stack.enter_context(suppress())
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue