<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import hashlib <EOL> import os <EOL> import textwrap <EOL> from google . apputils import basetest <EOL> from googleapis . codegen import django_helpers <EOL> from googleapis . codegen import template_helpers <EOL> from django import template as django_template <EOL> class TemplateHelpersTest ( basetest . TestCase ) : <EOL> _TEST_DATA_DIR = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> def testExtractCommentPrefix ( self ) : <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> template_helpers . _ExtractCommentPrefix ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> template_helpers . _ExtractCommentPrefix ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> template_helpers . _ExtractCommentPrefix ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT:#>' , <EOL> template_helpers . _ExtractCommentPrefix ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> template_helpers . _ExtractCommentPrefix ( '<STR_LIT>' ) ) <EOL> def testDivideIntoBlocks ( self ) : <EOL> test = """<STR_LIT>""" <EOL> blocks = [ ] <EOL> for block in template_helpers . _DivideIntoBlocks ( test . split ( '<STR_LIT:\n>' ) , <EOL> '<STR_LIT>' ) : <EOL> blocks . append ( block ) <EOL> self . assertEquals ( <NUM_LIT:3> , len ( blocks ) ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( blocks [ <NUM_LIT:0> ] ) ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( blocks [ <NUM_LIT:1> ] ) ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( blocks [ <NUM_LIT:2> ] ) ) <EOL> def testCommentFragment ( self ) : <EOL> value = '<STR_LIT>' * <NUM_LIT:15> <EOL> indent = <NUM_LIT:6> <EOL> expected = value [ : <NUM_LIT> ] + '<STR_LIT:\n>' + ( '<STR_LIT:U+0020>' * indent ) + '<STR_LIT>' + value [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> self . assertEquals ( expected , <EOL> template_helpers . java_comment_fragment ( value , indent ) ) <EOL> def testCommentBlockJavaDoc ( self ) : <EOL> alphabet = '<STR_LIT>' <EOL> value = """<STR_LIT>""" % ( alphabet , alphabet , alphabet , alphabet , alphabet ) <EOL> expected = """<STR_LIT>""" % ( alphabet , alphabet , alphabet , alphabet , alphabet ) <EOL> self . assertEquals ( expected , template_helpers . block_comment ( value ) ) <EOL> value = """<STR_LIT>""" % ( alphabet , alphabet , alphabet , alphabet , alphabet ) <EOL> expected = """<STR_LIT>""" % ( alphabet , alphabet , alphabet , alphabet , alphabet ) <EOL> self . assertEquals ( expected , template_helpers . block_comment ( value ) ) <EOL> value = '<STR_LIT>' % ( ( alphabet , ) * <NUM_LIT:4> ) <EOL> expected = '<STR_LIT>' % ( ( alphabet , ) * <NUM_LIT:4> ) <EOL> self . assertEquals ( expected , template_helpers . block_comment ( value ) ) <EOL> def testCommentBlockPerLanguage ( self ) : <EOL> text = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> tmpl_tmpl = textwrap . dedent ( """<STR_LIT>""" ) <EOL> def TestLanguage ( language ) : <EOL> lang_defaults = template_helpers . _language_defaults [ language ] <EOL> comment_start = lang_defaults [ template_helpers . _COMMENT_START ] <EOL> line_width = lang_defaults [ template_helpers . _LINE_WIDTH ] <EOL> source = tmpl_tmpl % ( language , comment_start ) <EOL> result = django_helpers . _DjangoRenderTemplateSource ( <EOL> source , { '<STR_LIT:text>' : text } ) <EOL> for line in result . splitlines ( ) : <EOL> len_line = len ( line ) <EOL> self . assertTrue ( len_line <= line_width , <EOL> '<STR_LIT>' % ( <EOL> len_line , line_width , language ) ) <EOL> for language in sorted ( template_helpers . _language_defaults ) : <EOL> TestLanguage ( language ) <EOL> def testNoblanklines ( self ) : <EOL> self . assertEquals ( '<STR_LIT>' , template_helpers . noblanklines ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , template_helpers . noblanklines ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , template_helpers . noblanklines ( '<STR_LIT>' ) ) <EOL> def _GetContext ( self , data = None ) : <EOL> return django_template . Context ( data or { } ) <EOL> def testCollapseNewLines ( self ) : <EOL> context = self . _GetContext ( ) <EOL> class NodesList ( object ) : <EOL> def __init__ ( self , ret ) : <EOL> self . _ret = ret <EOL> def render ( self , unused_context ) : <EOL> return self . _ret <EOL> collapse_node = template_helpers . CollapsedNewLinesNode ( NodesList ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , collapse_node . render ( context ) ) <EOL> collapse_node = template_helpers . CollapsedNewLinesNode ( NodesList ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , collapse_node . render ( context ) ) <EOL> collapse_node = template_helpers . CollapsedNewLinesNode ( NodesList ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , collapse_node . render ( context ) ) <EOL> collapse_node = template_helpers . CollapsedNewLinesNode ( <EOL> NodesList ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , collapse_node . render ( context ) ) <EOL> collapse_node = template_helpers . CollapsedNewLinesNode ( <EOL> NodesList ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , collapse_node . render ( context ) ) <EOL> def testDocCommentBlocks ( self ) : <EOL> def Render ( language , text , block ) : <EOL> context = self . _GetContext ( ) <EOL> lang_node = template_helpers . LanguageNode ( language ) <EOL> lang_node . render ( context ) <EOL> doc_comment_node = template_helpers . DocCommentNode ( <EOL> text = text , comment_type = '<STR_LIT>' , wrap_blocks = block ) <EOL> return doc_comment_node . render ( context ) <EOL> s1 = [ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' ] <EOL> s2 = '<STR_LIT>' <EOL> text = '<STR_LIT:\n>' . join ( [ '<STR_LIT>' . join ( s1 ) , s2 ] ) <EOL> no_blocks = Render ( '<STR_LIT>' , text , False ) <EOL> with_blocks = Render ( '<STR_LIT>' , text , True ) <EOL> self . assertNotEqual ( no_blocks , with_blocks ) <EOL> self . assertTrue ( ( '<STR_LIT>' % s2 ) in no_blocks ) <EOL> self . assertTrue ( s1 [ <NUM_LIT:1> ] + '<STR_LIT:U+0020>' + s2 in with_blocks ) <EOL> def testWrapInComment ( self ) : <EOL> text = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = textwrap . dedent ( """<STR_LIT>""" ) <EOL> for should_wrap in ( True , False ) : <EOL> wrapped = template_helpers . _WrapInComment ( <EOL> text , wrap_blocks = should_wrap , start_prefix = '<STR_LIT>' , <EOL> continue_prefix = '<STR_LIT>' , <EOL> comment_end = '<STR_LIT>' , begin_tag = '<STR_LIT>' , end_tag = '<STR_LIT>' , <EOL> available_width = <NUM_LIT> ) <EOL> self . assertEquals ( expected , wrapped ) <EOL> def testDocCommmentsEol ( self ) : <EOL> source_tmpl = textwrap . dedent ( """<STR_LIT>""" ) <EOL> for should_block in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> source = source_tmpl . replace ( '<STR_LIT>' , should_block ) <EOL> template = django_template . Template ( source ) <EOL> context = self . _GetContext ( { <EOL> '<STR_LIT:p>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> } } ) <EOL> rendered = template . render ( context ) <EOL> expected = ( <EOL> '<STR_LIT:\n>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEquals ( expected , rendered , '<STR_LIT>' % should_block ) <EOL> def testDocComments ( self ) : <EOL> def TryDocComment ( language , input_text , expected ) : <EOL> context = self . _GetContext ( ) <EOL> lang_node = template_helpers . LanguageNode ( language ) <EOL> lang_node . render ( context ) <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:50> <EOL> doc_comment_node = template_helpers . DocCommentNode ( <EOL> text = input_text , comment_type = '<STR_LIT>' ) <EOL> self . assertEquals ( expected , doc_comment_node . render ( context ) ) <EOL> alphabet = '<STR_LIT>' <EOL> value = '<STR_LIT:%s>' % alphabet <EOL> expected = '<STR_LIT>' % alphabet <EOL> TryDocComment ( '<STR_LIT>' , value , expected ) <EOL> TryDocComment ( '<STR_LIT>' , value , expected ) <EOL> value = '<STR_LIT>' <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % value ) <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % value ) <EOL> value = '<STR_LIT>' <EOL> expected_expansion = '<STR_LIT>' <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % expected_expansion ) <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % expected_expansion ) <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % expected_expansion ) <EOL> TryDocComment ( '<STR_LIT>' , value , <EOL> '<STR_LIT>' % expected_expansion ) <EOL> value = '<STR_LIT>' % ( alphabet , alphabet , alphabet ) <EOL> expected = '<STR_LIT>' % ( alphabet , alphabet , alphabet ) <EOL> TryDocComment ( '<STR_LIT>' , value , expected ) <EOL> TryDocComment ( '<STR_LIT>' , value , expected ) <EOL> value = alphabet <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % value ) <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % value ) <EOL> value = '<STR_LIT>' % ( alphabet , alphabet , alphabet ) <EOL> expected_expansion = '<STR_LIT>' % ( alphabet , alphabet , alphabet ) <EOL> TryDocComment ( '<STR_LIT>' , value , <EOL> '<STR_LIT>' % expected_expansion ) <EOL> expected_expansion = '<STR_LIT>' % ( alphabet , alphabet , alphabet ) <EOL> TryDocComment ( '<STR_LIT>' , value , '<STR_LIT>' % expected_expansion ) <EOL> def testCallTemplate ( self ) : <EOL> source = '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { <EOL> '<STR_LIT>' : self . _TEST_DATA_DIR , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' <EOL> } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testCallTemplateOutOfDirectory ( self ) : <EOL> source = '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { <EOL> '<STR_LIT>' : os . path . join ( self . _TEST_DATA_DIR , '<STR_LIT>' ) , <EOL> } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testCallTemplateWithEqualsSyntax ( self ) : <EOL> source = '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { <EOL> '<STR_LIT>' : self . _TEST_DATA_DIR , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' <EOL> } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testCallTemplateRestoreVar ( self ) : <EOL> """<STR_LIT>""" <EOL> source = '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { <EOL> '<STR_LIT>' : self . _TEST_DATA_DIR , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' , <EOL> '<STR_LIT:foo>' : '<STR_LIT>' <EOL> } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testParamList ( self ) : <EOL> source = """<STR_LIT>""" <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testParamEscaping ( self ) : <EOL> source = """<STR_LIT>""" <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> source = """<STR_LIT>""" <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( <EOL> { '<STR_LIT:foo>' : '<STR_LIT>' } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> source = '<STR_LIT>' + source <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( <EOL> { '<STR_LIT:foo>' : '<STR_LIT>' } ) ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> source = """<STR_LIT>""" <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( <EOL> { '<STR_LIT>' : self . _TEST_DATA_DIR , <EOL> '<STR_LIT:foo>' : '<STR_LIT>' } ) ) . strip ( ) <EOL> self . assertEquals ( '<STR_LIT>' , rendered ) <EOL> def testImportWithoutManager ( self ) : <EOL> expected = """<STR_LIT>""" <EOL> source = '<STR_LIT>' + expected + '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( { '<STR_LIT:x>' : { } } ) ) <EOL> self . assertEquals ( expected , rendered ) <EOL> def testNoEol ( self ) : <EOL> def TryIt ( source , expected , ctxt = None ) : <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( ctxt ) ) <EOL> self . assertEquals ( expected , rendered ) <EOL> source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = '<STR_LIT>' <EOL> TryIt ( source , expected , { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:x>' : '<STR_LIT:foo>' , '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = '<STR_LIT>' <EOL> TryIt ( source , expected , { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> def testNoBlank ( self ) : <EOL> def TryIt ( source , expected , ctxt = None ) : <EOL> template = django_template . Template ( source ) <EOL> rendered = template . render ( self . _GetContext ( ctxt ) ) <EOL> self . assertEquals ( expected , rendered ) <EOL> source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> TryIt ( source , expected , { } ) <EOL> source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> TryIt ( source , expected , { } ) <EOL> def testNestedNoBlank ( self ) : <EOL> source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> expected = '<STR_LIT>' <EOL> template = django_template . Template ( source ) <EOL> self . assertEquals ( expected , template . render ( self . _GetContext ( { } ) ) ) <EOL> def testNoBlankRecurse ( self ) : <EOL> def TryIt ( source , expected ) : <EOL> ctxt = self . _GetContext ( { <EOL> '<STR_LIT>' : self . _TEST_DATA_DIR <EOL> } ) <EOL> template = django_template . Template ( source ) <EOL> gotten = template . render ( ctxt ) <EOL> self . assertEquals ( expected , gotten ) <EOL> recurse_source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> recurse_expected = '<STR_LIT>' <EOL> TryIt ( recurse_source , recurse_expected ) <EOL> norecurse_source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> norecurse_expected = '<STR_LIT>' <EOL> TryIt ( norecurse_source , norecurse_expected ) <EOL> recurse_source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> recurse_expected = '<STR_LIT>' <EOL> TryIt ( recurse_source , recurse_expected ) <EOL> norecurse_source = textwrap . dedent ( """<STR_LIT>""" ) <EOL> norecurse_expected = '<STR_LIT>' <EOL> TryIt ( norecurse_source , norecurse_expected ) <EOL> def testLiteral ( self ) : <EOL> def TryTestLiteral ( language , input_text , expected ) : <EOL> context = self . _GetContext ( { <EOL> '<STR_LIT:foo>' : '<STR_LIT>' , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> lang_node = template_helpers . LanguageNode ( language ) <EOL> lang_node . render ( context ) <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:50> <EOL> node = template_helpers . LiteralStringNode ( input_text ) <EOL> self . assertEquals ( expected , node . render ( context ) ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] , '<STR_LIT>' ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT:foo>' ] , '<STR_LIT>' ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT:bar>' ] , '<STR_LIT>' ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT:foo>' ] , '<STR_LIT>' ) <EOL> TryTestLiteral ( '<STR_LIT>' , [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] , """<STR_LIT>""" ) <EOL> def testCopyright ( self ) : <EOL> copyright_text = '<STR_LIT>' <EOL> expected_license_preamble = '<STR_LIT>' <EOL> template = django_template . Template ( <EOL> '<STR_LIT>' ) <EOL> context = self . _GetContext ( { <EOL> '<STR_LIT>' : self . _TEST_DATA_DIR , <EOL> '<STR_LIT>' : { } , <EOL> } ) <EOL> text_without_copyright = template . render ( context ) <EOL> license_pos = text_without_copyright . find ( expected_license_preamble ) <EOL> self . assertLess ( <NUM_LIT:3> , license_pos ) <EOL> self . assertEquals ( - <NUM_LIT:1> , text_without_copyright . find ( copyright_text ) ) <EOL> context [ '<STR_LIT>' ] [ '<STR_LIT>' ] = copyright_text <EOL> text_with_copyright = template . render ( context ) <EOL> license_pos_with_copyright = text_with_copyright . find ( <EOL> expected_license_preamble ) <EOL> self . assertLess ( license_pos , license_pos_with_copyright ) <EOL> copyright_pos = text_with_copyright . find ( copyright_text ) <EOL> self . assertEquals ( license_pos , copyright_pos ) <EOL> def testGetArgFromToken ( self ) : <EOL> template = django_template . Template ( '<STR_LIT>' ) <EOL> context = self . _GetContext ( { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , template . render ( context ) ) <EOL> for tag in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> try : <EOL> template = django_template . Template ( '<STR_LIT>' % tag ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except django_template . TemplateSyntaxError as e : <EOL> self . assertEquals ( '<STR_LIT>' % tag , str ( e ) ) <EOL> def testCache ( self ) : <EOL> loader = template_helpers . CachingTemplateLoader ( ) <EOL> template_dir = os . path . join ( self . _TEST_DATA_DIR , '<STR_LIT>' ) <EOL> test_path = os . path . join ( template_dir , '<STR_LIT>' ) <EOL> stable_path = os . path . join ( template_dir , '<STR_LIT>' ) <EOL> loader . GetTemplate ( test_path , template_dir ) <EOL> loader . GetTemplate ( stable_path , template_dir ) <EOL> self . assertTrue ( stable_path in loader . _cache ) <EOL> self . assertFalse ( test_path in loader . _cache ) <EOL> def testHalt ( self ) : <EOL> template = django_template . Template ( '<STR_LIT>' ) <EOL> context = self . _GetContext ( { } ) <EOL> self . assertRaises ( <EOL> template_helpers . Halt , template . render , context ) <EOL> template = django_template . Template ( '<STR_LIT>' ) <EOL> context = self . _GetContext ( { } ) <EOL> self . assertEquals ( '<STR_LIT:OK>' , template . render ( context ) ) <EOL> def testBool ( self ) : <EOL> source = '<STR_LIT>' <EOL> def Test ( language , x ) : <EOL> ctxt = self . _GetContext ( { '<STR_LIT>' : language , '<STR_LIT:x>' : x , '<STR_LIT:y>' : not x } ) <EOL> template = django_template . Template ( source ) <EOL> key = template_helpers . _BOOLEAN_LITERALS <EOL> vals = template_helpers . _language_defaults [ language ] . get ( <EOL> key , template_helpers . _defaults [ key ] ) <EOL> if x : <EOL> vals = vals [ : : - <NUM_LIT:1> ] <EOL> expected = '<STR_LIT:|>' . join ( vals ) <EOL> self . assertEquals ( expected , template . render ( ctxt ) ) <EOL> for language in template_helpers . _language_defaults : <EOL> for value in ( True , False , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> Test ( language , value ) <EOL> def testDivChecksum ( self ) : <EOL> source = '<STR_LIT>' <EOL> context = self . _GetContext ( ) <EOL> template = django_template . Template ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' + source + '<STR_LIT>' ) <EOL> checksum = hashlib . sha1 ( source ) . hexdigest ( ) <EOL> expected = ( '<STR_LIT>' % checksum + <EOL> source + <EOL> '<STR_LIT>' ) <EOL> self . assertEquals ( expected , template . render ( context ) ) <EOL> def testWrite ( self ) : <EOL> self . name_to_content = { } <EOL> def MyWriter ( name , content ) : <EOL> """<STR_LIT>""" <EOL> self . name_to_content [ name ] = content <EOL> template = django_template . Template ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> context = self . _GetContext ( { <EOL> template_helpers . FILE_WRITER : MyWriter , <EOL> '<STR_LIT>' : '<STR_LIT:x>' , <EOL> '<STR_LIT>' : '<STR_LIT:y>' , <EOL> } ) <EOL> self . assertEquals ( '<STR_LIT>' , template . render ( context ) ) <EOL> self . assertEquals ( '<STR_LIT:foo>' , self . name_to_content [ '<STR_LIT:x>' ] ) <EOL> self . assertEquals ( '<STR_LIT:bar>' , self . name_to_content [ '<STR_LIT:y>' ] ) <EOL> class TemplateGlobalsTest ( basetest . TestCase ) : <EOL> def testSetContext ( self ) : <EOL> self . assertIsNone ( template_helpers . GetCurrentContext ( ) ) <EOL> data = { '<STR_LIT:key>' : '<STR_LIT:value>' } <EOL> with template_helpers . SetCurrentContext ( data ) : <EOL> ctxt = template_helpers . GetCurrentContext ( ) <EOL> self . assertIsNotNone ( ctxt ) <EOL> self . assertEquals ( '<STR_LIT:value>' , ctxt [ '<STR_LIT:key>' ] ) <EOL> self . assertIsNone ( template_helpers . GetCurrentContext ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> basetest . main ( ) </s>
