<s> from mako . template import Template <EOL> from mako import lookup <EOL> from util import flatten_result , result_lines <EOL> from test import TemplateTest , eq_ <EOL> class NamespaceTest ( TemplateTest ) : <EOL> def test_inline_crossreference ( self ) : <EOL> self . _do_memory_test ( <EOL> """<STR_LIT>""" , <EOL> "<STR_LIT>" , <EOL> filters = flatten_result <EOL> ) <EOL> def test_inline_assignment ( self ) : <EOL> self . _do_memory_test ( <EOL> """<STR_LIT>""" , <EOL> "<STR_LIT>" , <EOL> filters = flatten_result <EOL> ) <EOL> def test_inline_arguments ( self ) : <EOL> self . _do_memory_test ( <EOL> """<STR_LIT>""" , <EOL> "<STR_LIT>" , <EOL> filters = flatten_result <EOL> ) <EOL> def test_inline_not_duped ( self ) : <EOL> self . _do_memory_test ( <EOL> """<STR_LIT>""" , <EOL> "<STR_LIT>" , <EOL> filters = flatten_result <EOL> ) <EOL> def test_dynamic ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT:a>' , """<STR_LIT>""" ) <EOL> collection . put_string ( '<STR_LIT:b>' , """<STR_LIT>""" ) <EOL> eq_ ( <EOL> flatten_result ( collection . get_template ( '<STR_LIT:a>' ) . render ( b_def = '<STR_LIT:b>' ) ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_template ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_module ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_module_2 ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_module_imports ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_module_imports_2 ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_context ( self ) : <EOL> """<STR_LIT>""" <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( x = "<STR_LIT>" ) ) == "<STR_LIT>" <EOL> def test_overload ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> collection . put_string ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( '<STR_LIT>' ) . render ( ) ) == "<STR_LIT>" <EOL> def test_getattr ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert flatten_result ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == "<STR_LIT>" <EOL> def test_in_def ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_in_remote_def ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_dont_pollute_self ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_inheritance ( self ) : <EOL> """<STR_LIT>""" <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_inheritance_two ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_attr ( self ) : <EOL> l = lookup . TemplateLookup ( ) <EOL> l . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> l . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( l . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:body>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def test_attr_raise ( self ) : <EOL> l = lookup . TemplateLookup ( ) <EOL> l . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> l . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> self . assertRaises ( AttributeError , l . get_template ( "<STR_LIT>" ) . render ) <EOL> def test_custom_tag_1 ( self ) : <EOL> template = Template ( """<STR_LIT>""" ) <EOL> assert result_lines ( template . render ( ) ) == [ '<STR_LIT>' ] <EOL> def test_custom_tag_2 ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def test_custom_tag_3 ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_custom_tag_case_sensitive ( self ) : <EOL> t = Template ( """<STR_LIT>""" ) <EOL> assert result_lines ( t . render ( ) ) == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_expr_grouping ( self ) : <EOL> """<STR_LIT>""" <EOL> template = Template ( """<STR_LIT>""" , input_encoding = '<STR_LIT:utf-8>' ) <EOL> assert result_lines ( template . render ( foo = '<STR_LIT>' , g = False ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_ccall ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_ccall_2 ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_import ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( bar = "<STR_LIT>" , x = "<STR_LIT>" ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def test_import_calledfromdef ( self ) : <EOL> l = lookup . TemplateLookup ( ) <EOL> l . put_string ( "<STR_LIT:a>" , """<STR_LIT>""" ) <EOL> l . put_string ( "<STR_LIT:b>" , """<STR_LIT>""" ) <EOL> t = l . get_template ( "<STR_LIT:b>" ) <EOL> assert flatten_result ( t . render ( ) ) == "<STR_LIT>" <EOL> def test_closure_import ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( bar = "<STR_LIT>" , x = "<STR_LIT>" ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def test_import_local ( self ) : <EOL> t = Template ( """<STR_LIT>""" ) <EOL> assert flatten_result ( t . render ( ) ) == "<STR_LIT>" <EOL> def test_ccall_import ( self ) : <EOL> collection = lookup . TemplateLookup ( ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> collection . put_string ( "<STR_LIT>" , """<STR_LIT>""" ) <EOL> assert result_lines ( collection . get_template ( "<STR_LIT>" ) . render ( ) ) == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] </s>
