Merge "Fix error when run with no arguments on Python 3"

This commit is contained in:
Jenkins 2014-03-28 20:31:50 +00:00 committed by Gerrit Code Review
commit d85c24ff5a
2 changed files with 16 additions and 1 deletions

View File

@ -785,7 +785,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
def main():
try:
OpenStackComputeShell().main(map(strutils.safe_decode, sys.argv[1:]))
argv = [strutils.safe_decode(a) for a in sys.argv[1:]]
OpenStackComputeShell().main(argv)
except Exception as e:
logger.debug(e, exc_info=1)

View File

@ -257,3 +257,17 @@ class ShellTest(utils.TestCase):
@mock.patch('novaclient.client.Client')
def test_v_unknown_service_type(self, mock_client):
self._test_service_type('unknown', 'compute', mock_client)
@mock.patch('sys.argv', ['nova'])
@mock.patch('sys.stdout', six.StringIO())
@mock.patch('sys.stderr', six.StringIO())
def test_main_noargs(self):
# Ensure that main works with no command-line arguments
try:
novaclient.shell.main()
except SystemExit as exc:
self.fail('Unexpected SystemExit')
# We expect the normal usage as a result
self.assertIn('Command-line interface to the OpenStack Nova API',
sys.stdout.getvalue())