[pygobject] tests_gi: Use capture_output() context manager instead of manually mocking stdout
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests_gi: Use capture_output() context manager instead of manually mocking stdout
- Date: Mon, 12 Mar 2018 06:32:13 +0000 (UTC)
commit 32ed54bbe8519f8e771fcb6a03dd64160b60d22f
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Mar 10 18:04:14 2018 +0100
tests_gi: Use capture_output() context manager instead of manually mocking stdout
tests/helper.py | 2 +-
tests/test_gi.py | 14 +++-----------
2 files changed, 4 insertions(+), 12 deletions(-)
---
diff --git a/tests/helper.py b/tests/helper.py
index b683a4af..22d1b503 100644
--- a/tests/helper.py
+++ b/tests/helper.py
@@ -115,7 +115,7 @@ def capture_glib_deprecation_warnings():
@contextlib.contextmanager
def capture_output():
"""
- with capture_output as (stdout, stderr):
+ with capture_output() as (stdout, stderr):
some_action()
print(stdout.getvalue(), stderr.getvalue())
"""
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 31085206..2e2fed40 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -13,7 +13,6 @@ import os
import gc
import weakref
import warnings
-from io import StringIO, BytesIO
import gi
import gi.overrides
@@ -24,7 +23,7 @@ from gi.repository import GObject, GLib, Gio
from gi.repository import GIMarshallingTests
from .compathelper import PY2, PY3
-from .helper import capture_exceptions
+from .helper import capture_exceptions, capture_output
CONSTANT_UTF8 = "const ♥ utf8"
@@ -2996,16 +2995,9 @@ class TestModule(unittest.TestCase):
self.assertTrue(hasattr(item, '__class__'))
def test_help(self):
- orig_stdout = sys.stdout
- try:
- if sys.version_info < (3, 0):
- sys.stdout = BytesIO()
- else:
- sys.stdout = StringIO()
+ with capture_output() as (stdout, stderr):
help(GIMarshallingTests)
- output = sys.stdout.getvalue()
- finally:
- sys.stdout = orig_stdout
+ output = stdout.getvalue()
self.assertTrue('SimpleStruct' in output, output)
self.assertTrue('Interface2' in output, output)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]