X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fee8873d0c5eeec1bd838161357679de1a3fe0cb..ebb2559b3a09636ff687316bbe512e0e8a86b168:/sdk/python/tests/test_arv_copy.py diff --git a/sdk/python/tests/test_arv_copy.py b/sdk/python/tests/test_arv_copy.py index 4be212c73b..e291ee05f2 100644 --- a/sdk/python/tests/test_arv_copy.py +++ b/sdk/python/tests/test_arv_copy.py @@ -1,45 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import multiprocessing +import io import os import sys import tempfile import unittest import arvados.commands.arv_copy as arv_copy +import arvados_testutil as tutil class ArvCopyTestCase(unittest.TestCase): def run_copy(self, args): sys.argv = ['arv-copy'] + args return arv_copy.main() - def run_copy_process(self, args): - _, stdout_path = tempfile.mkstemp() - _, stderr_path = tempfile.mkstemp() - def wrap(): - def wrapper(): - sys.argv = ['arv-copy'] + args - sys.stdout = open(stdout_path, 'w') - sys.stderr = open(stderr_path, 'w') - arv_copy.main() - return wrapper - p = multiprocessing.Process(target=wrap()) - 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_copy(['-x=unknown']) def test_version_argument(self): - exitcode, out, err = self.run_copy_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_copy(['--version']) + self.assertEqual(out.getvalue(), '') + self.assertRegexpMatches(err.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+")