Launchpad automatic translations update.
[odoo/odoo.git] / bin / tools / yaml_import.py
index 0098e4e..6e5977d 100644 (file)
@@ -34,7 +34,8 @@ def is_comment(node):
     return isinstance(node, types.StringTypes)
 
 def is_assert(node):
-    return _is_yaml_mapping(node, yaml_tag.Assert)
+    return isinstance(node, yaml_tag.Assert) \
+        or _is_yaml_mapping(node, yaml_tag.Assert)
 
 def is_record(node):
     return _is_yaml_mapping(node, yaml_tag.Record)
@@ -105,7 +106,7 @@ class TestReport(object):
             success += self._report[severity][True]
             failure += self._report[severity][False]
         res.append("total\t%s\t%s" % (success, failure))
-        res.append("end of report (%s assertion(s) checked)" % success + failure)
+        res.append("end of report (%s assertion(s) checked)" % (success + failure))
         return "\n".join(res)
 
 class RecordDictWrapper(dict):
@@ -218,19 +219,22 @@ class YamlInterpreter(object):
         elif assertion.search:
             q = eval(assertion.search, self.eval_context)
             ids = self.pool.get(assertion.model).search(self.cr, self.uid, q, context=assertion.context)
-        if not ids:
+        else:
             raise YamlImportException('Nothing to assert: you must give either an id or a search criteria.')
         return ids
 
     def process_assert(self, node):
-        assertion, expressions = node.items()[0]
+        if isinstance(node, dict):
+            assertion, expressions = node.items()[0]
+        else:
+            assertion, expressions = node, []
 
         if self.isnoupdate(assertion) and self.mode != 'init':
             self.logger.warn('This assertion was not evaluated ("%s").' % assertion.string)
             return
         model = self.get_model(assertion.model)
         ids = self._get_assertion_id(assertion)
-        if assertion.count and len(ids) != assertion.count:
+        if assertion.count is not None and len(ids) != assertion.count:
             msg = 'assertion "%s" failed!\n'   \
                   ' Incorrect search count:\n' \
                   ' expected count: %d\n'      \
@@ -680,8 +684,12 @@ class YamlInterpreter(object):
         if node.auto:
             values['auto'] = eval(node.auto)
         if node.sxw:
-            sxw_content = misc.file_open(node.sxw).read()
-            values['report_sxw_content'] = sxw_content
+            sxw_file = misc.file_open(node.sxw)
+            try:
+                sxw_content = sxw_file.read()
+                values['report_sxw_content'] = sxw_content
+            finally:
+                sxw_file.close()
         if node.header:
             values['header'] = eval(node.header)
         values['multi'] = node.multi and eval(node.multi)