minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-python / pythonFiles / testing_tools / adapter / util.py
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3
4 import contextlib
5 try:
6     from io import StringIO
7 except ImportError:
8     from StringIO import StringIO  # 2.7
9 import sys
10
11
12 @contextlib.contextmanager
13 def noop_cm():
14     yield
15
16
17 @contextlib.contextmanager
18 def hide_stdio():
19     """Swallow stdout and stderr."""
20     ignored = IgnoredIO()
21     sys.stdout = ignored
22     sys.stderr = ignored
23     try:
24         yield
25     finally:
26         sys.stdout = sys.__stdout__
27         sys.stderr = sys.__stderr__
28
29
30 class IgnoredIO(StringIO):
31     """A noop "file"."""
32     def write(self, msg):
33         pass