From bdf8683c17aa8e1cb35b3dc844cf1ab1b723ea22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20Leh=C3=A9e?= Date: Thu, 12 Jun 2014 17:24:10 +0200 Subject: [PATCH 1/3] Add egg-info in ignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d20b64..7fdea58 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*.egg-info From 81d4443b9ba3f3fce3028521da5667df0d66df8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20Leh=C3=A9e?= Date: Thu, 12 Jun 2014 17:24:53 +0200 Subject: [PATCH 2/3] Update TestRunner to use module path given to test command --- django_coverage/coverage_runner.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/django_coverage/coverage_runner.py b/django_coverage/coverage_runner.py index 8fc95b4..d87d123 100644 --- a/django_coverage/coverage_runner.py +++ b/django_coverage/coverage_runner.py @@ -15,7 +15,6 @@ """ import os -import sys import django @@ -77,9 +76,11 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs): coverage.stop() coverage_modules = [] - if test_labels: + + if test_labels and all( + [len(label.split('.')) >= 2 for label in test_labels]): for label in test_labels: - label = label.split('.')[0] + label = label.split('.')[1] app = get_app(label) coverage_modules.append(self._get_app_package(app)) else: @@ -118,6 +119,6 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs): else: coverage._the_coverage.html_report(list(modules.values()), outdir) print("") - print("HTML reports were output to '%s'" %outdir) + print("HTML reports were output to '%s'" % outdir) return results From d4679223cc215eed12e978f63f31b17f4eb5178b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20Leh=C3=A9e?= Date: Thu, 12 Jun 2014 17:25:22 +0200 Subject: [PATCH 3/3] Use test command instead of test_coverage --- .../commands/{test_coverage.py => test.py} | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) rename django_coverage/management/commands/{test_coverage.py => test.py} (63%) diff --git a/django_coverage/management/commands/test_coverage.py b/django_coverage/management/commands/test.py similarity index 63% rename from django_coverage/management/commands/test_coverage.py rename to django_coverage/management/commands/test.py index 90dfb83..5404ba9 100755 --- a/django_coverage/management/commands/test_coverage.py +++ b/django_coverage/management/commands/test.py @@ -13,26 +13,31 @@ See the License for the specific language governing permissions and limitations under the License. """ +from optparse import make_option from django.conf import settings -from django.core.management import call_command from django.core.management.commands import test from django_coverage import settings as coverage_settings -class Command(test.Command): - 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.") - def handle(self, *test_labels, **options): +class Command(test.Command): + def __init__(self, *args, **kwargs): + super(Command, self).__init__(*args, **kwargs) + self.option_list += ( + make_option( + '--with-coverage', + action="store_true", dest="with_coverage", default=False, + help="Use Coverage TestRunner to generate coverage."), ) + + def handle(self, *args, **kwargs): """ Replaces the original test runner with the coverage test runner, but keeps track of what the original runner was so that the coverage runner can inherit from it. Then, call the test command. This plays well with apps that override the test command, such as South. """ - coverage_settings.ORIG_TEST_RUNNER = settings.TEST_RUNNER - settings.TEST_RUNNER = coverage_settings.COVERAGE_TEST_RUNNER - call_command('test', *test_labels, **options) - + if kwargs.get('with_coverage'): + coverage_settings.ORIG_TEST_RUNNER = settings.TEST_RUNNER + settings.TEST_RUNNER = coverage_settings.COVERAGE_TEST_RUNNER + super(Command, self).handle(*args, **kwargs)