Django

Code

Changeset 4206

Show
Ignore:
Timestamp:
12/15/06 00:06:52 (2 years ago)
Author:
adrian
Message:

Changed runtests.py to set USE_I18N=True during test running, because the template tests assume it. Some template tests were failing because my personal settings have USE_I18N=False

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/runtests.py

    r3708 r4206  
    4141                models.append((loc, f)) 
    4242    return models 
    43                  
     43 
    4444class InvalidModelTestCase(unittest.TestCase): 
    4545    def __init__(self, model_label): 
    4646        unittest.TestCase.__init__(self) 
    4747        self.model_label = model_label 
    48          
     48 
    4949    def runTest(self): 
    5050        from django.core import management 
     
    5656        except Exception, e: 
    5757            self.fail('Unable to load invalid model module') 
    58          
     58 
    5959        s = StringIO() 
    6060        count = management.get_validation_errors(s, module) 
     
    7272def django_tests(verbosity, tests_to_run): 
    7373    from django.conf import settings 
    74     from django.db.models.loading import get_apps, load_app 
    7574 
    7675    old_installed_apps = settings.INSTALLED_APPS 
     
    7877    old_root_urlconf = settings.ROOT_URLCONF 
    7978    old_template_dirs = settings.TEMPLATE_DIRS 
    80      
     79    old_use_i18n = settings.USE_I18N 
     80 
    8181    # Redirect some settings for the duration of these tests 
    8282    settings.TEST_DATABASE_NAME = TEST_DATABASE_NAME 
     
    8484    settings.ROOT_URLCONF = 'urls' 
    8585    settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), TEST_TEMPLATE_DIR),) 
    86      
    87     # load all the ALWAYS_INSTALLED_APPS 
     86    settings.USE_I18N = True 
     87 
     88    # Load all the ALWAYS_INSTALLED_APPS. 
     89    # (This import statement is intentionally delayed until after we 
     90    # access settings because of the USE_I18N dependency.) 
     91    from django.db.models.loading import get_apps, load_app 
    8892    get_apps() 
    89      
     93 
    9094    # Load all the test model apps 
    9195    test_models = [] 
    92     for model_dir, model_name in get_test_models():         
     96    for model_dir, model_name in get_test_models(): 
    9397        model_label = '.'.join([model_dir, model_name]) 
    9498        try: 
    9599            # if the model was named on the command line, or 
    96             # no models were named (i.e., run all), import  
     100            # no models were named (i.e., run all), import 
    97101            # this model and add it to the list to test. 
    98102            if not tests_to_run or model_name in tests_to_run: 
     
    100104                    print "Importing model %s" % model_name 
    101105                mod = load_app(model_label) 
    102                 settings.INSTALLED_APPS.append(model_label)         
     106                settings.INSTALLED_APPS.append(model_label) 
    103107                test_models.append(mod) 
    104108        except Exception, e: 
    105109            sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
    106             continue     
     110            continue 
    107111 
    108112    # Add tests for invalid models 
     
    112116        if not tests_to_run or model_name in tests_to_run: 
    113117            extra_tests.append(InvalidModelTestCase(model_label)) 
    114      
     118 
    115119    # Run the test suite, including the extra validation tests. 
    116120    from django.test.simple import run_tests 
    117121    run_tests(test_models, verbosity, extra_tests=extra_tests) 
    118    
     122 
    119123    # Restore the old settings 
    120124    settings.INSTALLED_APPS = old_installed_apps 
     
    122126    settings.ROOT_URLCONF = old_root_urlconf 
    123127    settings.TEMPLATE_DIRS = old_template_dirs 
    124      
     128    settings.USE_I18N = old_use_i18n 
     129 
    125130if __name__ == "__main__": 
    126131    from optparse import OptionParser 
     
    129134    parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0', 
    130135        type='choice', choices=['0', '1', '2'], 
    131         help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')     
     136        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 
    132137    parser.add_option('--settings', 
    133138        help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.') 
     
    135140    if options.settings: 
    136141        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    137          
     142 
    138143    django_tests(int(options.verbosity), args)