Fix error when run with no arguments on Python 3
Python 3 changed the map built-in to return an iterable instead of a list. When tested in a boolean context, this always returns True, even if it would not return anything when iterated. Instead of the usage being printed, this error was printed: ERROR: 'Namespace' object has no attribute 'func' Use list comprehension instead to ensure that an iterable isn't returned Change-Id: Ie15f2fa8ee93ab26490e371133fa0f944430737b Closes-bug: 1295356
This commit is contained in:
parent
733f1e58d8
commit
656cf91f89
@ -785,7 +785,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
logger.debug(e, exc_info=1)
|
logger.debug(e, exc_info=1)
|
||||||
|
@ -257,3 +257,17 @@ class ShellTest(utils.TestCase):
|
|||||||
@mock.patch('novaclient.client.Client')
|
@mock.patch('novaclient.client.Client')
|
||||||
def test_v_unknown_service_type(self, mock_client):
|
def test_v_unknown_service_type(self, mock_client):
|
||||||
self._test_service_type('unknown', 'compute', 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())
|
||||||
|
Loading…
Reference in New Issue
Block a user