From 70f3fa45c12d50280b293478c2336396166618e3 Mon Sep 17 00:00:00 2001 From: Adrian Date: Tue, 29 Sep 2015 21:50:26 +0200 Subject: [PATCH] Simple tests --- .travis.yml | 4 +-- quicktest.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ setup.py | 7 +++++- 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 quicktest.py create mode 100644 requirements.txt diff --git a/.travis.yml b/.travis.yml index ebd61e1..e32af2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ python: - 3.5 - "pypy" install: - - pip install . - pip install -q Django==$DJANGO_VERSION - - python setup.py -q install + - python setup.py install env: - DJANGO_VERSION=1.7 - DJANGO_VERSION=1.8 +script: python quicktest.py markdownx diff --git a/quicktest.py b/quicktest.py new file mode 100644 index 0000000..3443658 --- /dev/null +++ b/quicktest.py @@ -0,0 +1,65 @@ +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.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.admin', + ) + + def __init__(self, *args, **kwargs): + self.apps = args + self.run_tests() + + + def run_tests(self): + settings.configure( + DEBUG = False, + 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, interactive=False) + if failures: + 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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d451b60 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Pillow +Markdown diff --git a/setup.py b/setup.py index 5f5e3fc..ccf4726 100755 --- a/setup.py +++ b/setup.py @@ -4,6 +4,11 @@ import os if 'vagrant' in str(os.environ): del os.link + +def get_requirements(): + return open('requirements.txt').read().splitlines() + + setup( name='django-markdownx', version='1.0.1', @@ -27,5 +32,5 @@ setup( 'Programming Language :: JavaScript', ], keywords='django markdown live preview images upload', - install_requires=['Pillow', 'Markdown'], + install_requires=get_requirements(), )