diff --git a/novaclient/tests/test_utils.py b/novaclient/tests/test_utils.py index 87aadea76..ad0dff5e7 100644 --- a/novaclient/tests/test_utils.py +++ b/novaclient/tests/test_utils.py @@ -125,6 +125,31 @@ class _FakeResult(object): class PrintResultTestCase(test_utils.TestCase): + @mock.patch('sys.stdout', six.StringIO()) + def test_print_dict(self): + dict = {'key': 'value'} + utils.print_dict(dict) + self.assertEqual(sys.stdout.getvalue(), + '+----------+-------+\n' + '| Property | Value |\n' + '+----------+-------+\n' + '| key | value |\n' + '+----------+-------+\n') + + @mock.patch('sys.stdout', six.StringIO()) + def test_print_dict_wrap(self): + dict = {'key1': 'not wrapped', + 'key2': 'this will be wrapped'} + utils.print_dict(dict, wrap=16) + self.assertEqual(sys.stdout.getvalue(), + '+----------+--------------+\n' + '| Property | Value |\n' + '+----------+--------------+\n' + '| key1 | not wrapped |\n' + '| key2 | this will be |\n' + '| | wrapped |\n' + '+----------+--------------+\n') + @mock.patch('sys.stdout', six.StringIO()) def test_print_list_sort_by_str(self): objs = [_FakeResult("k1", 1), diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index bf9095bca..d83a01447 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1372,7 +1372,7 @@ def do_unshelve(cs, args): def do_diagnostics(cs, args): """Retrieve server diagnostics.""" server = _find_server(cs, args.server) - utils.print_dict(cs.servers.diagnostics(server)[1]) + utils.print_dict(cs.servers.diagnostics(server)[1], wrap=80) @utils.arg('server', metavar='', help='Name or ID of server.') diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 0c10e73f5..c11e1fcbf 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -1210,7 +1210,7 @@ def do_unrescue(cs, args): def do_diagnostics(cs, args): """Retrieve server diagnostics.""" server = _find_server(cs, args.server) - utils.print_dict(cs.servers.diagnostics(server)[1]) + utils.print_dict(cs.servers.diagnostics(server)[1], wrap=80) @utils.arg('server', metavar='', help='Name or ID of server.')