""" Copyright 2009 55 Minutes (http://www.55minutes.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from django.core.management.base import BaseCommand from optparse import make_option import sys def get_runner(settings): test_path = settings.COVERAGE_TEST_RUNNER.split('.') # Allow for Python 2.5 relative paths if len(test_path) > 1: test_module_name = '.'.join(test_path[:-1]) else: test_module_name = '.' test_module = __import__(test_module_name, {}, {}, test_path[-1]) test_runner = getattr(test_module, test_path[-1]) return test_runner class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--noinput', action='store_false', dest='interactive', default=True, help='Tells Django to NOT prompt the user for input of any kind.'), ) help = """\ Runs the test suite for the specified applications, or the entire site if \ no apps are specified. Then generates coverage report both onscreen and as HTML. """ args = '[appname ...]' requires_model_validation = False def handle(self, *test_labels, **options): from django.conf import settings verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive', True) test_runner = get_runner(settings) failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive) if failures: sys.exit(failures)