X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fee8873d0c5eeec1bd838161357679de1a3fe0cb..04951581a941697d68cdaf9af6661c3c412f1bce:/sdk/python/tests/test_arv_ws.py diff --git a/sdk/python/tests/test_arv_ws.py b/sdk/python/tests/test_arv_ws.py index 17706c19b6..2a85e04e87 100644 --- a/sdk/python/tests/test_arv_ws.py +++ b/sdk/python/tests/test_arv_ws.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import multiprocessing +import io import os import sys import tempfile @@ -8,36 +8,21 @@ import unittest import arvados.errors as arv_error import arvados.commands.ws as arv_ws +import arvados_testutil as tutil class ArvWsTestCase(unittest.TestCase): def run_ws(self, args): return arv_ws.main(args) - def run_ws_process(self, args=[], api_client=None): - _, stdout_path = tempfile.mkstemp() - _, stderr_path = tempfile.mkstemp() - def wrap(): - def wrapper(*args, **kwargs): - sys.stdout = open(stdout_path, 'w') - sys.stderr = open(stderr_path, 'w') - arv_ws.main(*args, **kwargs) - return wrapper - p = multiprocessing.Process(target=wrap(), args=(args,)) - p.start() - p.join() - out = open(stdout_path, 'r').read() - err = open(stderr_path, 'r').read() - os.unlink(stdout_path) - os.unlink(stderr_path) - return p.exitcode, out, err - def test_unsupported_arg(self): with self.assertRaises(SystemExit): self.run_ws(['-x=unknown']) def test_version_argument(self): - exitcode, out, err = self.run_ws_process(['--version']) - self.assertEqual(0, exitcode) - self.assertEqual('', out) - self.assertNotEqual('', err) - self.assertRegexpMatches(err, "[0-9]+\.[0-9]+\.[0-9]+") + err = io.BytesIO() + out = io.BytesIO() + with tutil.redirected_streams(stdout=out, stderr=err): + with self.assertRaises(SystemExit): + self.run_ws(['--version']) + self.assertEqual(out.getvalue(), '') + self.assertRegexpMatches(err.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+")