mirror of
https://github.com/powerline/powerline.git
synced 2025-09-23 09:59:25 +02:00
Check whether values have marks recursively
This commit is contained in:
parent
f8bea417fe
commit
1cc1e35624
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user