Refactor result merging code
@@ -31,42 +31,38 @@ class Merger(SuiteVisitor):
self.result.errors.add(merged.errors)
def start_suite(self, suite):
- try:
- self.current = self._find_suite(self.current, suite.name)
- except IndexError:
+ if self.current is None:
+ old = self._find_root(suite.name)
+ else:
+ old = self._find(self.current.suites, suite.name)
+ if old is not None:
+ old.starttime = old.endtime = None
+ self.current = old
+ else:
suite.message = self._create_add_message(suite, suite=True)
self.current.suites.append(suite)
- return False
-
- def _find_suite(self, parent, name):
- if not parent:
- suite = self._find_root(name)
- else:
- suite = self._find(parent.suites, name)
- suite.starttime = suite.endtime = None
- return suite
+ return bool(old)
def _find_root(self, name):
root = self.result.suite
if root.name != name:
- raise DataError("Cannot merge outputs containing different root "
- "suites. Original suite is '%s' and merged is "
- "'%s'." % (root.name, name))
+ raise DataError("Cannot merge outputs containing different root suites. "
+ "Original suite is '%s' and merged is '%s'."
+ % (root.name, name))
return root
def _find(self, items, name):
for item in items:
if item.name == name:
return item
- raise IndexError
+ return None
def end_suite(self, suite):
self.current = self.current.parent
def visit_test(self, test):
- try:
old = self._find(self.current.tests, test.name)
- except IndexError:
+ if old is None:
test.message = self._create_add_message(test)
self.current.tests.append(test)
else:
