Django

Code

Changeset 367

Show
Ignore:
Timestamp:
08/01/05 14:09:07 (3 years ago)
Author:
jacob
Message:

Added framework for writing non-model-based tests, and added tests for cache and templates
from the old django/tests location (which has been removed).

Files:

Legend:

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

    r348 r367  
    99 
    1010APP_NAME = 'testapp' 
     11OTHER_TESTS_DIR = "othertests" 
    1112TEST_DATABASE_NAME = 'django_test_db' 
    1213 
     
    1415def log_error(model_name, title, description): 
    1516    error_list.append({ 
    16         'title': "%r model: %s" % (model_name, title), 
     17        'title': "%r module: %s" % (model_name, title), 
    1718        'description': description, 
    1819    }) 
     
    9293 
    9394        # Run the tests for each test model. 
     95        self.output(1, "Running app tests") 
    9496        for model_name in get_test_models(): 
    9597            self.output(1, "%s model: Importing" % model_name) 
     
    111113            self.output(1, "%s model: Running tests" % model_name) 
    112114            runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
    113  
     115             
     116        # Run the non-model tests in the other tests dir 
     117        self.output(1, "Running other tests") 
     118        other_tests_dir = os.path.join(os.path.dirname(__file__), OTHER_TESTS_DIR) 
     119        test_modules = [f[:-3] for f in os.listdir(other_tests_dir) if f.endswith('.py') and not f.startswith('__init__')] 
     120        for module in test_modules: 
     121            self.output(1, "%s module: Importing" % module) 
     122            try: 
     123                mod = __import__("othertests." + module, '', '', ['']) 
     124            except Exception, e: 
     125                log_error(module, "Error while importing", ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
     126                continue 
     127            if mod.__doc__: 
     128                p = doctest.DocTestParser() 
     129                dtest = p.get_doctest(mod.__doc__, mod.__dict__, module, None, None) 
     130                runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 
     131                self.output(1, "%s module: runing tests" % module) 
     132                runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
     133            if hasattr(mod, "run_tests") and callable(mod.run_tests): 
     134                self.output(1, "%s module: runing tests" % module) 
     135                try: 
     136                    mod.run_tests(verbosity_level) 
     137                except Exception, e: 
     138                    log_error(module, "Exception running tests", ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
     139                    continue 
     140             
    114141        # Unless we're using SQLite, remove the test database to clean up after 
    115142        # ourselves. Connect to the previous database (not the test database)