<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> from optparse import make_option <EOL> from django . core . management . base import BaseCommand <EOL> from windmill . authoring import djangotest <EOL> import logging <EOL> LOG = logging . getLogger ( __name__ ) <EOL> DEFAULT_PORT = <NUM_LIT> <EOL> class ServerContainer ( object ) : <EOL> """<STR_LIT>""" <EOL> port = DEFAULT_PORT <EOL> def start_test_server ( self ) : <EOL> djangotest . start_test_server ( self , "<STR_LIT:127.0.0.1>" , self . port ) <EOL> stop_test_server = djangotest . stop_test_server <EOL> class Command ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> type = int , <EOL> default = DEFAULT_PORT , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> def setup_test_db ( self ) : <EOL> """<STR_LIT>""" <EOL> import south . management . commands <EOL> south . management . commands . patch_for_test_db_setup ( ) <EOL> from django . db import connection <EOL> connection . creation . create_test_db ( <NUM_LIT:0> ) <EOL> def start_helper_servers ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def stop_helper_servers ( self ) : <EOL> self . cluster . shutdown ( ) <EOL> def handle ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> from windmill . bin import admin_lib <EOL> from windmill . conf import global_settings <EOL> import nose <EOL> self . setup_test_db ( ) <EOL> server_container = ServerContainer ( ) <EOL> server_container . start_test_server ( ) <EOL> LOG . info ( "<STR_LIT>" % server_container . server_thread . port ) <EOL> self . start_helper_servers ( ) <EOL> global_settings . TEST_URL = '<STR_LIT>' % server_container . server_thread . port <EOL> global_settings . START_FIREFOX = True <EOL> admin_lib . configure_global_settings ( logging_on = False ) <EOL> windmill_obj = admin_lib . setup ( ) <EOL> nose_args = self . find_modules ( ) <EOL> LOG . info ( "<STR_LIT>" + repr ( nose_args ) ) <EOL> if "<STR_LIT>" in sys . argv : <EOL> nose_args . extend ( sys . argv [ sys . argv . index ( "<STR_LIT>" ) + <NUM_LIT:1> : ] ) <EOL> res = nose . run ( argv = nose_args ) <EOL> self . stop_helper_servers ( ) <EOL> server_container . stop_test_server ( ) <EOL> admin_lib . teardown ( windmill_obj ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> if res : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def find_modules ( self ) : <EOL> """<STR_LIT>""" <EOL> import django . conf <EOL> names = [ ] <EOL> for app in django . conf . settings . INSTALLED_APPS : <EOL> name = app + "<STR_LIT:.>" + "<STR_LIT>" <EOL> try : <EOL> __import__ ( name ) <EOL> names . append ( name ) <EOL> except ImportError : <EOL> pass <EOL> return names </s>
