<s> import sys <EOL> import time <EOL> import os <EOL> import warnings <EOL> from django . conf import settings <EOL> from django . core import mail <EOL> from django . core . mail . backends import locmem <EOL> from django . test import signals <EOL> from django . template import Template <EOL> from django . utils . translation import deactivate <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> class Approximate ( object ) : <EOL> def __init__ ( self , val , places = <NUM_LIT:7> ) : <EOL> self . val = val <EOL> self . places = places <EOL> def __repr__ ( self ) : <EOL> return repr ( self . val ) <EOL> def __eq__ ( self , other ) : <EOL> if self . val == other : <EOL> return True <EOL> return round ( abs ( self . val - other ) , self . places ) == <NUM_LIT:0> <EOL> class ContextList ( list ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> if isinstance ( key , basestring ) : <EOL> for subcontext in self : <EOL> if key in subcontext : <EOL> return subcontext [ key ] <EOL> raise KeyError ( key ) <EOL> else : <EOL> return super ( ContextList , self ) . __getitem__ ( key ) <EOL> def __contains__ ( self , key ) : <EOL> try : <EOL> value = self [ key ] <EOL> except KeyError : <EOL> return False <EOL> return True <EOL> def instrumented_test_render ( self , context ) : <EOL> """<STR_LIT>""" <EOL> signals . template_rendered . send ( sender = self , template = self , context = context ) <EOL> return self . nodelist . render ( context ) <EOL> def setup_test_environment ( ) : <EOL> """<STR_LIT>""" <EOL> Template . original_render = Template . _render <EOL> Template . _render = instrumented_test_render <EOL> mail . original_SMTPConnection = mail . SMTPConnection <EOL> mail . SMTPConnection = locmem . EmailBackend <EOL> mail . original_email_backend = settings . EMAIL_BACKEND <EOL> settings . EMAIL_BACKEND = '<STR_LIT>' <EOL> mail . outbox = [ ] <EOL> deactivate ( ) <EOL> def teardown_test_environment ( ) : <EOL> """<STR_LIT>""" <EOL> Template . _render = Template . original_render <EOL> del Template . original_render <EOL> mail . SMTPConnection = mail . original_SMTPConnection <EOL> del mail . original_SMTPConnection <EOL> settings . EMAIL_BACKEND = mail . original_email_backend <EOL> del mail . original_email_backend <EOL> del mail . outbox <EOL> def get_warnings_state ( ) : <EOL> """<STR_LIT>""" <EOL> return warnings . filters [ : ] <EOL> def restore_warnings_state ( state ) : <EOL> """<STR_LIT>""" <EOL> warnings . filters = state [ : ] <EOL> def get_runner ( settings ) : <EOL> test_path = settings . TEST_RUNNER . split ( '<STR_LIT:.>' ) <EOL> if len ( test_path ) > <NUM_LIT:1> : <EOL> test_module_name = '<STR_LIT:.>' . join ( test_path [ : - <NUM_LIT:1> ] ) <EOL> else : <EOL> test_module_name = '<STR_LIT:.>' <EOL> test_module = __import__ ( test_module_name , { } , { } , test_path [ - <NUM_LIT:1> ] ) <EOL> test_runner = getattr ( test_module , test_path [ - <NUM_LIT:1> ] ) <EOL> return test_runner </s>
