<s> """<STR_LIT>""" <EOL> from django . conf import settings <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> settings . configure ( ) <EOL> import sys <EOL> import pkg_resources <EOL> import imp <EOL> import StringIO <EOL> import os . path <EOL> from django . template import TemplateDoesNotExist , Context <EOL> from django . template . loaders . eggs import Loader as EggLoader <EOL> from django . template import loader <EOL> from django . utils import unittest <EOL> class MockProvider ( pkg_resources . NullProvider ) : <EOL> def __init__ ( self , module ) : <EOL> pkg_resources . NullProvider . __init__ ( self , module ) <EOL> self . module = module <EOL> def _has ( self , path ) : <EOL> return path in self . module . _resources <EOL> def _isdir ( self , path ) : <EOL> return False <EOL> def get_resource_stream ( self , manager , resource_name ) : <EOL> return self . module . _resources [ resource_name ] <EOL> def _get ( self , path ) : <EOL> return self . module . _resources [ path ] . read ( ) <EOL> class MockLoader ( object ) : <EOL> pass <EOL> def create_egg ( name , resources ) : <EOL> """<STR_LIT>""" <EOL> egg = imp . new_module ( name ) <EOL> egg . __loader__ = MockLoader ( ) <EOL> egg . _resources = resources <EOL> sys . modules [ name ] = egg <EOL> class EggLoaderTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> pkg_resources . _provider_factories [ MockLoader ] = MockProvider <EOL> self . empty_egg = create_egg ( "<STR_LIT>" , { } ) <EOL> self . egg_1 = create_egg ( "<STR_LIT>" , { <EOL> os . path . normcase ( '<STR_LIT>' ) : StringIO . StringIO ( "<STR_LIT:y>" ) , <EOL> os . path . normcase ( '<STR_LIT>' ) : StringIO . StringIO ( "<STR_LIT:x>" ) , <EOL> } ) <EOL> self . _old_installed_apps = settings . INSTALLED_APPS <EOL> settings . INSTALLED_APPS = [ ] <EOL> def tearDown ( self ) : <EOL> settings . INSTALLED_APPS = self . _old_installed_apps <EOL> def test_empty ( self ) : <EOL> "<STR_LIT>" <EOL> settings . INSTALLED_APPS = [ '<STR_LIT>' ] <EOL> egg_loader = EggLoader ( ) <EOL> self . assertRaises ( TemplateDoesNotExist , egg_loader . load_template_source , "<STR_LIT>" ) <EOL> def test_non_existing ( self ) : <EOL> "<STR_LIT>" <EOL> settings . INSTALLED_APPS = [ '<STR_LIT>' ] <EOL> egg_loader = EggLoader ( ) <EOL> self . assertRaises ( TemplateDoesNotExist , egg_loader . load_template_source , "<STR_LIT>" ) <EOL> def test_existing ( self ) : <EOL> "<STR_LIT>" <EOL> settings . INSTALLED_APPS = [ '<STR_LIT>' ] <EOL> egg_loader = EggLoader ( ) <EOL> contents , template_name = egg_loader . load_template_source ( "<STR_LIT>" ) <EOL> self . assertEqual ( contents , "<STR_LIT:y>" ) <EOL> self . assertEqual ( template_name , "<STR_LIT>" ) <EOL> def test_not_installed ( self ) : <EOL> "<STR_LIT>" <EOL> settings . INSTALLED_APPS = [ ] <EOL> egg_loader = EggLoader ( ) <EOL> self . assertRaises ( TemplateDoesNotExist , egg_loader . load_template_source , "<STR_LIT>" ) <EOL> class CachedLoader ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . old_TEMPLATE_LOADERS = settings . TEMPLATE_LOADERS <EOL> settings . TEMPLATE_LOADERS = ( <EOL> ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) , <EOL> ) <EOL> def tearDown ( self ) : <EOL> settings . TEMPLATE_LOADERS = self . old_TEMPLATE_LOADERS <EOL> def test_templatedir_caching ( self ) : <EOL> "<STR_LIT>" <EOL> t1 , name = loader . find_template ( '<STR_LIT>' , ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' ) , ) ) <EOL> t2 , name = loader . find_template ( '<STR_LIT>' , ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' ) , ) ) <EOL> self . assertNotEqual ( t1 . render ( Context ( { } ) ) , t2 . render ( Context ( { } ) ) ) <EOL> class RenderToStringTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _old_TEMPLATE_DIRS = settings . TEMPLATE_DIRS <EOL> settings . TEMPLATE_DIRS = ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) , <EOL> ) <EOL> def tearDown ( self ) : <EOL> settings . TEMPLATE_DIRS = self . _old_TEMPLATE_DIRS <EOL> def test_basic ( self ) : <EOL> self . assertEqual ( loader . render_to_string ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_basic_context ( self ) : <EOL> self . assertEqual ( loader . render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:test>' } ) , '<STR_LIT>' ) <EOL> def test_existing_context_kept_clean ( self ) : <EOL> context = Context ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> output = loader . render_to_string ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> context_instance = context ) <EOL> self . assertEqual ( output , '<STR_LIT>' ) <EOL> self . assertEqual ( context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_empty_list ( self ) : <EOL> self . assertRaisesRegexp ( TemplateDoesNotExist , <EOL> '<STR_LIT>' , <EOL> loader . render_to_string , [ ] ) <EOL> def test_select_templates_from_empty_list ( self ) : <EOL> self . assertRaisesRegexp ( TemplateDoesNotExist , <EOL> '<STR_LIT>' , <EOL> loader . select_template , [ ] ) </s>
