#NEWLINE# def setup_test_template_loader( templates_dict , use_cached_loader = False ) : #NEWLINE# #INDENT# '\n    Changes Django to only find templates from within a dictionary (where each\n    key is the template name and each value is the corresponding template\n    content to return).\n\n    Use meth:`restore_template_loaders` to restore the original loaders.\n    ' #NEWLINE# if hasattr ( loader , RESTORE_LOADERS_ATTR ) : #NEWLINE# #INDENT# raise Exception ( ( 'loader.%s already exists' % RESTORE_LOADERS_ATTR ) ) #NEWLINE# #UNINDENT# def test_template_loader( template_name , template_dirs = None ) : #NEWLINE# #INDENT# 'A custom template loader that loads templates from a dictionary.' #NEWLINE# try : #NEWLINE# #INDENT# return ( templates_dict [ template_name ] , ( 'test:%s' % template_name ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise TemplateDoesNotExist ( template_name ) #NEWLINE# #UNINDENT# #UNINDENT# if use_cached_loader : #NEWLINE# #INDENT# template_loader = cached . Loader ( ( 'test_template_loader' , ) ) #NEWLINE# template_loader . _cached_loaders = ( test_template_loader , ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# template_loader = test_template_loader #NEWLINE# #UNINDENT# setattr ( loader , RESTORE_LOADERS_ATTR , loader . template_source_loaders ) #NEWLINE# loader . template_source_loaders = ( template_loader , ) #NEWLINE# return template_loader