From adaab46bf7e04f8e202c79e690e865bc321f188a Mon Sep 17 00:00:00 2001 From: Dong Wang Date: Mon, 11 Sep 2017 14:15:34 +0800 Subject: [PATCH] Fix pungi-koji --version Signed-off-by: dowang --- bin/pungi-koji | 7 ++----- tests/helpers.py | 5 +++++ tests/test_arguments.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tests/test_arguments.py diff --git a/bin/pungi-koji b/bin/pungi-koji index 79ff331f..fc338e44 100755 --- a/bin/pungi-koji +++ b/bin/pungi-koji @@ -130,7 +130,8 @@ def main(): ) parser.add_argument( "--version", - action="store_true", + action="version", + version=get_full_version(), help="output version information and exit", ) parser.add_argument( @@ -173,10 +174,6 @@ def main(): fail_to_start(msg) parser.error(msg) - if opts.version: - print("pungi %s" % get_full_version()) - sys.exit(0) - if opts.target_dir and not opts.compose_dir: opts.target_dir = os.path.abspath(opts.target_dir) if not os.path.isdir(opts.target_dir): diff --git a/tests/helpers.py b/tests/helpers.py index be6ac6d9..165c91ff 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -9,6 +9,7 @@ except ImportError: import tempfile import shutil import errno +import imp from pungi.util import get_arch_variant_data from pungi import paths, checks @@ -190,3 +191,7 @@ def load_config(data={}, **kwargs): conf.update(data) conf.update(kwargs) return conf + + +def load_bin(name): + return imp.load_source('pungi_cli_fake_' + name, os.path.dirname(__file__) + "/../bin/" + name) \ No newline at end of file diff --git a/tests/test_arguments.py b/tests/test_arguments.py new file mode 100644 index 00000000..aebc431b --- /dev/null +++ b/tests/test_arguments.py @@ -0,0 +1,19 @@ +import mock +import unittest +import six +import pungi + +from helpers import load_bin + +cli = load_bin("pungi-koji") + + +class PungiKojiTestCase(unittest.TestCase): + + @mock.patch('sys.argv', new=['prog', '--version']) + @mock.patch('sys.stderr', new_callable=six.StringIO) + @mock.patch('pungi_cli_fake_pungi-koji.get_full_version', return_value='a-b-c.111') + def test_version(self, get_full_version, stderr): + with self.assertRaises(SystemExit): + cli.main() + self.assertMultiLineEqual(stderr.getvalue(), 'a-b-c.111\n') \ No newline at end of file