From 3b41b2a4b7532c911b63b41066a75b3e1546d214 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Thu, 15 Dec 2022 17:21:20 +0100 Subject: minor test improvements and information hiding in builder --- test/apps/test_index.py | 2 +- test/apps/test_info.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/apps/test_index.py b/test/apps/test_index.py index c567dea..2be8470 100644 --- a/test/apps/test_index.py +++ b/test/apps/test_index.py @@ -5,10 +5,10 @@ A copy of the license is provided with the project. Author: Matthias Baumgartner, 2022 """ # imports +import contextlib import io import os import rdflib -import sys import unittest # bsie imports diff --git a/test/apps/test_info.py b/test/apps/test_info.py index 60a540e..ad39c64 100644 --- a/test/apps/test_info.py +++ b/test/apps/test_info.py @@ -6,9 +6,9 @@ Author: Matthias Baumgartner, 2022 """ # imports import argparse +import contextlib import io import os -import sys import unittest # objects to test @@ -19,10 +19,10 @@ from bsie.apps.info import main class TestIndex(unittest.TestCase): def test_predicates(self): - stdout, sys.stdout = sys.stdout, io.StringIO() - # show predicates infos - main(['predicates']) - outbuf, sys.stdout = sys.stdout, stdout + outbuf = io.StringIO() + with contextlib.redirect_stdout(outbuf): + # show predicates infos + main(['predicates']) # verify output self.assertSetEqual({pred for pred in outbuf.getvalue().split('\n') if pred != ''}, { 'http://bsfs.ai/schema/Entity#author', @@ -32,7 +32,8 @@ class TestIndex(unittest.TestCase): }) def test_invalid(self): - self.assertRaises(SystemExit, main, ['foobar']) + with contextlib.redirect_stderr(io.StringIO()): + self.assertRaises(SystemExit, main, ['foobar']) ## main ## -- cgit v1.2.3