Check whether values have marks recursively

This commit is contained in:
ZyX 2014-08-25 00:38:04 +04:00
parent f8bea417fe
commit 1cc1e35624

View File

@ -45,18 +45,22 @@ def context_key(context):
return key_sep.join((c[0] for c in 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): for i, v in enumerate(args):
if not hasattr(v, 'mark'): 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): def context_has_marks(context):
for i, v in enumerate(context): for i, v in enumerate(context):
if not hasattr(v[0], 'mark'): havemarks(v[0], origin='context key')
raise AssertionError('Key #{0} ({1!r}) in context has no attribute `mark`'.format(i, v[0])) havemarks(v[1], origin='context val')
if not hasattr(v[1], 'mark'):
raise AssertionError('Value #{0} ({1!r}) in context has no attribute `mark`'.format(i, v[1]))
class EchoErr(object): class EchoErr(object):