<s> from __future__ import unicode_literals <EOL> """<STR_LIT>""" <EOL> import logging <EOL> try : <EOL> from unittest2 import SkipTest <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> from unittest import SkipTest <EOL> import unittest <EOL> from test . test_environment import env , db_user , CLIENT_PEM <EOL> def suppress_tornado_warnings ( ) : <EOL> for name in [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> logger = logging . getLogger ( name ) <EOL> logger . setLevel ( logging . ERROR ) <EOL> class SkippedModule ( object ) : <EOL> def __init__ ( self , name , reason ) : <EOL> def runTest ( self ) : <EOL> raise SkipTest ( str ( reason ) ) <EOL> self . test_case = type ( <EOL> str ( name ) , <EOL> ( unittest . TestCase , ) , <EOL> { '<STR_LIT>' : runTest } ) <EOL> class MotorTestLoader ( unittest . TestLoader ) : <EOL> def __init__ ( self , avoid = None , reason = None ) : <EOL> super ( MotorTestLoader , self ) . __init__ ( ) <EOL> self . _avoid = [ ] <EOL> def avoid ( self , prefix , reason ) : <EOL> """<STR_LIT>""" <EOL> self . _avoid . append ( ( prefix , reason ) ) <EOL> def _get_module_from_name ( self , name ) : <EOL> for prefix , reason in self . _avoid : <EOL> if name . startswith ( prefix ) : <EOL> if unittest . __name__ == '<STR_LIT>' : <EOL> raise SkipTest ( reason ) <EOL> else : <EOL> return SkippedModule ( name , reason ) <EOL> return super ( MotorTestLoader , self ) . _get_module_from_name ( name ) <EOL> class MotorTestRunner ( unittest . TextTestRunner ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . tornado_warnings = kwargs . pop ( '<STR_LIT>' , False ) <EOL> super ( MotorTestRunner , self ) . __init__ ( * args , ** kwargs ) <EOL> def run ( self , test ) : <EOL> env . setup ( ) <EOL> if not self . tornado_warnings : <EOL> suppress_tornado_warnings ( ) <EOL> result = super ( MotorTestRunner , self ) . run ( test ) <EOL> env . teardown ( ) <EOL> return result <EOL> class MockRequestHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . n_written = <NUM_LIT:0> <EOL> def write ( self , data ) : <EOL> self . n_written += len ( data ) <EOL> def flush ( self ) : <EOL> pass </s>
