From 124fe21d06329ea3d2b0329700bdc9f80fd68964 Mon Sep 17 00:00:00 2001 From: Gagaro Date: Thu, 4 Dec 2014 10:22:31 +0100 Subject: [PATCH] tests: upgrade quicktest.py + improve travis configuration --- .travis.yml | 31 +++++++++++++++++++++++++++---- quicktest.py | 32 +++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95b869d..39c5da0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,42 @@ language: python python: - - "2.7" + - 2.6 + - 2.7 + - 3.2 + - 3.3 + - 3.4 env: - - DJANGO_VERSION=1.4 - - DJANGO_VERSION=1.5 + - DJANGO_VERSION=1.4 MODULE=jsignature + - DJANGO_VERSION=1.5 MODULE=jsignature + - DJANGO_VERSION=1.6 MODULE=jsignature.tests + - DJANGO_VERSION=1.7 MODULE=jsignature.tests install: - pip install -r requirements.txt --use-mirrors - pip install -q Django==$DJANGO_VERSION --use-mirrors - pip install coverage -script: coverage run quicktest.py jsignature +script: coverage run quicktest.py $MODULE after_success: - pip install coveralls - coveralls + +# We need to exclude old versions of Django for tests with python 3. +# We need to exclude old versions of Python for tests with Django >= 1.7. +matrix: + exclude: + - python: 3.2 + env: DJANGO_VERSION=1.4 + - python: 3.3 + env: DJANGO_VERSION=1.4 + - python: 3.4 + env: DJANGO_VERSION=1.4 + - python: 3.4 + env: DJANGO_VERSION=1.5 + - python: 3.4 + env: DJANGO_VERSION=1.6 + - python: 2.6 + env: DJANGO_VERSION=1.7 diff --git a/quicktest.py b/quicktest.py index 358460d..885e736 100644 --- a/quicktest.py +++ b/quicktest.py @@ -3,6 +3,7 @@ import sys import argparse from django.conf import settings + class QuickDjangoTest(object): """ A quick way to run the Django test suite without a fully-configured project. @@ -16,8 +17,6 @@ class QuickDjangoTest(object): """ DIRNAME = os.path.dirname(__file__) INSTALLED_APPS = ( - 'django.contrib.contenttypes', - 'django.contrib.sessions', ) def __init__(self, *args, **kwargs): @@ -29,7 +28,10 @@ class QuickDjangoTest(object): Fire up the Django test suite developed for version 1.2 """ settings.configure( - DATABASES={ + TEMPLATE_DIRS = ('jsignature/templates/',), + ROOT_URLCONF = 'jsignature.tests', + DEBUG = True, + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(self.DIRNAME, 'database.db'), @@ -39,11 +41,27 @@ class QuickDjangoTest(object): 'PORT': '', } }, - INSTALLED_APPS=self.INSTALLED_APPS + self.apps, + MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + ), + INSTALLED_APPS = self.INSTALLED_APPS + self.apps ) - from django.test.simple import DjangoTestSuiteRunner - failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) - if failures: # pragma: no cover + # Setup is needed for Django >= 1.7 + import django + if hasattr(django, 'setup'): + django.setup() + try: + from django.test.runner import DiscoverRunner + failures = DiscoverRunner().run_tests(self.apps, verbosity=1) + except ImportError: + # DjangoTestSuiteRunner has been deprecated in Django 1.7 + from django.test.simple import DjangoTestSuiteRunner + failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) + if failures: # pragma: no cover sys.exit(failures) if __name__ == '__main__':