11789: Merge branch 'master' into 11789-arvput-exclude-flag
[arvados.git] / sdk / python / tests / test_arv_ws.py
index 17706c19b655c66eb063cc046691bcd86143d143..521c46ee34e72df4c25fc3a7f0dcbe2cdce379b6 100644 (file)
@@ -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)