<s> import unittest <EOL> from bottle import Jinja2Template , jinja2_template , jinja2_view , touni <EOL> from tools import warn <EOL> from test . tools import chdir <EOL> class TestJinja2Template ( unittest . TestCase ) : <EOL> def test_string ( self ) : <EOL> """<STR_LIT>""" <EOL> t = Jinja2Template ( '<STR_LIT>' ) . render ( var = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , '<STR_LIT>' . join ( t ) ) <EOL> def test_file ( self ) : <EOL> """<STR_LIT>""" <EOL> with chdir ( __file__ ) : <EOL> t = Jinja2Template ( name = '<STR_LIT>' , lookup = [ '<STR_LIT:.>' ] ) . render ( var = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , '<STR_LIT>' . join ( t ) ) <EOL> def test_name ( self ) : <EOL> """<STR_LIT>""" <EOL> with chdir ( __file__ ) : <EOL> t = Jinja2Template ( name = '<STR_LIT>' , lookup = [ '<STR_LIT>' ] ) . render ( var = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , '<STR_LIT>' . join ( t ) ) <EOL> def test_notfound ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( Exception , Jinja2Template , name = "<STR_LIT>" ) <EOL> def test_error ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( Exception , Jinja2Template , '<STR_LIT>' ) <EOL> def test_inherit ( self ) : <EOL> """<STR_LIT>""" <EOL> with chdir ( __file__ ) : <EOL> t = Jinja2Template ( name = '<STR_LIT>' , lookup = [ '<STR_LIT>' ] ) . render ( ) <EOL> self . assertEqual ( '<STR_LIT>' , '<STR_LIT>' . join ( t ) ) <EOL> def test_custom_filters ( self ) : <EOL> """<STR_LIT>""" <EOL> from bottle import jinja2_template as template <EOL> settings = dict ( filters = { "<STR_LIT>" : lambda var : touni ( "<STR_LIT>" ) . join ( ( touni ( '<STR_LIT:*>' ) , var , touni ( '<STR_LIT:*>' ) ) ) } ) <EOL> t = Jinja2Template ( "<STR_LIT>" , ** settings ) <EOL> self . assertEqual ( "<STR_LIT>" , t . render ( var = "<STR_LIT>" ) ) <EOL> def test_custom_tests ( self ) : <EOL> """<STR_LIT>""" <EOL> from bottle import jinja2_template as template <EOL> TEMPL = touni ( "<STR_LIT>" ) <EOL> settings = dict ( tests = { "<STR_LIT>" : lambda x : False if x % <NUM_LIT:2> else True } ) <EOL> t = Jinja2Template ( TEMPL , ** settings ) <EOL> self . assertEqual ( "<STR_LIT>" , t . render ( var = <NUM_LIT:2> ) ) <EOL> self . assertEqual ( "<STR_LIT>" , t . render ( var = <NUM_LIT:1> ) ) <EOL> def test_template_shortcut ( self ) : <EOL> result = jinja2_template ( '<STR_LIT>' , var = '<STR_LIT>' ) <EOL> self . assertEqual ( touni ( '<STR_LIT>' ) , result ) <EOL> def test_view_decorator ( self ) : <EOL> @ jinja2_view ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> return dict ( var = '<STR_LIT>' ) <EOL> self . assertEqual ( touni ( '<STR_LIT>' ) , test ( ) ) <EOL> try : <EOL> import jinja2 <EOL> except ImportError : <EOL> warn ( "<STR_LIT>" ) <EOL> del TestJinja2Template </s>
