<s> import doctest <EOL> import os <EOL> import unittest <EOL> from genshi . core import Stream <EOL> from genshi . output import DocType <EOL> from genshi . template import MarkupTemplate , TextTemplate , NewTextTemplate <EOL> from genshi . template . plugin import ConfigurationError , MarkupTemplateEnginePlugin , TextTemplateEnginePlugin <EOL> PACKAGE = '<STR_LIT>' <EOL> class MarkupTemplateEnginePluginTestCase ( unittest . TestCase ) : <EOL> def test_init_no_options ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> self . assertEqual ( '<STR_LIT:utf-8>' , plugin . default_encoding ) <EOL> self . assertEqual ( '<STR_LIT:html>' , plugin . default_format ) <EOL> self . assertEqual ( None , plugin . default_doctype ) <EOL> self . assertEqual ( [ ] , plugin . loader . search_path ) <EOL> self . assertEqual ( True , plugin . loader . auto_reload ) <EOL> self . assertEqual ( <NUM_LIT> , plugin . loader . _cache . capacity ) <EOL> def test_init_with_loader_options ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:100>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> plugin . loader . search_path ) <EOL> self . assertEqual ( False , plugin . loader . auto_reload ) <EOL> self . assertEqual ( <NUM_LIT:100> , plugin . loader . _cache . capacity ) <EOL> def test_init_with_invalid_cache_size ( self ) : <EOL> self . assertRaises ( ConfigurationError , MarkupTemplateEnginePlugin , <EOL> options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_init_with_output_options ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( '<STR_LIT>' , plugin . default_encoding ) <EOL> self . assertEqual ( '<STR_LIT>' , plugin . default_format ) <EOL> self . assertEqual ( DocType . XHTML , plugin . default_doctype ) <EOL> def test_init_with_invalid_output_format ( self ) : <EOL> self . assertRaises ( ConfigurationError , MarkupTemplateEnginePlugin , <EOL> options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_init_with_invalid_doctype ( self ) : <EOL> self . assertRaises ( ConfigurationError , MarkupTemplateEnginePlugin , <EOL> options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_load_template_from_file ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , os . path . basename ( tmpl . filename ) ) <EOL> assert isinstance ( tmpl , MarkupTemplate ) <EOL> def test_load_template_from_string ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( None , template_string = """<STR_LIT>""" ) <EOL> self . assertEqual ( None , tmpl . filename ) <EOL> assert isinstance ( tmpl , MarkupTemplate ) <EOL> def test_transform_with_load ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> stream = plugin . transform ( { '<STR_LIT:message>' : '<STR_LIT>' } , tmpl ) <EOL> assert isinstance ( stream , Stream ) <EOL> def test_transform_without_load ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> stream = plugin . transform ( { '<STR_LIT:message>' : '<STR_LIT>' } , <EOL> PACKAGE + '<STR_LIT>' ) <EOL> assert isinstance ( stream , Stream ) <EOL> def test_render ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:message>' : '<STR_LIT>' } , template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def test_render_with_format ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:message>' : '<STR_LIT>' } , format = '<STR_LIT>' , <EOL> template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def test_render_with_doctype ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:message>' : '<STR_LIT>' } , template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def test_render_fragment_with_doctype ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:message>' : '<STR_LIT>' } , template = tmpl , <EOL> fragment = True ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def test_helper_functions ( self ) : <EOL> plugin = MarkupTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT>' : '<STR_LIT>' } , template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> class TextTemplateEnginePluginTestCase ( unittest . TestCase ) : <EOL> def test_init_no_options ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> self . assertEqual ( '<STR_LIT:utf-8>' , plugin . default_encoding ) <EOL> self . assertEqual ( '<STR_LIT:text>' , plugin . default_format ) <EOL> self . assertEqual ( [ ] , plugin . loader . search_path ) <EOL> self . assertEqual ( True , plugin . loader . auto_reload ) <EOL> self . assertEqual ( <NUM_LIT> , plugin . loader . _cache . capacity ) <EOL> def test_init_with_loader_options ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:100>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> plugin . loader . search_path ) <EOL> self . assertEqual ( False , plugin . loader . auto_reload ) <EOL> self . assertEqual ( <NUM_LIT:100> , plugin . loader . _cache . capacity ) <EOL> def test_init_with_output_options ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( '<STR_LIT>' , plugin . default_encoding ) <EOL> def test_init_with_new_syntax ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( options = { <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> } ) <EOL> self . assertEqual ( NewTextTemplate , plugin . template_class ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:foo>' : True } , template = tmpl ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , output ) <EOL> def test_load_template_from_file ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> assert isinstance ( tmpl , TextTemplate ) <EOL> self . assertEqual ( '<STR_LIT>' , os . path . basename ( tmpl . filename ) ) <EOL> def test_load_template_from_string ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( None , template_string = "<STR_LIT>" ) <EOL> self . assertEqual ( None , tmpl . filename ) <EOL> assert isinstance ( tmpl , TextTemplate ) <EOL> def test_transform_without_load ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> stream = plugin . transform ( { '<STR_LIT:message>' : '<STR_LIT>' } , <EOL> PACKAGE + '<STR_LIT>' ) <EOL> assert isinstance ( stream , Stream ) <EOL> def test_transform_with_load ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> stream = plugin . transform ( { '<STR_LIT:message>' : '<STR_LIT>' } , tmpl ) <EOL> assert isinstance ( stream , Stream ) <EOL> def test_render ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { '<STR_LIT:message>' : '<STR_LIT>' } , template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def test_helper_functions ( self ) : <EOL> plugin = TextTemplateEnginePlugin ( ) <EOL> tmpl = plugin . load_template ( PACKAGE + '<STR_LIT>' ) <EOL> output = plugin . render ( { } , template = tmpl ) <EOL> self . assertEqual ( """<STR_LIT>""" , output ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( MarkupTemplateEnginePluginTestCase , '<STR_LIT:test>' ) ) <EOL> suite . addTest ( unittest . makeSuite ( TextTemplateEnginePluginTestCase , '<STR_LIT:test>' ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
