#NEWLINE# def test_thread_mix( self ) : #NEWLINE# #INDENT# XML = self . etree . XML #NEWLINE# Element = self . etree . Element #NEWLINE# SubElement = self . etree . SubElement #NEWLINE# tostring = self . etree . tostring #NEWLINE# xml = _bytes ( '<a><b>B</b><c xmlns="test">C</c></a>' ) #NEWLINE# root = XML ( xml ) #NEWLINE# fragment = XML ( _bytes ( '<other><tags/></other>' ) ) #NEWLINE# result = self . etree . Element ( '{myns}root' , att = 'someval' ) #NEWLINE# def run_XML( ) : #NEWLINE# #INDENT# thread_root = XML ( xml ) #NEWLINE# result . append ( thread_root [ 0 ] ) #NEWLINE# result . append ( thread_root [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# def run_parse( ) : #NEWLINE# #INDENT# thread_root = self . etree . parse ( BytesIO ( xml ) ) . getroot ( ) #NEWLINE# result . append ( thread_root [ 0 ] ) #NEWLINE# result . append ( thread_root [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# def run_move_main( ) : #NEWLINE# #INDENT# result . append ( fragment [ 0 ] ) #NEWLINE# #UNINDENT# def run_build( ) : #NEWLINE# #INDENT# result . append ( Element ( '{myns}foo' , attrib = { #NEWLINE# #INDENT# '{test}attr' : 'val' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# SubElement ( result , '{otherns}tasty' ) #NEWLINE# #UNINDENT# def run_xslt( ) : #NEWLINE# #INDENT# style = XML ( _bytes ( '    <xsl:stylesheet version="1.0"\n        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n      <xsl:template match="*">\n        <xsl:copy><foo><xsl:value-of select="/a/b/text()" /></foo></xsl:copy>\n      </xsl:template>\n    </xsl:stylesheet>' ) ) #NEWLINE# st = etree . XSLT ( style ) #NEWLINE# result . append ( st ( root ) . getroot ( ) ) #NEWLINE# #UNINDENT# for test in ( run_XML , run_parse , run_move_main , run_xslt , run_build ) : #NEWLINE# #INDENT# tostring ( result ) #NEWLINE# self . _run_thread ( test ) #NEWLINE# #UNINDENT# self . assertEqual ( _bytes ( '<ns0:root xmlns:ns0="myns" att="someval"><b>B</b><c xmlns="test">C</c><b>B</b><c xmlns="test">C</c><tags/><a><foo>B</foo></a><ns0:foo xmlns:ns1="test" ns1:attr="val"/><ns1:tasty xmlns:ns1="otherns"/></ns0:root>' ) , tostring ( result ) ) #NEWLINE# def strip_first( ) : #NEWLINE# #INDENT# root = Element ( 'newroot' ) #NEWLINE# root . append ( result [ 0 ] ) #NEWLINE# #UNINDENT# while len ( test ) : #NEWLINE# #INDENT# self . _run_thread ( strip_first ) #NEWLINE# #UNINDENT# self . assertEqual ( _bytes ( '<ns0:root xmlns:ns0="myns" att="someval"/>' ) , tostring ( result ) )