From b5ea9f6ad5ff42ee8b7c87e43388b62a2a94cbb0 Mon Sep 17 00:00:00 2001 From: Kevin Kubasik Date: Wed, 1 Jul 2009 10:39:52 +0000 Subject: [PATCH] [gsoc2009-testing] Import windmill imports before starting coverage, this fixes some module load issues git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11140 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../core/management/commands/test_windmill.py | 5 ++- django/test/test_coverage.py | 43 +------------------ tests/runtests.py | 26 ++++++----- 3 files changed, 17 insertions(+), 57 deletions(-) diff --git a/django/core/management/commands/test_windmill.py b/django/core/management/commands/test_windmill.py index 7031431fd7..c3da16fe84 100644 --- a/django/core/management/commands/test_windmill.py +++ b/django/core/management/commands/test_windmill.py @@ -1,12 +1,13 @@ from django.core.management.base import BaseCommand #from windmill.authoring import djangotest -from django.test import windmill_tests as djangotest +from django.utils import importlib +from django.test import windmill_tests as djangotest import sys, os from time import sleep import types import logging import threading -from django.utils import importlib + class ServerContainer(object): start_test_server = djangotest.start_test_server stop_test_server = djangotest.stop_test_server diff --git a/django/test/test_coverage.py b/django/test/test_coverage.py index f6cf0312ac..fa78cf66bc 100644 --- a/django/test/test_coverage.py +++ b/django/test/test_coverage.py @@ -3,7 +3,7 @@ import coverage, time import os, sys from django.conf import settings -from django.db.models import get_app, get_apps +from django.db.models.loading import get_app, get_apps from django.test.simple import DefaultTestRunner as base_run_tests @@ -34,7 +34,7 @@ class BaseCoverageRunner(object): Runs the specified tests while generating code coverage statistics. Upon the tests' completion, the results are printed to stdout. """ - self.cov.erase() + #self.cov.erase() #Allow an on-disk cache of coverage stats. self.cov.use_cache(0) #for e in getattr(settings, 'COVERAGE_CODE_EXCLUDES', []): @@ -124,42 +124,3 @@ class ReportingCoverageRunner(BaseCoverageRunner): return res - -try: - set -except: - from sets import Set as set - - -class ModuleVars(object): - modules = dict() - def __new__(cls, module_name, module=None): - if cls.modules.get(module_name, None): - return cls.modules.get(module_name) - else: - obj=super(ModuleVars, cls).__new__(cls) - obj._init(module_name, module) - cls.modules[module_name] = obj - return obj - - def _init(self, module_name, module): - source_file, stmts, excluded, missed, missed_display = coverage.analysis2(module) - executed = list(set(stmts).difference(missed)) - total = list(set(stmts).union(excluded)) - total.sort() - title = module.__name__ - total_count = len(total) - executed_count = len(executed) - excluded_count = len(excluded) - missed_count = len(missed) - try: - percent_covered = float(len(executed))/len(stmts)*100 - except ZeroDivisionError: - percent_covered = 100 - test_timestamp = time.strftime('%a %Y-%m-%d %H:%M %Z') - severity = 'normal' - if percent_covered < 75: severity = 'warning' - if percent_covered < 50: severity = 'critical' - - for k, v in locals().iteritems(): - setattr(self, k, v) diff --git a/tests/runtests.py b/tests/runtests.py index 3b4e7fbeb9..9fa238ac6f 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -185,10 +185,19 @@ def django_tests(verbosity, interactive, test_labels): # Default number of failures is 0 failures = 0 - + if do_windmill: + # Our bank of windmill-specific imports. Only loaded when used. + import types + import logging + import threading + from windmill.conf import global_settings + from windmill.authoring import setup_module, teardown_module + from django.core.management.commands.test_windmill import ServerContainer, attempt_import + from django.test.windmill_tests import WindmillDjangoUnitTest + from django.db.models.loading import remove_model #Run the appropriate test runner based on command line params. - if(do_std): - if(do_coverage): + if do_std: + if do_coverage: test_runner = get_runner(settings, coverage=True, reports=True) else: test_runner = get_runner(settings, coverage=False, reports=False) @@ -201,17 +210,6 @@ def django_tests(verbosity, interactive, test_labels): #Run windmill tests if --windmill parameter was passed. if do_windmill: - # Our bank of windmill-specific imports. Only loaded when used. - import types - import logging - import threading - from windmill.conf import global_settings - from windmill.authoring import setup_module, teardown_module - from django.core.management.commands.test_windmill import ServerContainer, attempt_import - from django.test.windmill_tests import WindmillDjangoUnitTest - from django.db.models.loading import remove_model - - # We don't want to try and parse models that we know are invalid. remove_model('invalid_models')