diff options
| -rwxr-xr-x | repo | 16 | ||||
| -rw-r--r-- | tests/test_wrapper.py | 18 | ||||
| -rw-r--r-- | tox.ini | 5 |
3 files changed, 38 insertions, 1 deletions
| @@ -819,6 +819,7 @@ def _FindRepo(): | |||
| 819 | 819 | ||
| 820 | class _Options(object): | 820 | class _Options(object): |
| 821 | help = False | 821 | help = False |
| 822 | version = False | ||
| 822 | 823 | ||
| 823 | 824 | ||
| 824 | def _ParseArguments(args): | 825 | def _ParseArguments(args): |
| @@ -830,7 +831,8 @@ def _ParseArguments(args): | |||
| 830 | a = args[i] | 831 | a = args[i] |
| 831 | if a == '-h' or a == '--help': | 832 | if a == '-h' or a == '--help': |
| 832 | opt.help = True | 833 | opt.help = True |
| 833 | 834 | elif a == '--version': | |
| 835 | opt.version = True | ||
| 834 | elif not a.startswith('-'): | 836 | elif not a.startswith('-'): |
| 835 | cmd = a | 837 | cmd = a |
| 836 | arg = args[i + 1:] | 838 | arg = args[i + 1:] |
| @@ -877,6 +879,16 @@ def _Help(args): | |||
| 877 | sys.exit(1) | 879 | sys.exit(1) |
| 878 | 880 | ||
| 879 | 881 | ||
| 882 | def _Version(): | ||
| 883 | """Show version information.""" | ||
| 884 | print('<repo not installed>') | ||
| 885 | print('repo launcher version %s' % ('.'.join(str(x) for x in VERSION),)) | ||
| 886 | print(' (from %s)' % (__file__,)) | ||
| 887 | print('git %s' % (ParseGitVersion().full,)) | ||
| 888 | print('Python %s' % sys.version) | ||
| 889 | sys.exit(0) | ||
| 890 | |||
| 891 | |||
| 880 | def _NotInstalled(): | 892 | def _NotInstalled(): |
| 881 | print('error: repo is not installed. Use "repo init" to install it here.', | 893 | print('error: repo is not installed. Use "repo init" to install it here.', |
| 882 | file=sys.stderr) | 894 | file=sys.stderr) |
| @@ -953,6 +965,8 @@ def main(orig_args): | |||
| 953 | _Usage() | 965 | _Usage() |
| 954 | if cmd == 'help': | 966 | if cmd == 'help': |
| 955 | _Help(args) | 967 | _Help(args) |
| 968 | if opt.version or cmd == 'version': | ||
| 969 | _Version() | ||
| 956 | if not cmd: | 970 | if not cmd: |
| 957 | _NotInstalled() | 971 | _NotInstalled() |
| 958 | if cmd == 'init' or cmd == 'gitc-init': | 972 | if cmd == 'init' or cmd == 'gitc-init': |
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index e574946b..61636b26 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py | |||
| @@ -26,6 +26,14 @@ from pyversion import is_python3 | |||
| 26 | import wrapper | 26 | import wrapper |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | if is_python3(): | ||
| 30 | from unittest import mock | ||
| 31 | from io import StringIO | ||
| 32 | else: | ||
| 33 | import mock | ||
| 34 | from StringIO import StringIO | ||
| 35 | |||
| 36 | |||
| 29 | def fixture(*paths): | 37 | def fixture(*paths): |
| 30 | """Return a path relative to tests/fixtures. | 38 | """Return a path relative to tests/fixtures. |
| 31 | """ | 39 | """ |
| @@ -48,6 +56,16 @@ class RepoWrapperUnitTest(RepoWrapperTestCase): | |||
| 48 | """Tests helper functions in the repo wrapper | 56 | """Tests helper functions in the repo wrapper |
| 49 | """ | 57 | """ |
| 50 | 58 | ||
| 59 | def test_version(self): | ||
| 60 | """Make sure _Version works.""" | ||
| 61 | with self.assertRaises(SystemExit) as e: | ||
| 62 | with mock.patch('sys.stdout', new_callable=StringIO) as stdout: | ||
| 63 | with mock.patch('sys.stderr', new_callable=StringIO) as stderr: | ||
| 64 | self.wrapper._Version() | ||
| 65 | self.assertEqual(0, e.exception.code) | ||
| 66 | self.assertEqual('', stderr.getvalue()) | ||
| 67 | self.assertIn('repo launcher version', stdout.getvalue()) | ||
| 68 | |||
| 51 | def test_get_gitc_manifest_dir_no_gitc(self): | 69 | def test_get_gitc_manifest_dir_no_gitc(self): |
| 52 | """ | 70 | """ |
| 53 | Test reading a missing gitc config file | 71 | Test reading a missing gitc config file |
| @@ -20,3 +20,8 @@ envlist = py27, py36, py37, py38 | |||
| 20 | [testenv] | 20 | [testenv] |
| 21 | deps = pytest | 21 | deps = pytest |
| 22 | commands = {toxinidir}/run_tests | 22 | commands = {toxinidir}/run_tests |
| 23 | |||
| 24 | [testenv:py27] | ||
| 25 | deps = | ||
| 26 | mock | ||
| 27 | pytest | ||
