From 1cc1e3562455c02d33e73f54c4cb1a9a8136f151 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 25 Aug 2014 00:38:04 +0400 Subject: [PATCH] Check whether values have marks recursively --- powerline/lint/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index 6f38de9b..af599245 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -45,18 +45,22 @@ def context_key(context): return key_sep.join((c[0] for c in context)) -def havemarks(*args): +def havemarks(*args, **kwargs): + origin = kwargs.get('origin', '') for i, v in enumerate(args): if not hasattr(v, 'mark'): - raise AssertionError('Value #{0} ({1!r}) has no attribute `mark`'.format(i, v)) + raise AssertionError('Value #{0}/{1} ({2!r}) has no attribute `mark`'.format(origin, i, v)) + if isinstance(v, dict): + for key, val in v.items(): + havemarks(key, val, origin=(origin + '[' + unicode(i) + ']/' + unicode(key))) + elif isinstance(v, list): + havemarks(*v, origin=(origin + '[' + unicode(i) + ']')) def context_has_marks(context): for i, v in enumerate(context): - if not hasattr(v[0], 'mark'): - raise AssertionError('Key #{0} ({1!r}) in context has no attribute `mark`'.format(i, v[0])) - if not hasattr(v[1], 'mark'): - raise AssertionError('Value #{0} ({1!r}) in context has no attribute `mark`'.format(i, v[1])) + havemarks(v[0], origin='context key') + havemarks(v[1], origin='context val') class EchoErr(object):