From: Eric Biagiotti Date: Tue, 2 Jul 2019 15:59:26 +0000 (-0400) Subject: 14965: Fixes test for checking the arvmount version X-Git-Tag: 2.0.0~248^2~32 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/ad085a257d057f604939b00a13eb72f99c52df17 14965: Fixes test for checking the arvmount version Arvados-DCO-1.1-Signed-off-by: --- diff --git a/services/fuse/arvados_fuse/command.py b/services/fuse/arvados_fuse/command.py index 76449729db..5283367532 100644 --- a/services/fuse/arvados_fuse/command.py +++ b/services/fuse/arvados_fuse/command.py @@ -34,7 +34,7 @@ class ArgumentParser(argparse.ArgumentParser): with "--". """) self.add_argument('--version', action='version', - version="%s %s" % (sys.argv[0], __version__), + version=u"%s %s" % (sys.argv[0], __version__), help='Print version and exit.') self.add_argument('mountpoint', type=str, help="""Mount point.""") self.add_argument('--allow-other', action='store_true', diff --git a/services/fuse/tests/test_command_args.py b/services/fuse/tests/test_command_args.py index bc18749f55..1962c03390 100644 --- a/services/fuse/tests/test_command_args.py +++ b/services/fuse/tests/test_command_args.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0 from __future__ import absolute_import +from __future__ import print_function import arvados import arvados_fuse import arvados_fuse.command @@ -185,11 +186,20 @@ class MountArgsTest(unittest.TestCase): self.assertEqual(True, self.mnt.listen_for_events) def test_version_argument(self): - orig, sys.stderr = sys.stderr, io.BytesIO() + # The argparse version action prints to stderr in Python 2 and stdout + # in Python 3.4 and up. Write both to the same stream so the test can pass + # in both cases. + origerr = sys.stderr + origout = sys.stdout + sys.stderr = io.StringIO() + sys.stdout = sys.stderr + with self.assertRaises(SystemExit): args = arvados_fuse.command.ArgumentParser().parse_args(['--version']) - self.assertRegexpMatches(sys.stderr.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+") - sys.stderr = orig + self.assertRegexpMatches(sys.stdout.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+") + sys.stderr.close() + sys.stderr = origerr + sys.stdout = origout @noexit @mock.patch('arvados.events.subscribe')