1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-07-06 20:22:22 +00:00
senpy/senpy/utils.py
J. Fernando Sánchez 85aef3d15f Improved shelf tests
Refactored template tests
2017-08-22 16:33:21 +02:00

26 lines
961 B
Python

from . import models
def check_template(indict, template):
if isinstance(template, dict) and isinstance(indict, dict):
for k, v in template.items():
if k not in indict:
return '{} not in {}'.format(k, indict)
check_template(indict[k], v)
elif isinstance(template, list) and isinstance(indict, list):
if len(indict) != len(template):
raise models.Error('Different size for {} and {}'.format(indict, template))
for e in template:
found = False
for i in indict:
try:
check_template(i, e)
found = True
except models.Error as ex:
continue
if not found:
raise models.Error('{} not found in {}'.format(e, indict))
else:
if indict != template:
raise models.Error('{} and {} are different'.format(indict, template))