def dump_xml(self, output_dir):
self.buffer = False<EOL>if not os.path.exists(output_dir):<EOL><INDENT>os.makedirs(output_dir)<EOL><DEDENT>with open(os.path.join(output_dir, '<STR_LIT>'), '<STR_LIT:w>') as output:<EOL><INDENT>document = XMLGenerator(output, '<STR_LIT:utf-8>')<EOL>document.startDocument()<EOL>document.startElement('<STR_LIT>', AttributesImpl({}))<EOL>suites = groupby(<EOL>self.testInfos, key=lambda test_info: self.test_case_name(test_info.test_method)<EOL>)<EOL>for suite_name, suite in suites:<EOL><INDENT>document.startElement('<STR_LIT>',<EOL>AttributesImpl({'<STR_LIT:name>': suite_name}))<EOL>for test_info in suite:<EOL><INDENT>document.startElement('<STR_LIT>', AttributesImpl({<EOL>'<STR_LIT>': suite_name,<EOL>'<STR_LIT:name>': self.test_method_name(test_info.test_method),<EOL>'<STR_LIT:time>': '<STR_LIT>' % (<EOL>test_info.end_time - test_info.start_time<EOL>).total_seconds()<EOL>}))<EOL>if test_info.result == TestInfo.RESULT.ERROR:<EOL><INDENT>document.startElement('<STR_LIT:error>', AttributesImpl({<EOL>'<STR_LIT:message>': smart_text(test_info.err[<NUM_LIT:1>])<EOL>}))<EOL>document.characters(self._exc_info_to_string(test_info.err, test_info.test_method))<EOL>document.endElement('<STR_LIT:error>')<EOL><DEDENT>elif test_info.result == TestInfo.RESULT.FAILURE:<EOL><INDENT>document.startElement('<STR_LIT>', AttributesImpl({<EOL>'<STR_LIT:message>': smart_text(test_info.err[<NUM_LIT:1>])<EOL>}))<EOL>document.characters(<EOL>self._exc_info_to_string(test_info.err, test_info.test_method).decode('<STR_LIT:utf-8>')<EOL>)<EOL>document.endElement('<STR_LIT>')<EOL><DEDENT>elif test_info.result == TestInfo.RESULT.UNEXPECTED_SUCCESS:<EOL><INDENT>document.startElement('<STR_LIT:error>', AttributesImpl({<EOL>'<STR_LIT:message>': '<STR_LIT>'<EOL>}))<EOL>document.endElement('<STR_LIT:error>')<EOL><DEDENT>elif test_info.result == TestInfo.RESULT.SKIPPED:<EOL><INDENT>document.startElement('<STR_LIT>', AttributesImpl({}))<EOL>document.characters(test_info.reason)<EOL>document.endElement('<STR_LIT>')<EOL><DEDENT>if test_info.stdout:<EOL><INDENT>document.startElement('<STR_LIT>', AttributesImpl({}))<EOL>document.characters(test_info.stdout)<EOL>document.endElement('<STR_LIT>')<EOL><DEDENT>if test_info.stderr:<EOL><INDENT>document.startElement('<STR_LIT>', AttributesImpl({}))<EOL>document.characters(test_info.stderr)<EOL>document.endElement('<STR_LIT>')<EOL><DEDENT>document.endElement('<STR_LIT>')<EOL><DEDENT>document.endElement('<STR_LIT>')<EOL><DEDENT>document.endElement('<STR_LIT>')<EOL>document.endDocument()<EOL><DEDENT>
Dumps test result to xml