From 95860405f39b104c2d402dbb410ba5e4ffdf1920 Mon Sep 17 00:00:00 2001 From: Florent Lebreton Date: Sun, 29 Sep 2013 10:24:18 +0200 Subject: [PATCH] Use travis-ci --- .travis.yml | 15 ++++++++++ jsignature/quicktest.py | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .travis.yml create mode 100644 jsignature/quicktest.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2619d67 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: python + +python: + - "2.6" + - "2.7" + +env: + - DJANGO_VERSION=1.4 + - DJANGO_VERSION=1.5 + +install: + pip install -r requirements.txt --use-mirrors + pip install -q Django==$DJANGO_VERSION --use-mirrors + +script: python quicktest.py jsignature diff --git a/jsignature/quicktest.py b/jsignature/quicktest.py new file mode 100644 index 0000000..358460d --- /dev/null +++ b/jsignature/quicktest.py @@ -0,0 +1,64 @@ +import os +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. + + Example usage: + + >>> QuickDjangoTest('app1', 'app2') + + Based on a script published by Lukasz Dziedzia at: + http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app + """ + DIRNAME = os.path.dirname(__file__) + INSTALLED_APPS = ( + 'django.contrib.contenttypes', + 'django.contrib.sessions', + ) + + def __init__(self, *args, **kwargs): + self.apps = args + self.run_tests() + + def run_tests(self): + """ + Fire up the Django test suite developed for version 1.2 + """ + settings.configure( + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(self.DIRNAME, 'database.db'), + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } + }, + 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 + sys.exit(failures) + +if __name__ == '__main__': + """ + What do when the user hits this file from the shell. + + Example usage: + + $ python quicktest.py app1 app2 + + """ + parser = argparse.ArgumentParser( + usage="[args]", + description="Run Django tests on the provided applications." + ) + parser.add_argument('apps', nargs='+', type=str) + args = parser.parse_args() + QuickDjangoTest(*args.apps)