204         Builds the XML document for the JUnit test suite. 
  205         Produces clean unicode strings and decodes non-unicode with the help of encoding. 
  206         @param encoding: Used to decode encoded strings. 
  207         @return: XML document with unicode string elements 
  211         test_suite_attributes = dict()
 
  212         test_suite_attributes[
'name'] = 
decode(self.
name, encoding)
 
  213         if any(c.assertions 
for c 
in self.
test_cases):
 
  214             test_suite_attributes[
'assertions'] = \
 
  215                 str(sum([int(c.assertions) 
for c 
in self.
test_cases if c.assertions]))
 
  216         test_suite_attributes[
'disabled'] = \
 
  217             str(len([c 
for c 
in self.
test_cases if not c.is_enabled]))
 
  218         test_suite_attributes[
'failures'] = \
 
  219             str(len([c 
for c 
in self.
test_cases if c.is_failure()]))
 
  220         test_suite_attributes[
'errors'] = \
 
  221             str(len([c 
for c 
in self.
test_cases if c.is_error()]))
 
  222         test_suite_attributes[
'skipped'] = \
 
  223             str(len([c 
for c 
in self.
test_cases if c.is_skipped()]))
 
  224         test_suite_attributes[
'time'] = \
 
  225             str(sum(c.elapsed_sec 
for c 
in self.
test_cases if c.elapsed_sec))
 
  226         test_suite_attributes[
'tests'] = str(len(self.
test_cases))
 
  229             test_suite_attributes[
'hostname'] = 
decode(self.
hostname, encoding)
 
  231             test_suite_attributes[
'id'] = 
decode(self.
id, encoding)
 
  233             test_suite_attributes[
'package'] = 
decode(self.
package, encoding)
 
  235             test_suite_attributes[
'timestamp'] = 
decode(
 
  238             test_suite_attributes[
'file'] = 
decode(self.
file, encoding)
 
  240             test_suite_attributes[
'log'] = 
decode(self.
log, encoding)
 
  242             test_suite_attributes[
'url'] = 
decode(self.
url, encoding)
 
  244         xml_element = ET.Element(
"testsuite", test_suite_attributes)
 
  248             props_element = ET.SubElement(xml_element, 
"properties")
 
  249             for k, v 
in self.properties.items():
 
  251                     'name': 
decode(k, encoding),
 
  252                     'value': 
decode(v, encoding)
 
  254                 ET.SubElement(props_element, 
"property", attrs)
 
  258             stdout_element = ET.SubElement(xml_element, 
"system-out")
 
  263             stderr_element = ET.SubElement(xml_element, 
"system-err")
 
  268             test_case_attributes = dict()
 
  269             test_case_attributes[
'name'] = 
decode(case.name, encoding)
 
  272                 test_case_attributes[
'assertions'] = 
"%d" % case.assertions
 
  274                 test_case_attributes[
'time'] = 
"%f" % case.elapsed_sec
 
  276                 test_case_attributes[
'timestamp'] = 
decode(
 
  277                     case.timestamp, encoding)
 
  279                 test_case_attributes[
'classname'] = 
decode(
 
  280                     case.classname, encoding)
 
  282                 test_case_attributes[
'status'] = 
decode(case.status, encoding)
 
  284                 test_case_attributes[
'class'] = 
decode(case.category, encoding)
 
  286                 test_case_attributes[
'file'] = 
decode(case.file, encoding)
 
  288                 test_case_attributes[
'line'] = 
decode(case.line, encoding)
 
  290                 test_case_attributes[
'log'] = 
decode(case.log, encoding)
 
  292                 test_case_attributes[
'url'] = 
decode(case.url, encoding)
 
  294             test_case_element = ET.SubElement(xml_element, 
"testcase",
 
  295                                               test_case_attributes)
 
  298             if case.is_failure():
 
  299                 attrs = {
'type': 
'failure'}
 
  300                 if case.failure_message:
 
  301                     attrs[
'message'] = 
decode(case.failure_message, encoding)
 
  302                 if case.failure_type:
 
  303                     attrs[
'type'] = 
decode(case.failure_type, encoding)
 
  304                 failure_element = ET.Element(
"failure", attrs)
 
  305                 if case.failure_output:
 
  306                     failure_element.text = 
decode(case.failure_output,
 
  308                 test_case_element.append(failure_element)
 
  312                 attrs = {
'type': 
'error'}
 
  313                 if case.error_message:
 
  314                     attrs[
'message'] = 
decode(case.error_message, encoding)
 
  316                     attrs[
'type'] = 
decode(case.error_type, encoding)
 
  317                 error_element = ET.Element(
"error", attrs)
 
  318                 if case.error_output:
 
  319                     error_element.text = 
decode(case.error_output, encoding)
 
  320                 test_case_element.append(error_element)
 
  323             if case.is_skipped():
 
  324                 attrs = {
'type': 
'skipped'}
 
  325                 if case.skipped_message:
 
  326                     attrs[
'message'] = 
decode(case.skipped_message, encoding)
 
  327                 skipped_element = ET.Element(
"skipped", attrs)
 
  328                 if case.skipped_output:
 
  329                     skipped_element.text = 
decode(case.skipped_output,
 
  331                 test_case_element.append(skipped_element)
 
  335                 stdout_element = ET.Element(
"system-out")
 
  336                 stdout_element.text = 
decode(case.stdout, encoding)
 
  337                 test_case_element.append(stdout_element)
 
  341                 stderr_element = ET.Element(
"system-err")
 
  342                 stderr_element.text = 
decode(case.stderr, encoding)
 
  343                 test_case_element.append(stderr_element)