Permalink
Browse files

removes dependency for django-setuptest and adds more flexible invoca…

…tions for tox
  • Loading branch information...
1 parent ba33d46 commit 469d3b81c3f9fed3c27eb599684c2ea5450da3d5 @stefanfoulis stefanfoulis committed Jan 22, 2013
Showing with 195 additions and 116 deletions.
  1. +13 −2 README.rst
  2. +22 −9 docs/running_tests.rst
  3. +1 −0 filer/test_utils/__init__.py
  4. +85 −0 filer/test_utils/cli.py
  5. +26 −0 filer/test_utils/tmpdir.py
  6. +40 −0 runtests.py
  7. +0 −60 runtests.sh
  8. +2 −4 setup.py
  9. +0 −29 test_settings.py
  10. +6 −12 tox.ini
View
@@ -30,8 +30,8 @@ To get started using ``django-filer`` simply install it with
Configuration
-------------
-Add ``"filer"`` and ``"easy_thumbnails"`` to your project's ``INSTALLED_APPS`` setting and run ``syncdb``
-(or ``migrate`` if you're using South).
+Add ``"filer"``, ``"mptt"`` and ``"easy_thumbnails"`` to your project's ``INSTALLED_APPS`` setting and run ``syncdb``
+(and ``migrate`` if you're using South).
See the docs for advanced configuration:
@@ -40,6 +40,17 @@ See the docs for advanced configuration:
* `secure file downloads docs`_ (experimental)
+Testsuite
+---------
+
+The easiest way to run the testsuite is to checkout the code and run::
+
+ python setup.py test
+
+
+For serious testing ``tox`` is recommended. See documentation for details.
+
+
.. _Django: http://djangoproject.com
.. _django-polymorphic: https://github.com/bconstantin/django_polymorphic
.. _easy_thumbnails: https://github.com/SmileyChris/easy-thumbnails
@@ -3,17 +3,30 @@
Running tests
=============
-There is a minimal project and buildout configuration to get the tests up and
-running.
-In the source checkout switch to the ``tests`` directory and run::
- python bootstrap.py
- ./bin/buildout
+django-filer is continuously being tested on `travis-ci <https://travis-ci.org/stefanfoulis/django-filer>`_.
-This will setup buildout and install all the needed dependencies in a isolated
-environment.
+The simplest way to run the testsuite locally is to checkout the sourcecode and run::
-Run the tests::
+ python setup.py test
- ./bin/django test filer
+It is also possible to invoke the test script directly. Just make sure the test dependencies have been installed::
+
+ runtests.py
+
+
+The recommended way to test locally is with `tox <http://tox.readthedocs.org/en/latest/>`_. Once ``tox`` is installed,
+simply running the ``tox`` command inside the package root. Tox will setup multiple virtual environments with different
+python and django versions to test against::
+
+ # run all tests in all default environments
+ tox
+ # run testsuite with django-dev/python 2.7 and django-1.4/python 2.6
+ tox -e py27-django-dev,py26-django14
+ # run a specific testcase in all environemnts
+ tox -- filer.FilerApiTests.test_create_folder_structure
+ # run a test class in specific environments
+ tox -e py27-django-dev,py26-django14 -- filer.FilerApiTests
+
+``--verbosity=3`` and ``--failfast`` are also supported.
@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-
@@ -0,0 +1,85 @@
+# -*- coding: utf-8 -*-
+from distutils.version import LooseVersion
+import django
+import os
+
+gettext = lambda s: s
+
+urlpatterns = []
+DJANGO_1_3 = LooseVersion(django.get_version()) < LooseVersion('1.4')
+
+def configure(**extra):
+ from django.conf import settings
+ os.environ['DJANGO_SETTINGS_MODULE'] = 'filer.test_utils.cli'
+ defaults = dict(
+ CACHE_BACKEND='locmem:///',
+ DEBUG=True,
+ TEMPLATE_DEBUG=True,
+ DATABASE_SUPPORTS_TRANSACTIONS=True,
+ DATABASES={
+ 'default': {'ENGINE': 'django.db.backends.sqlite3'}
+ },
+ USE_I18N=True,
+ MEDIA_ROOT='/media/',
+ STATIC_ROOT='/static/',
+ MEDIA_URL='/media/',
+ STATIC_URL='/static/',
+ ADMIN_MEDIA_PREFIX='/static/admin/',
+ EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend',
+ SECRET_KEY='key',
+ TEMPLATE_LOADERS=(
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+ 'django.template.loaders.eggs.Loader',
+ ),
+# TEMPLATE_CONTEXT_PROCESSORS=[
+# "django.contrib.auth.context_processors.auth",
+# 'django.contrib.messages.context_processors.messages',
+# "django.core.context_processors.i18n",
+# "django.core.context_processors.debug",
+# "django.core.context_processors.request",
+# "django.core.context_processors.media",
+# 'django.core.context_processors.csrf',
+# "django.core.context_processors.static",
+# ],
+# TEMPLATE_DIRS=[
+# os.path.abspath(os.path.join(os.path.dirname(__file__), 'project', 'templates'))
+# ],
+# MIDDLEWARE_CLASSES=[
+# 'django.contrib.sessions.middleware.SessionMiddleware',
+# 'django.contrib.auth.middleware.AuthenticationMiddleware',
+# 'django.contrib.messages.middleware.MessageMiddleware',
+# 'django.middleware.csrf.CsrfViewMiddleware',
+# 'django.middleware.locale.LocaleMiddleware',
+# 'django.middleware.doc.XViewMiddleware',
+# 'django.middleware.common.CommonMiddleware',
+# 'django.middleware.transaction.TransactionMiddleware',
+# 'django.middleware.cache.FetchFromCacheMiddleware',
+# 'cms.middleware.user.CurrentUserMiddleware',
+# 'cms.middleware.page.CurrentPageMiddleware',
+# 'cms.middleware.toolbar.ToolbarMiddleware',
+# ],
+ INSTALLED_APPS = [
+ 'filer',
+ 'mptt',
+ 'easy_thumbnails',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.admin',
+ 'django.contrib.sessions',
+ 'django.contrib.staticfiles',
+ ],
+ ROOT_URLCONF='filer.test_utils.cli',
+ )
+# if DJANGO_1_3:
+# defaults['INSTALLED_APPS'].append("i18nurls")
+# defaults['MIDDLEWARE_CLASSES'][4] = 'i18nurls.middleware.LocaleMiddleware'
+# else:
+# from django.utils.functional import empty
+# settings._wrapped = empty
+ defaults.update(extra)
+ settings.configure(**defaults)
+# from south.management.commands import patch_for_test_db_setup
+# patch_for_test_db_setup()
+ from django.contrib import admin
+ admin.autodiscover()
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+from contextlib import contextmanager
+from tempfile import mkdtemp
+import os
+import random
+import shutil
+import stat
+
+
+@contextmanager
+def temp_dir():
+ name = make_temp_dir()
+ yield name
+ shutil.rmtree(name)
+
+def make_temp_dir():
+ if os.path.exists('/dev/shm/'):
+ if os.stat('/dev/shm').st_mode & stat.S_IWGRP:
+ dirname = 'django-filer-tests-%s' % random.randint(1,1000000)
+ path = os.path.join('/dev/shm', dirname)
+ while os.path.exists(path):
+ dirname = 'django-filer-tests-%s' % random.randint(1,1000000)
+ path = os.path.join('/dev/shm', dirname)
+ os.mkdir(path)
+ return path
+ return mkdtemp()
View
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+from __future__ import with_statement
+from filer.test_utils.cli import configure
+from filer.test_utils.tmpdir import temp_dir
+import argparse
+import sys
+import warnings
+
+
+def main(verbosity=1, failfast=False, test_labels=None):
+ verbosity = int(verbosity)
+ if not test_labels:
+ test_labels = ['filer']
+ with temp_dir() as STATIC_ROOT:
+ with temp_dir() as MEDIA_ROOT:
+ # from django import VERSION
+ # use_tz = VERSION[:2] >= (1, 4)
+ use_tz = False
+ warnings.filterwarnings(
+ 'error', r"DateTimeField received a naive datetime",
+ RuntimeWarning, r'django\.db\.models\.fields')
+ configure(ROOT_URLCONF='test_urls',
+ STATIC_ROOT=STATIC_ROOT, MEDIA_ROOT=MEDIA_ROOT, USE_TZ=use_tz)
+ from django.conf import settings
+ from django.test.utils import get_runner
+ TestRunner = get_runner(settings)
+
+ test_runner = TestRunner(verbosity=verbosity, interactive=False, failfast=failfast)
+ failures = test_runner.run_tests(test_labels)
+ sys.exit(failures)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--failfast', action='store_true', default=False, dest='failfast')
+ parser.add_argument('--verbosity', default=1)
+ parser.add_argument('test_labels', nargs='*')
+ args = parser.parse_args()
+ test_labels = ['%s' % label for label in args.test_labels]
+ main(verbosity=args.verbosity, failfast=args.failfast, test_labels=test_labels)
View
@@ -1,60 +0,0 @@
-#!/bin/bash
-
-extra=""
-django="13"
-args=("$@")
-num_args=${#args[@]}
-index=0
-while [ "$index" -lt "$num_args" ]
-do
- case "${args[$index]}" in
- "-d"|"--django")
- let "index = $index + 1"
- django="${args[$index]}"
- ;;
-
- "-h"|"--help")
- echo ""
- echo "usage:"
- echo " runtests.sh"
- echo " or runtests.sh [-d <version>|--django <version>] [test arguments]"
- echo ""
- echo "flags:"
- echo " -d, --django <version> - run tests against a django version, options: 13 or 14"
- echo ""
- echo "test arguments:"
- echo " any other argument is passed to setup.py test command for further evaluation"
- exit 1
- ;;
-
- *)
- extra="$extra ${args[$index]}"
- esac
- let "index = $index + 1"
-done
-
-read -r -p "This will install dependencies and run the testsuite. Please make sure you are in a virtualenv! Continue? [Y/n]" response
-case $response in
- [yY]|[eE]|[sS]|[yY])
- ;;
- *)
- echo "cancelled"
- exit
- ;;
-esac
-
-find . -name '*.pyc' -delete
-
-if [ $django == "13" ]; then
- export DJANGO="django>=1.3,<1.4"
-fi
-if [ $django == "14" ]; then
- export DJANGO="django>=1.4,<1.5"
-fi
-if [ $django == "dev" ]; then
- export DJANGO="-e git+git://github.com/django/django.git#egg=Django"
- export EASY_THUMBNAILS="-e git+git://github.com/SmileyChris/easy-thumbnails.git#egg=easy-thumbnails"
-fi
-
-./.travis_setup
-python setup.py test $extra
View
@@ -41,10 +41,8 @@ def read(fname):
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP',
],
- cmdclass={'test': test},
- test_suite='setuptest.setuptest.SetupTestSuite',
+ test_suite='runtests.main',
tests_require=(
- 'django-setuptest>=0.1.1',
- 'argparse', # apparently needed by django-setuptest on python 2.6
+ 'argparse', # needed on python 2.6
),
)
View
@@ -1,29 +0,0 @@
-#-*- coding: utf-8 -*-
-import os
-DEBUG = True
-PACKAGE_ROOT = os.path.abspath( os.path.dirname(__file__) )
-TMP_ROOT = os.path.abspath( os.path.join(PACKAGE_ROOT, 'tmp') )
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': os.path.join(TMP_ROOT,'filer_test.sqlite3'),
- },
- }
-INSTALLED_APPS = [
- 'filer',
- 'mptt',
- 'easy_thumbnails',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.admin',
- 'django.contrib.sessions',
- 'django.contrib.staticfiles',
-]
-
-ROOT_URLCONF = 'test_urls'
-
-MEDIA_ROOT = os.path.abspath( os.path.join(TMP_ROOT, 'media') )
-MEDIA_URL = '/media/'
-STATIC_URL = '/static/'
-
-USE_TZ = False # because of a bug in easy-thumbnails 1.0.3
View
@@ -12,54 +12,48 @@ commands =
deps = pep8
commands = pep8 --repeat --show-source --ignore=E125 --max-line-length=120 --exclude=.venv,.tox,dist,doc,*egg filer
+[testenv]
+commands = python runtests.py {posargs}
[testenv:py26-django13]
basepython = python2.6
-commands =
- python setup.py test
deps =
django>=1.3,<1.4
Pillow
+ argparse
[testenv:py27-django13]
basepython = python2.7
-commands =
- python setup.py test
deps =
django>=1.3,<1.4
Pillow
[testenv:py26-django14]
basepython = python2.6
-commands =
- python setup.py test
deps =
django>=1.4,<1.5
Pillow
+ argparse
+
[testenv:py27-django14]
basepython = python2.7
-commands =
- python setup.py test
deps =
django>=1.4,<1.5
Pillow
[testenv:py26-django-dev]
basepython = python2.6
-commands =
- python setup.py test
deps =
git+git://github.com/django/django.git#egg=Django
git+git://github.com/SmileyChris/easy-thumbnails.git#egg=easy-thumbnails
Pillow
+ argparse
[testenv:py27-django-dev]
basepython = python2.7
-commands =
- python setup.py test
deps =
git+git://github.com/django/django.git#egg=Django
git+git://github.com/SmileyChris/easy-thumbnails.git#egg=easy-thumbnails

0 comments on commit 469d3b8

Please sign in to comment.