Django

Code

Changeset 3176

Show
Ignore:
Timestamp:
06/20/06 00:29:19 (2 years ago)
Author:
mtredinnick
Message:

Added regressions tests to ensure that one-to-one and many-to-many fields
continue to interact properly. Refs #1064. Refs #1506.

Files:

Legend:

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

    r3133 r3176  
    1010MODEL_TESTS_DIR_NAME = 'modeltests' 
    1111OTHER_TESTS_DIR = "othertests" 
     12REGRESSION_TESTS_DIR_NAME = 'regressiontests' 
    1213TEST_DATABASE_NAME = 'django_test_db' 
    1314 
     
    2021 
    2122MODEL_TEST_DIR = os.path.join(os.path.dirname(__file__), MODEL_TESTS_DIR_NAME) 
     23REGRESSION_TEST_DIR = os.path.join(os.path.dirname(__file__), REGRESSION_TESTS_DIR_NAME) 
    2224 
    2325ALWAYS_INSTALLED_APPS = [ 
     
    3335 
    3436def get_test_models(): 
    35     return [f for f in os.listdir(MODEL_TEST_DIR) if not f.startswith('__init__') and not f.startswith('.')] 
     37    return [(MODEL_TESTS_DIR_NAME, f) for f in os.listdir(MODEL_TEST_DIR) if not f.startswith('__init__') and not f.startswith('.')] +\ 
     38        [(REGRESSION_TESTS_DIR_NAME, f) for f in os.listdir(REGRESSION_TEST_DIR) if not f.startswith('__init__') and not f.startswith('.')] 
    3639 
    3740class DjangoDoctestRunner(doctest.DocTestRunner): 
     
    9093 
    9194        # Manually set INSTALLED_APPS to point to the test models. 
    92         settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS + [MODEL_TESTS_DIR_NAME + '.' + a for a in get_test_models()] 
     95        settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS + ['.'.join(a) for a in get_test_models()] 
    9396 
    9497        # Manually set DEBUG = False. 
     
    111114        if self.which_tests: 
    112115            # Only run the specified tests. 
    113             bad_models = [m for m in self.which_tests if m not in test_models] 
     116            bad_models = [m for m in self.which_tests if (MODEL_TESTS_DIR_NAME, m) not in test_models and (REGRESSION_TESTS_DIR_NAME, m) not in test_models] 
    114117            if bad_models: 
    115118                sys.stderr.write("Models not found: %s\n" % bad_models) 
    116119                sys.exit(1) 
    117120            else: 
    118                 test_models = self.which_tests 
     121                all_tests = [] 
     122                for test in self.which_tests: 
     123                    for loc in MODEL_TESTS_DIR_NAME, REGRESSION_TESTS_DIR_NAME: 
     124                        if (loc, test) in test_models: 
     125                            all_tests.append((loc, test)) 
     126                test_models = all_tests 
    119127 
    120128        self.output(0, "Running tests with database %r" % settings.DATABASE_ENGINE) 
     
    158166        # Run the tests for each test model. 
    159167        self.output(1, "Running app tests") 
    160         for model_name in test_models: 
     168        for model_dir, model_name in test_models: 
    161169            self.output(1, "%s model: Importing" % model_name) 
    162170            try: 
    163171                # TODO: Abstract this into a meta.get_app() replacement? 
    164                 mod = __import__(MODEL_TESTS_DIR_NAME + '.' + model_name + '.models', '', '', ['']) 
     172                mod = __import__(model_dir + '.' + model_name + '.models', '', '', ['']) 
    165173            except Exception, e: 
    166174                log_error(model_name, "Error while importing", ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
     
    169177            if not getattr(mod, 'error_log', None): 
    170178                # Model is not marked as an invalid model 
    171                 self.output(1, "%s model: Installing" % model_name
     179                self.output(1, "%s.%s model: Installing" % (model_dir, model_name)
    172180                management.install(mod) 
    173181 
     
    180188                # has side effects on doctest TestRunner class. 
    181189                runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 
    182                 self.output(1, "%s model: Running tests" % model_name
     190                self.output(1, "%s.%s model: Running tests" % (model_dir, model_name)
    183191                runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
    184192            else: 
    185193                # Check that model known to be invalid is invalid for the right reasons. 
    186                 self.output(1, "%s model: Validating" % model_name
     194                self.output(1, "%s.%s model: Validating" % (model_dir, model_name)
    187195 
    188196                from cStringIO import StringIO