Skip to content

Commit

Permalink
Use tox for testing locally and in travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmac committed Nov 6, 2015
1 parent 7743f5d commit 15c1903
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 243 deletions.
191 changes: 24 additions & 167 deletions .travis.yml
@@ -1,169 +1,26 @@
sudo: false
language: python
branches:
only:
- master

# The current build matrix may be described as follows:
#
# build := (Python version, Django version, Celery version)
#
# where
#
# 2.6 <= Python version <= 3.4 + PyPy
# 1.3 <= Django version <= 1.7
# 2.3 <= Celery version <= 3.1
#
# We skip Celery 2.5 since it doesn't introduce any relevant features
# and the number of build variants is big enough already.
#
# Python 3.3 and PyPy are only supported by Django 1.5+.
# Python 3.3 is only supported by Celery 2.4+.
#
# Python 3.4 is supported by Django 1.7, which also drops 2.6 support.
# Python 3.4 also breaks with Celery <3.1, so drop those combinations.
# (It may actually be that django-celery breaks in 3.4. It's a super edge
# case, so I haven't investigated at all.)
#
# For Celery < 3.1, we additionally need to install django-celery.
#
# Since this kind of build matrix is difficult to encode in a .travis.yml
# file we just present an unrolled version here.
matrix:
include:
# Python 2.6: Django 1.3 to 1.6, Celery 2.3 to 3.1
- python: 2.6
env: INSTALL="Django>=1.3,<1.4 celery>=2.3,<2.4 django-celery django-override-settings"
- python: 2.6
env: INSTALL="Django>=1.3,<1.4 celery>=2.4,<2.5 django-celery django-override-settings"
- python: 2.6
env: INSTALL="Django>=1.3,<1.4 celery>=3.0,<3.1 django-celery django-override-settings"
- python: 2.6
env: INSTALL="Django>=1.3,<1.4 celery>=3.1,<3.2 django-override-settings"
- python: 2.6
env: INSTALL="Django>=1.4,<1.5 celery>=2.3,<2.4 django-celery"
- python: 2.6
env: INSTALL="Django>=1.4,<1.5 celery>=2.4,<2.5 django-celery"
- python: 2.6
env: INSTALL="Django>=1.4,<1.5 celery>=3.0,<3.1 django-celery"
- python: 2.6
env: INSTALL="Django>=1.4,<1.5 celery>=3.1,<3.2"
- python: 2.6
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
- python: 2.6
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
- python: 2.6
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
- python: 2.6
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
- python: 2.6
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
- python: 2.6
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
- python: 2.6
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
- python: 2.6
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"

# Python 2.7: Django 1.3 to 1.7, Celery 2.3 to 3.1
- python: 2.7
env: INSTALL="Django>=1.3,<1.4 celery>=2.3,<2.4 django-celery django-override-settings"
- python: 2.7
env: INSTALL="Django>=1.3,<1.4 celery>=2.4,<2.5 django-celery django-override-settings"
- python: 2.7
env: INSTALL="Django>=1.3,<1.4 celery>=3.0,<3.1 django-celery django-override-settings"
- python: 2.7
env: INSTALL="Django>=1.3,<1.4 celery>=3.1,<3.2 django-override-settings"
- python: 2.7
env: INSTALL="Django>=1.4,<1.5 celery>=2.3,<2.4 django-celery"
- python: 2.7
env: INSTALL="Django>=1.4,<1.5 celery>=2.4,<2.5 django-celery"
- python: 2.7
env: INSTALL="Django>=1.4,<1.5 celery>=3.0,<3.1 django-celery"
- python: 2.7
env: INSTALL="Django>=1.4,<1.5 celery>=3.1,<3.2"
- python: 2.7
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
- python: 2.7
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
- python: 2.7
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
- python: 2.7
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
- python: 2.7
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
- python: 2.7
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
- python: 2.7
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
- python: 2.7
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
- python: 2.7
env: INSTALL="Django>=1.7,<1.8 celery>=2.3,<2.4 django-celery"
- python: 2.7
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
- python: 2.7
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
- python: 2.7
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"

# Python 3.3: Django 1.5 to 1.7, Celery 2.4 to 3.1
- python: 3.3
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
- python: 3.3
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
- python: 3.3
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
- python: 3.3
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
- python: 3.3
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
- python: 3.3
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
- python: 3.3
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
- python: 3.3
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
- python: 3.3
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"

# Python 3.4: Django 1.7, Celery 3.1
- python: 3.4
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"


# PyPy: Django 1.5 to 1.7, Celery 2.3 to 3.1
- python: pypy
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
- python: pypy
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
- python: pypy
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
- python: pypy
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
- python: pypy
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
- python: pypy
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
- python: pypy
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
- python: pypy
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
- python: pypy
env: INSTALL="Django>=1.7,<1.8 celery>=2.3,<2.4 django-celery"
- python: pypy
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
- python: pypy
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
- python: pypy
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"


install:
- pip install $INSTALL
- pip install -r requirements.txt


before_script:
- flake8
script: python setup.py test
env:
- TOXENV=py27-dj17-celery24
- TOXENV=py27-dj17-celery30
- TOXENV=py27-dj17-celery31
- TOXENV=py27-dj18-celery24
- TOXENV=py27-dj18-celery30
- TOXENV=py27-dj18-celery31
- TOXENV=py33-dj17-celery24
- TOXENV=py33-dj17-celery30
- TOXENV=py33-dj17-celery31
- TOXENV=py33-dj18-celery24
- TOXENV=py33-dj18-celery30
- TOXENV=py33-dj18-celery31
- TOXENV=pypy-dj17-celery24
- TOXENV=pypy-dj17-celery30
- TOXENV=pypy-dj17-celery31
- TOXENV=pypy-dj18-celery24
- TOXENV=pypy-dj18-celery30
- TOXENV=pypy-dj18-celery31
- TOXENV=py34-dj18-celery31
- TOXENV=py35-dj18-celery31
- TOXENV=flake8
install: pip install tox
script: tox
2 changes: 1 addition & 1 deletion djcelery_email/__init__.py
@@ -1 +1 @@
from __about__ import * # noqa
from .__about__ import * # noqa
3 changes: 1 addition & 2 deletions requirements.txt
@@ -1,5 +1,4 @@
Django
Django>=1.7
celery>=2.3.0
django-appconf
flake8
six
13 changes: 13 additions & 0 deletions runtests.py
@@ -0,0 +1,13 @@
#!/usr/bin/env python
import os
import sys

import django

from tests import DJCETestSuiteRunner

if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
failures = DJCETestSuiteRunner().run_tests(["tests"])
sys.exit(bool(failures))
2 changes: 0 additions & 2 deletions setup.cfg
@@ -1,2 +0,0 @@
[flake8]
max-line-length=100
29 changes: 2 additions & 27 deletions setup.py
@@ -1,38 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import codecs

from setuptools import setup, find_packages, Command


base_dir = os.path.dirname(__file__)


class RunTests(Command):
description = 'Run the django test suite from the tests dir.'
user_options = []

def run(self):
this_dir = os.getcwd()
testproj_dir = os.path.join(this_dir, 'test_project')
sys.path.append(testproj_dir)

from django.core.management import execute_from_command_line
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
os.chdir(testproj_dir)
execute_from_command_line([__file__, 'test'])
os.chdir(this_dir)

def initialize_options(self):
pass

def finalize_options(self):
pass


with codecs.open(os.path.join(base_dir, 'README.rst')) as f:
with codecs.open(os.path.join(base_dir, 'README.rst'), 'r', encoding='utf8') as f:
long_description = f.read()

about = {}
Expand All @@ -50,15 +26,14 @@ def finalize_options(self):
author=about['__author__'],
author_email=about['__email__'],
platforms=['any'],
packages=find_packages(exclude=['ez_setup', 'test_project', 'test_project.*']),
packages=find_packages(exclude=['ez_setup', 'tests']),
scripts=[],
zip_safe=False,
install_requires=[
'django>=1.7',
'celery>=2.3.0',
'django-appconf',
],
cmdclass={'test': RunTests},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
Expand Down
Empty file removed test_project/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions test_project/manage.py

This file was deleted.

8 changes: 0 additions & 8 deletions test_project/test_runner.py

This file was deleted.

Empty file removed test_project/tester/__init__.py
Empty file.
Empty file removed test_project/tester/models.py
Empty file.
3 changes: 0 additions & 3 deletions test_project/urls.py

This file was deleted.

10 changes: 10 additions & 0 deletions tests/__init__.py
@@ -0,0 +1,10 @@
from django.test.runner import DiscoverRunner


class DJCETestSuiteRunner(DiscoverRunner):
def setup_test_environment(self, **kwargs):
# have to do this here as the default test runner overrides EMAIL_BACKEND
super(DJCETestSuiteRunner, self).setup_test_environment(**kwargs)

from django.conf import settings
settings.EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
14 changes: 1 addition & 13 deletions test_project/settings.py → tests/settings.py
@@ -1,21 +1,14 @@
import os
import sys


PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(PROJECT_ROOT, '..'))

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}


INSTALLED_APPS = (
'djcelery_email',
'appconf',
'tester',
)

SECRET_KEY = 'unique snowflake'
Expand All @@ -24,11 +17,6 @@
# We don't actually use any middleware, given that there are no views.
MIDDLEWARE_CLASSES = ()

TEST_RUNNER = "test_runner.DJCETestSuiteRunner"

# Not set here - see 'test_runner.py'
# EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'

CELERY_EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
CELERY_EMAIL_TASK_CONFIG = {
'queue': 'django_email',
Expand Down
16 changes: 6 additions & 10 deletions test_project/tester/tests.py → tests/tests.py
@@ -1,13 +1,9 @@
from django.core import mail
from django.core.mail.backends.base import BaseEmailBackend
from django.test import TestCase
from django.core.mail.backends import locmem
from django.core.mail import EmailMultiAlternatives

try:
from django.test.utils import override_settings
except ImportError:
from override_settings import override_settings
from django.test import TestCase
from django.test.utils import override_settings

import celery
from djcelery_email import tasks
Expand Down Expand Up @@ -105,23 +101,23 @@ def test_send_multiple_email_dicts_response(self):
self.assertEqual(messages_sent, N)
self.assertEqual(len(mail.outbox), N)

@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
def test_uses_correct_backend(self):
""" It should use the backend configured in CELERY_EMAIL_BACKEND. """
TracingBackend.called = False
msg = mail.EmailMessage()
tasks.send_email(email_to_dict(msg), backend_kwargs={})
self.assertTrue(TracingBackend.called)

@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
def test_backend_parameters(self):
""" It should pass kwargs like username and password to the backend. """
TracingBackend.kwargs = None
msg = mail.EmailMessage()
tasks.send_email(email_to_dict(msg), backend_kwargs={'foo': 'bar'})
self.assertEqual(TracingBackend.kwargs.get('foo'), 'bar')

@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
def test_backend_parameters_kwargs(self):
""" It should pass on kwargs specified as keyword params. """
TracingBackend.kwargs = None
Expand Down Expand Up @@ -165,7 +161,7 @@ def tearDown(self):
super(TaskErrorTests, self).tearDown()
tasks.send_emails.retry = self._old_retry

@override_settings(CELERY_EMAIL_BACKEND='tester.tests.EvenErrorBackend')
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.EvenErrorBackend')
def test_send_multiple_emails(self):
N = 10
msgs = [mail.EmailMessage(subject="msg %d" % i) for i in range(N)]
Expand Down

0 comments on commit 15c1903

Please sign in to comment.