From ca72c6b1cea5e81a4eb11c806efd6df818bb1f42 Mon Sep 17 00:00:00 2001 From: "P. Christeas" <> Date: Thu, 2 Sep 2010 13:30:25 +0200 Subject: [PATCH] [IMP] tools/yaml_import: Try to explain values of failed assertions When some assertion fails, eg. "a == 4" , try to break it down and eval the parts so that we see the real "8 == 4" data. bzr revid: odo@openerp.com-20100902113025-ef3gdit4r6ipwoxn --- bin/tools/yaml_import.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/tools/yaml_import.py b/bin/tools/yaml_import.py index 1e2c7409459..87fd2ff432c 100644 --- a/bin/tools/yaml_import.py +++ b/bin/tools/yaml_import.py @@ -250,6 +250,25 @@ class YamlInterpreter(object): if not success: msg = 'Assertion "%s" FAILED\ntest: %s\n' args = (assertion.string, test) + for aop in ('==', '!=', '<>', 'in', 'not in', '>=', '<=', '>', '<'): + if aop in test: + left, right = test.split(aop,1) + lmsg = '' + rmsg = '' + try: + lmsg = unsafe_eval(left, self.eval_context, RecordDictWrapper(record)) + except Exception, e: + lmsg = '' + + try: + rmsg = unsafe_eval(right, self.eval_context, RecordDictWrapper(record)) + except Exception, e: + rmsg = '' + + msg += 'values: ! %s %s %s' + args += ( lmsg, aop, rmsg ) + break + self._log_assert_failure(assertion.severity, msg, *args) return else: # all tests were successful for this assertion tag (no break)