Commit 6e381262 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Fix minor test, warning & pep8 issues (Python 2.6)

A bug is fixed in the test of "add_subcmd" of "kamaki.cli.cmdtree".
A warning on using the deprecated "message" name in ClientError has been
dealt with.
Pep8 issues concerning the modified files are fixed.
parent 0f01bb76
......@@ -444,7 +444,8 @@ def update_parser_help(parser, cmd):
def print_error_message(cli_err, out=stderr):
errmsg = escape_ctrl_chars(('%s' % cli_err).strip('\n'))
errmsg = escape_ctrl_chars(('%s' % cli_err).strip('\n')).encode(
pref_enc, 'replace')
if cli_err.importance == 1:
errmsg = magenta(errmsg)
elif cli_err.importance == 2:
......@@ -454,7 +455,8 @@ def print_error_message(cli_err, out=stderr):
out.write(errmsg)
out.write('\n')
for errmsg in cli_err.details:
out.write('| %s\n' % escape_ctrl_chars(u'%s' % errmsg))
out.write('| %s\n' % escape_ctrl_chars(u'%s' % errmsg).encode(
pref_enc, 'replace'))
out.flush()
......
......@@ -31,7 +31,6 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
#from mock import patch, call
from unittest import TestCase
from itertools import product
......@@ -83,7 +82,7 @@ class Command(TestCase):
self.assertFalse(cmd.add_subcmd(subcmd))
self.assertTrue(len(cmd.subcommands) == 0)
else:
self.assertRaises(cmd.add_subcmd, subname, AttributeError)
self.assertRaises(AttributeError, cmd.add_subcmd, subname)
def test_get_subcmd(self):
cmd = cmdtree.Command('cmd')
......@@ -356,19 +355,19 @@ class CommandTree(TestCase):
self.assertRaises(KeyError, ctree.get_subcommands, 'cmd')
self._add_commands(ctree)
for s1, l2 in (
('', ['cmd', 'othercmd']),
('cmd', ['cmd0a', 'cmd0b', 'cmd0c']),
('cmd_cmd0a', ['cmd1a', 'cmd1b']),
('cmd_cmd0a_cmd1a', ['cmd2', ]),
('cmd_cmd0a_cmd1b', ['cmd2', ]),
('cmd_cmd0a_cmd1a_cmd2', []),
('cmd_cmd0a_cmd1b_cmd2', []),
('cmd_cmd0b', []),
('cmd_cmd0c', ['cmd1a', 'cmd1b']),
('cmd_cmd0c_cmd1a', []),
('cmd_cmd0c_cmd1b', ['cmd2', ]),
('cmd_cmd0c_cmd1b_cmd2', []),
('othercmd', [])):
('', ['cmd', 'othercmd']),
('cmd', ['cmd0a', 'cmd0b', 'cmd0c']),
('cmd_cmd0a', ['cmd1a', 'cmd1b']),
('cmd_cmd0a_cmd1a', ['cmd2', ]),
('cmd_cmd0a_cmd1b', ['cmd2', ]),
('cmd_cmd0a_cmd1a_cmd2', []),
('cmd_cmd0a_cmd1b_cmd2', []),
('cmd_cmd0b', []),
('cmd_cmd0c', ['cmd1a', 'cmd1b']),
('cmd_cmd0c_cmd1a', []),
('cmd_cmd0c_cmd1b', ['cmd2', ]),
('cmd_cmd0c_cmd1b_cmd2', []),
('othercmd', [])):
l1 = [cmd.path for cmd in ctree.get_subcommands(s1)]
l2 = ['_'.join([s1, i]) for i in l2] if s1 else l2
l1.sort(), l2.sort(), self.assertEqual(l1, l2)
......
......@@ -46,6 +46,7 @@ class CLIError(Exception):
"""
message += '' if message and message.endswith('\n') else '\n'
super(CLIError, self).__init__(message)
self.message = message
self.details = (list(details) if (
isinstance(details, list) or isinstance(details, tuple)) else [
'%s' % details]) if details else []
......@@ -55,7 +56,7 @@ class CLIError(Exception):
self.importance = 0
def __str__(self):
return u'%s' % getattr(self, 'message', '')
return self.message
class CLIUnimplemented(CLIError):
......
......@@ -92,11 +92,12 @@ class ClientError(Exception):
while message.endswith('\n\n'):
message = message[:-1]
super(ClientError, self).__init__(message)
self.message = message
self.status = status if isinstance(status, int) else 0
self.details = details if details else []
def __str__(self):
return u'%s' % getattr(self, 'message', '')
return self.message
class KamakiSSLError(ClientError):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment