def to_xml_string(test_suites, prettyprint=True, encoding=None):
        """
        Returns the string representation of the JUnit XML document.
        @param encoding: The encoding of the input.
        @return: unicode string
        """

        try:
            iter(test_suites)
        except TypeError:
            raise Exception('test_suites must be a list of test suites')

        xml_element = ET.Element("testsuites")
        attributes = defaultdict(int)
        for ts in test_suites:
            ts_xml = ts.build_xml_doc(encoding=encoding)
            for key in ['failures', 'errors', 'tests', 'disabled']:
                attributes[key] += int(ts_xml.get(key, 0))
            for key in ['time']:
                attributes[key] += float(ts_xml.get(key, 0))
            xml_element.append(ts_xml)
        for key, value in iteritems(attributes):
            xml_element.set(key, str(value))

        xml_string = ET.tostring(xml_element, encoding=encoding)
        # is encoded now
        xml_string = TestSuite._clean_illegal_xml_chars(
            xml_string.decode(encoding or 'utf-8'))
        # is unicode now

        if prettyprint:
            # minidom.parseString() works just on correctly encoded binary strings
            xml_string = xml_string.encode(encoding or 'utf-8')
            xml_string = xml.dom.minidom.parseString(xml_string)
            # toprettyxml() produces unicode if no encoding is being passed or binary string with an encoding
            xml_string = xml_string.toprettyxml(encoding=encoding)
            if encoding:
                xml_string = xml_string.decode(encoding)
            # is unicode now
        return xml_string
def to_xml_string ( test_suites , prettyprint = True , encoding = None ) : try : iter ( test_suites ) except TypeError : raise Exception ( 'test_suites must be a list of test suites' ) xml_element = ET . Element ( "testsuites" ) attributes = defaultdict ( int ) for ts in test_suites : ts_xml = ts . build_xml_doc ( encoding = encoding ) for key in [ 'failures' , 'errors' , 'tests' , 'disabled' ] : attributes [ key ] += int ( ts_xml . get ( key , 0 ) ) for key in [ 'time' ] : attributes [ key ] += float ( ts_xml . get ( key , 0 ) ) xml_element . append ( ts_xml ) for key , value in iteritems ( attributes ) : xml_element . set ( key , str ( value ) ) xml_string = ET . tostring ( xml_element , encoding = encoding ) xml_string = TestSuite . _clean_illegal_xml_chars ( xml_string . decode ( encoding or 'utf-8' ) ) if prettyprint : xml_string = xml_string . encode ( encoding or 'utf-8' ) xml_string = xml . dom . minidom . parseString ( xml_string ) xml_string = xml_string . toprettyxml ( encoding = encoding ) if encoding : xml_string = xml_string . decode ( encoding ) return xml_string
Returns the string representation of the JUnit XML document.
        @param encoding: The encoding of the input.
        @return: unicode string