Make all classes new-style in Python 2, allowing them to be used with ExitStack.

This commit is contained in:
Devin Jeanpierre 2016-01-29 14:11:25 -08:00
parent 20cdf6eda5
commit e48fbea5a5
2 changed files with 12 additions and 2 deletions

View file

@ -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

View file

@ -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()