#NEWLINE# def test_xslt_resolver_url_building( self ) : #NEWLINE# #INDENT# assertEqual = self . assertEqual #NEWLINE# called = { #NEWLINE# #INDENT# 'count' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# expected_url = None #NEWLINE# class TestResolver ( etree . Resolver ) : #NEWLINE# #INDENT# def resolve( self , url , id , context ) : #NEWLINE# #INDENT# assertEqual ( url , expected_url ) #NEWLINE# called [ 'count' ] += 1 #NEWLINE# return self . resolve_string ( '<CALLED/>' , context ) #NEWLINE# #UNINDENT# #UNINDENT# stylesheet_xml = _bytes ( '<xsl:stylesheet version="1.0"\n   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\n   xmlns:l="local">\n  <xsl:template match="/">\n    <xsl:copy-of select="document(\'test.xml\')"/>\n  </xsl:template>\n</xsl:stylesheet>\n' ) #NEWLINE# parser = etree . XMLParser ( ) #NEWLINE# parser . resolvers . add ( TestResolver ( ) ) #NEWLINE# expected_url = 'test.xml' #NEWLINE# xslt = etree . XSLT ( etree . XML ( stylesheet_xml , parser ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 0 ) #NEWLINE# result = xslt ( etree . XML ( '<a/>' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 1 ) #NEWLINE# called [ 'count' ] = 0 #NEWLINE# expected_url = 'MY/BASE/test.xml' #NEWLINE# xslt = etree . XSLT ( etree . XML ( stylesheet_xml , parser , base_url = os . path . join ( 'MY' , 'BASE' , 'FILE' ) ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 0 ) #NEWLINE# result = xslt ( etree . XML ( '<a/>' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 1 ) #NEWLINE# called [ 'count' ] = 0 #NEWLINE# expected_url = 'http://server.com/BASE/DIR/test.xml' #NEWLINE# xslt = etree . XSLT ( etree . XML ( stylesheet_xml , parser , base_url = 'http://server.com/BASE/DIR/FILE' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 0 ) #NEWLINE# result = xslt ( etree . XML ( '<a/>' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 1 ) #NEWLINE# called [ 'count' ] = 0 #NEWLINE# expected_url = 'file://BASE/DIR/test.xml' #NEWLINE# xslt = etree . XSLT ( etree . XML ( stylesheet_xml , parser , base_url = 'file://BASE/DIR/FILE' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 0 ) #NEWLINE# result = xslt ( etree . XML ( '<a/>' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 1 )