<s> from django . test . simple import DjangoTestSuiteRunner <EOL> from django . conf import settings <EOL> from . import loading <EOL> from ... exceptions import ResourceNotFound <EOL> class CouchDbKitTestSuiteRunner ( DjangoTestSuiteRunner ) : <EOL> """<STR_LIT>""" <EOL> dbs = [ ] <EOL> def get_test_db_name ( self , dbname ) : <EOL> return "<STR_LIT>" % dbname <EOL> def get_test_db ( self , db ) : <EOL> test_db = db . copy ( ) <EOL> test_db [ '<STR_LIT>' ] = self . get_test_db_name ( test_db [ '<STR_LIT>' ] ) <EOL> return test_db <EOL> def setup_databases ( self , ** kwargs ) : <EOL> print "<STR_LIT>" <EOL> databases = getattr ( settings , "<STR_LIT>" , [ ] ) <EOL> if isinstance ( databases , ( list , tuple ) ) : <EOL> databases = dict ( <EOL> ( app_name , { '<STR_LIT>' : uri } ) for app_name , uri in databases <EOL> ) <EOL> self . dbs = dict ( <EOL> ( app , self . get_test_db ( db ) ) for app , db in databases . items ( ) <EOL> ) <EOL> old_handler = loading . couchdbkit_handler <EOL> couchdbkit_handler = loading . CouchdbkitHandler ( self . dbs ) <EOL> loading . couchdbkit_handler = couchdbkit_handler <EOL> loading . register_schema = couchdbkit_handler . register_schema <EOL> loading . get_schema = couchdbkit_handler . get_schema <EOL> loading . get_db = couchdbkit_handler . get_db <EOL> for app , value in old_handler . app_schema . items ( ) : <EOL> for name , cls in value . items ( ) : <EOL> cls . set_db ( loading . get_db ( app ) ) <EOL> return super ( CouchDbKitTestSuiteRunner , self ) . setup_databases ( ** kwargs ) <EOL> def teardown_databases ( self , old_config , ** kwargs ) : <EOL> deleted_databases = [ ] <EOL> skipcount = <NUM_LIT:0> <EOL> for app in self . dbs : <EOL> app_label = app . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> db = loading . get_db ( app_label ) <EOL> if db . dbname in deleted_databases : <EOL> skipcount += <NUM_LIT:1> <EOL> continue <EOL> try : <EOL> db . server . delete_db ( db . dbname ) <EOL> deleted_databases . append ( db . dbname ) <EOL> print "<STR_LIT>" % ( db . dbname , app_label ) <EOL> except ResourceNotFound : <EOL> print "<STR_LIT>" % ( db . dbname , app_label ) <EOL> if skipcount : <EOL> print "<STR_LIT>" % skipcount <EOL> return super ( CouchDbKitTestSuiteRunner , self ) . teardown_databases ( old_config , ** kwargs ) </s>
