summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/contextlib.py8
-rw-r--r--Lib/test/test_contextlib.py28
2 files changed, 18 insertions, 18 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 41ff9cc..144d6bb 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -5,7 +5,7 @@ from collections import deque
from functools import wraps
__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack",
- "ignore", "redirect_stdout"]
+ "redirect_stdout", "suppress"]
class ContextDecorator(object):
@@ -179,10 +179,10 @@ class redirect_stdout:
sys.stdout = self.old_target
@contextmanager
-def ignore(*exceptions):
- """Context manager to ignore specified exceptions
+def suppress(*exceptions):
+ """Context manager to suppress specified exceptions
- with ignore(OSError):
+ with suppress(OSError):
os.remove(somefile)
"""
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 48f8fa9..5c1c5c5 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -632,36 +632,36 @@ class TestExitStack(unittest.TestCase):
stack.push(cm)
self.assertIs(stack._exit_callbacks[-1], cm)
-class TestIgnore(unittest.TestCase):
+class TestRedirectStdout(unittest.TestCase):
+
+ def test_redirect_to_string_io(self):
+ f = io.StringIO()
+ with redirect_stdout(f):
+ help(pow)
+ s = f.getvalue()
+ self.assertIn('pow', s)
+
+class TestSuppress(unittest.TestCase):
def test_no_exception(self):
- with ignore(ValueError):
+ with suppress(ValueError):
self.assertEqual(pow(2, 5), 32)
def test_exact_exception(self):
- with ignore(TypeError):
+ with suppress(TypeError):
len(5)
def test_multiple_exception_args(self):
- with ignore(ZeroDivisionError, TypeError):
+ with suppress(ZeroDivisionError, TypeError):
len(5)
def test_exception_hierarchy(self):
- with ignore(LookupError):
+ with suppress(LookupError):
'Hello'[50]
-class TestRedirectStdout(unittest.TestCase):
-
- def test_redirect_to_string_io(self):
- f = io.StringIO()
- with redirect_stdout(f):
- help(pow)
- s = f.getvalue()
- self.assertIn('pow', s)
-
if __name__ == "__main__":
unittest.main()