X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fee8873d0c5eeec1bd838161357679de1a3fe0cb..22f9af1104fa45e95ef3cd8b5a770fc0b9ed0fd3:/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..521c46ee34 100644 --- a/sdk/python/tests/test_arv_ws.py +++ b/sdk/python/tests/test_arv_ws.py @@ -1,6 +1,8 @@ -#!/usr/bin/env python +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 -import multiprocessing +from __future__ import absolute_import import os import sys import tempfile @@ -8,36 +10,19 @@ import unittest import arvados.errors as arv_error import arvados.commands.ws as arv_ws +from . import arvados_testutil as tutil -class ArvWsTestCase(unittest.TestCase): +class ArvWsTestCase(unittest.TestCase, tutil.VersionChecker): 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]+") + with tutil.redirected_streams( + stdout=tutil.StringIO, stderr=tutil.StringIO) as (out, err): + with self.assertRaises(SystemExit): + self.run_ws(['--version']) + self.assertVersionOutput(out, err)