|
|
|
@ -14,6 +14,30 @@ from ..api import API_PARAMS
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Plugin(models.Plugin):
|
|
|
|
|
def __init__(self, info=None):
|
|
|
|
|
"""
|
|
|
|
@ -37,6 +61,15 @@ class Plugin(models.Plugin):
|
|
|
|
|
def deactivate(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
|
for case in self.test_cases:
|
|
|
|
|
res = list(self.analyse_entry(models.Entry(case['entry']),
|
|
|
|
|
case['params']))
|
|
|
|
|
exp = case['expected']
|
|
|
|
|
if not isinstance(exp, list):
|
|
|
|
|
exp = [exp]
|
|
|
|
|
check_template(res, exp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SenpyPlugin = Plugin
|
|
|
|
|
|
|
|
|
|