def merge(a, b):
global loglevel<EOL>for child in b.iterchildren():<EOL><INDENT>if child.tag == '<STR_LIT>':<EOL><INDENT>source = child.get('<STR_LIT:source>')<EOL>suites = a.xpath('<STR_LIT>' % source)<EOL>if suites:<EOL><INDENT>merge(suites[<NUM_LIT:0>], child)<EOL><DEDENT>else:<EOL><INDENT>suites = a.xpath('<STR_LIT>')<EOL>child_id = child.get('<STR_LIT:id>')<EOL>parent_id = a.get('<STR_LIT:id>', '<STR_LIT>')<EOL>if parent_id:<EOL><INDENT>suite_id = '<STR_LIT>' % (parent_id, str(len(suites) + <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>suite_id = '<STR_LIT>' % str(len(suites) + <NUM_LIT:1>)<EOL><DEDENT>for node in child.xpath('<STR_LIT>' % child_id):<EOL><INDENT>node.set('<STR_LIT:id>', re.sub('<STR_LIT>' % child_id, suite_id,<EOL>node.get('<STR_LIT:id>')))<EOL><DEDENT>a.append(child)<EOL><DEDENT>if a.tag == '<STR_LIT>' and a.xpath('<STR_LIT>'):<EOL><INDENT>for merge_root in a.xpath('<STR_LIT>'):<EOL><INDENT>mergeable = etree.Element('<STR_LIT>')<EOL>for suite in a.xpath('<STR_LIT>'):<EOL><INDENT>mergeable.append(suite)<EOL><DEDENT>merge(merge_root, mergeable)<EOL><DEDENT><DEDENT><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>name = child.get('<STR_LIT:name>')<EOL>type_ = child.get('<STR_LIT:type>')<EOL>keywords = a.xpath('<STR_LIT>' % (name, type_))<EOL>if len(keywords) == <NUM_LIT:1>:<EOL><INDENT>merge(keywords[<NUM_LIT:0>], child)<EOL><DEDENT>elif len(keywords) > <NUM_LIT:1>:<EOL><INDENT>child_keywords = child.getparent().xpath(<EOL>'<STR_LIT>' % (name, type_))<EOL>child_position = child_keywords.index(child)<EOL>merge(keywords[min(child_position, len(keywords) - <NUM_LIT:1>)], child)<EOL><DEDENT>else:<EOL><INDENT>a.append(child)<EOL><DEDENT><DEDENT>elif child.tag == '<STR_LIT:test>':<EOL><INDENT>tests = a.xpath('<STR_LIT:test>')<EOL>child.set('<STR_LIT:id>', '<STR_LIT>' % (a.get('<STR_LIT:id>'), str(len(tests) + <NUM_LIT:1>)))<EOL>a.append(child)<EOL><DEDENT>elif child.tag == '<STR_LIT:status>':<EOL><INDENT>a.append(child)<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>statistics = a.xpath('<STR_LIT>')<EOL>if not statistics:<EOL><INDENT>a.append(child)<EOL><DEDENT>else:<EOL><INDENT>for grandchild in child.xpath('<STR_LIT>'):<EOL><INDENT>totals = a.xpath('<STR_LIT>')<EOL>if totals:<EOL><INDENT>merge(totals[<NUM_LIT:0>], grandchild)<EOL><DEDENT>else:<EOL><INDENT>statistics.append(child)<EOL><DEDENT><DEDENT>for grandchild in child.xpath('<STR_LIT>'):<EOL><INDENT>suites = a.xpath('<STR_LIT>')<EOL>if suites:<EOL><INDENT>merge(suites[<NUM_LIT:0>], grandchild)<EOL><DEDENT>else:<EOL><INDENT>statistics.append(child)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>stats = a.xpath('<STR_LIT>' % child.text)<EOL>if stats:<EOL><INDENT>stats[<NUM_LIT:0>].set('<STR_LIT>', str(int(stats[<NUM_LIT:0>].get('<STR_LIT>'))<EOL>+ int(child.get('<STR_LIT>'))))<EOL>stats[<NUM_LIT:0>].set('<STR_LIT>', str(int(stats[<NUM_LIT:0>].get('<STR_LIT>'))<EOL>+ int(child.get('<STR_LIT>'))))<EOL><DEDENT>else:<EOL><INDENT>suites = a.xpath('<STR_LIT>' % child.get('<STR_LIT:name>'))<EOL>if suites:<EOL><INDENT>child.set('<STR_LIT:id>', suites[<NUM_LIT:0>].get('<STR_LIT:id>'))<EOL><DEDENT>a.append(child)<EOL><DEDENT><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>errors = a.xpath('<STR_LIT>')<EOL>for grandchild in tuple(child.iterchildren()):<EOL><INDENT>try:<EOL><INDENT>level = int(getattr(logging, grandchild.get('<STR_LIT>')))<EOL><DEDENT>except (TypeError, AttributeError, ValueError):<EOL><INDENT>level = <NUM_LIT:0><EOL><DEDENT>if level < loglevel:<EOL><INDENT>child.remove(grandchild)<EOL><DEDENT><DEDENT>if not errors:<EOL><INDENT>a.append(child)<EOL><DEDENT>else:<EOL><INDENT>for grandchild in child.iterchildren():<EOL><INDENT>errors[<NUM_LIT:0>].append(grandchild)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Merge two unicode Robot Framework reports so that report 'b' is merged
    into report 'a'. This merge may not be complete and may be is lossy. Still,
    note that the original single test reports will remain untouched.