Skip to content

Commit 15c1903

Browse files
committed
Use tox for testing locally and in travis.
1 parent 7743f5d commit 15c1903

16 files changed

+80
-243
lines changed

.travis.yml

+24-167
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,26 @@
11
sudo: false
22
language: python
3-
branches:
4-
only:
5-
- master
6-
7-
# The current build matrix may be described as follows:
8-
#
9-
# build := (Python version, Django version, Celery version)
10-
#
11-
# where
12-
#
13-
# 2.6 <= Python version <= 3.4 + PyPy
14-
# 1.3 <= Django version <= 1.7
15-
# 2.3 <= Celery version <= 3.1
16-
#
17-
# We skip Celery 2.5 since it doesn't introduce any relevant features
18-
# and the number of build variants is big enough already.
19-
#
20-
# Python 3.3 and PyPy are only supported by Django 1.5+.
21-
# Python 3.3 is only supported by Celery 2.4+.
22-
#
23-
# Python 3.4 is supported by Django 1.7, which also drops 2.6 support.
24-
# Python 3.4 also breaks with Celery <3.1, so drop those combinations.
25-
# (It may actually be that django-celery breaks in 3.4. It's a super edge
26-
# case, so I haven't investigated at all.)
27-
#
28-
# For Celery < 3.1, we additionally need to install django-celery.
29-
#
30-
# Since this kind of build matrix is difficult to encode in a .travis.yml
31-
# file we just present an unrolled version here.
32-
matrix:
33-
include:
34-
# Python 2.6: Django 1.3 to 1.6, Celery 2.3 to 3.1
35-
- python: 2.6
36-
env: INSTALL="Django>=1.3,<1.4 celery>=2.3,<2.4 django-celery django-override-settings"
37-
- python: 2.6
38-
env: INSTALL="Django>=1.3,<1.4 celery>=2.4,<2.5 django-celery django-override-settings"
39-
- python: 2.6
40-
env: INSTALL="Django>=1.3,<1.4 celery>=3.0,<3.1 django-celery django-override-settings"
41-
- python: 2.6
42-
env: INSTALL="Django>=1.3,<1.4 celery>=3.1,<3.2 django-override-settings"
43-
- python: 2.6
44-
env: INSTALL="Django>=1.4,<1.5 celery>=2.3,<2.4 django-celery"
45-
- python: 2.6
46-
env: INSTALL="Django>=1.4,<1.5 celery>=2.4,<2.5 django-celery"
47-
- python: 2.6
48-
env: INSTALL="Django>=1.4,<1.5 celery>=3.0,<3.1 django-celery"
49-
- python: 2.6
50-
env: INSTALL="Django>=1.4,<1.5 celery>=3.1,<3.2"
51-
- python: 2.6
52-
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
53-
- python: 2.6
54-
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
55-
- python: 2.6
56-
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
57-
- python: 2.6
58-
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
59-
- python: 2.6
60-
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
61-
- python: 2.6
62-
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
63-
- python: 2.6
64-
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
65-
- python: 2.6
66-
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
67-
68-
# Python 2.7: Django 1.3 to 1.7, Celery 2.3 to 3.1
69-
- python: 2.7
70-
env: INSTALL="Django>=1.3,<1.4 celery>=2.3,<2.4 django-celery django-override-settings"
71-
- python: 2.7
72-
env: INSTALL="Django>=1.3,<1.4 celery>=2.4,<2.5 django-celery django-override-settings"
73-
- python: 2.7
74-
env: INSTALL="Django>=1.3,<1.4 celery>=3.0,<3.1 django-celery django-override-settings"
75-
- python: 2.7
76-
env: INSTALL="Django>=1.3,<1.4 celery>=3.1,<3.2 django-override-settings"
77-
- python: 2.7
78-
env: INSTALL="Django>=1.4,<1.5 celery>=2.3,<2.4 django-celery"
79-
- python: 2.7
80-
env: INSTALL="Django>=1.4,<1.5 celery>=2.4,<2.5 django-celery"
81-
- python: 2.7
82-
env: INSTALL="Django>=1.4,<1.5 celery>=3.0,<3.1 django-celery"
83-
- python: 2.7
84-
env: INSTALL="Django>=1.4,<1.5 celery>=3.1,<3.2"
85-
- python: 2.7
86-
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
87-
- python: 2.7
88-
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
89-
- python: 2.7
90-
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
91-
- python: 2.7
92-
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
93-
- python: 2.7
94-
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
95-
- python: 2.7
96-
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
97-
- python: 2.7
98-
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
99-
- python: 2.7
100-
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
101-
- python: 2.7
102-
env: INSTALL="Django>=1.7,<1.8 celery>=2.3,<2.4 django-celery"
103-
- python: 2.7
104-
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
105-
- python: 2.7
106-
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
107-
- python: 2.7
108-
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"
109-
110-
# Python 3.3: Django 1.5 to 1.7, Celery 2.4 to 3.1
111-
- python: 3.3
112-
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
113-
- python: 3.3
114-
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
115-
- python: 3.3
116-
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
117-
- python: 3.3
118-
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
119-
- python: 3.3
120-
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
121-
- python: 3.3
122-
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
123-
- python: 3.3
124-
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
125-
- python: 3.3
126-
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
127-
- python: 3.3
128-
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"
129-
130-
# Python 3.4: Django 1.7, Celery 3.1
131-
- python: 3.4
132-
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"
133-
134-
135-
# PyPy: Django 1.5 to 1.7, Celery 2.3 to 3.1
136-
- python: pypy
137-
env: INSTALL="Django>=1.5,<1.6 celery>=2.3,<2.4 django-celery"
138-
- python: pypy
139-
env: INSTALL="Django>=1.5,<1.6 celery>=2.4,<2.5 django-celery"
140-
- python: pypy
141-
env: INSTALL="Django>=1.5,<1.6 celery>=3.0,<3.1 django-celery"
142-
- python: pypy
143-
env: INSTALL="Django>=1.5,<1.6 celery>=3.1,<3.2"
144-
- python: pypy
145-
env: INSTALL="Django>=1.6,<1.7 celery>=2.3,<2.4 django-celery"
146-
- python: pypy
147-
env: INSTALL="Django>=1.6,<1.7 celery>=2.4,<2.5 django-celery"
148-
- python: pypy
149-
env: INSTALL="Django>=1.6,<1.7 celery>=3.0,<3.1 django-celery"
150-
- python: pypy
151-
env: INSTALL="Django>=1.6,<1.7 celery>=3.1,<3.2"
152-
- python: pypy
153-
env: INSTALL="Django>=1.7,<1.8 celery>=2.3,<2.4 django-celery"
154-
- python: pypy
155-
env: INSTALL="Django>=1.7,<1.8 celery>=2.4,<2.5 django-celery"
156-
- python: pypy
157-
env: INSTALL="Django>=1.7,<1.8 celery>=3.0,<3.1 django-celery"
158-
- python: pypy
159-
env: INSTALL="Django>=1.7,<1.8 celery>=3.1,<3.2"
160-
161-
162-
install:
163-
- pip install $INSTALL
164-
- pip install -r requirements.txt
165-
166-
167-
before_script:
168-
- flake8
169-
script: python setup.py test
3+
env:
4+
- TOXENV=py27-dj17-celery24
5+
- TOXENV=py27-dj17-celery30
6+
- TOXENV=py27-dj17-celery31
7+
- TOXENV=py27-dj18-celery24
8+
- TOXENV=py27-dj18-celery30
9+
- TOXENV=py27-dj18-celery31
10+
- TOXENV=py33-dj17-celery24
11+
- TOXENV=py33-dj17-celery30
12+
- TOXENV=py33-dj17-celery31
13+
- TOXENV=py33-dj18-celery24
14+
- TOXENV=py33-dj18-celery30
15+
- TOXENV=py33-dj18-celery31
16+
- TOXENV=pypy-dj17-celery24
17+
- TOXENV=pypy-dj17-celery30
18+
- TOXENV=pypy-dj17-celery31
19+
- TOXENV=pypy-dj18-celery24
20+
- TOXENV=pypy-dj18-celery30
21+
- TOXENV=pypy-dj18-celery31
22+
- TOXENV=py34-dj18-celery31
23+
- TOXENV=py35-dj18-celery31
24+
- TOXENV=flake8
25+
install: pip install tox
26+
script: tox

djcelery_email/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from __about__ import * # noqa
1+
from .__about__ import * # noqa

requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Django
1+
Django>=1.7
22
celery>=2.3.0
33
django-appconf
44
flake8
5-
six

runtests.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
import django
6+
7+
from tests import DJCETestSuiteRunner
8+
9+
if __name__ == "__main__":
10+
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
11+
django.setup()
12+
failures = DJCETestSuiteRunner().run_tests(["tests"])
13+
sys.exit(bool(failures))

setup.cfg

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
[flake8]
2-
max-line-length=100

setup.py

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import os
4-
import sys
54
import codecs
65

76
from setuptools import setup, find_packages, Command
87

98

109
base_dir = os.path.dirname(__file__)
1110

12-
13-
class RunTests(Command):
14-
description = 'Run the django test suite from the tests dir.'
15-
user_options = []
16-
17-
def run(self):
18-
this_dir = os.getcwd()
19-
testproj_dir = os.path.join(this_dir, 'test_project')
20-
sys.path.append(testproj_dir)
21-
22-
from django.core.management import execute_from_command_line
23-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
24-
os.chdir(testproj_dir)
25-
execute_from_command_line([__file__, 'test'])
26-
os.chdir(this_dir)
27-
28-
def initialize_options(self):
29-
pass
30-
31-
def finalize_options(self):
32-
pass
33-
34-
35-
with codecs.open(os.path.join(base_dir, 'README.rst')) as f:
11+
with codecs.open(os.path.join(base_dir, 'README.rst'), 'r', encoding='utf8') as f:
3612
long_description = f.read()
3713

3814
about = {}
@@ -50,15 +26,14 @@ def finalize_options(self):
5026
author=about['__author__'],
5127
author_email=about['__email__'],
5228
platforms=['any'],
53-
packages=find_packages(exclude=['ez_setup', 'test_project', 'test_project.*']),
29+
packages=find_packages(exclude=['ez_setup', 'tests']),
5430
scripts=[],
5531
zip_safe=False,
5632
install_requires=[
5733
'django>=1.7',
5834
'celery>=2.3.0',
5935
'django-appconf',
6036
],
61-
cmdclass={'test': RunTests},
6237
classifiers=[
6338
'Development Status :: 5 - Production/Stable',
6439
'Framework :: Django',

test_project/__init__.py

Whitespace-only changes.

test_project/manage.py

-10
This file was deleted.

test_project/test_runner.py

-8
This file was deleted.

test_project/tester/__init__.py

Whitespace-only changes.

test_project/tester/models.py

Whitespace-only changes.

test_project/urls.py

-3
This file was deleted.

tests/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.test.runner import DiscoverRunner
2+
3+
4+
class DJCETestSuiteRunner(DiscoverRunner):
5+
def setup_test_environment(self, **kwargs):
6+
# have to do this here as the default test runner overrides EMAIL_BACKEND
7+
super(DJCETestSuiteRunner, self).setup_test_environment(**kwargs)
8+
9+
from django.conf import settings
10+
settings.EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'

test_project/settings.py tests/settings.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import os
2-
import sys
3-
4-
5-
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
6-
sys.path.insert(0, os.path.join(PROJECT_ROOT, '..'))
7-
81
DATABASES = {
92
'default': {
103
'ENGINE': 'django.db.backends.sqlite3',
4+
'NAME': ':memory:',
115
}
126
}
137

148

159
INSTALLED_APPS = (
1610
'djcelery_email',
1711
'appconf',
18-
'tester',
1912
)
2013

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

27-
TEST_RUNNER = "test_runner.DJCETestSuiteRunner"
28-
29-
# Not set here - see 'test_runner.py'
30-
# EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
31-
3220
CELERY_EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
3321
CELERY_EMAIL_TASK_CONFIG = {
3422
'queue': 'django_email',

test_project/tester/tests.py tests/tests.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from django.core import mail
22
from django.core.mail.backends.base import BaseEmailBackend
3-
from django.test import TestCase
43
from django.core.mail.backends import locmem
54
from django.core.mail import EmailMultiAlternatives
6-
7-
try:
8-
from django.test.utils import override_settings
9-
except ImportError:
10-
from override_settings import override_settings
5+
from django.test import TestCase
6+
from django.test.utils import override_settings
117

128
import celery
139
from djcelery_email import tasks
@@ -105,23 +101,23 @@ def test_send_multiple_email_dicts_response(self):
105101
self.assertEqual(messages_sent, N)
106102
self.assertEqual(len(mail.outbox), N)
107103

108-
@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
104+
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
109105
def test_uses_correct_backend(self):
110106
""" It should use the backend configured in CELERY_EMAIL_BACKEND. """
111107
TracingBackend.called = False
112108
msg = mail.EmailMessage()
113109
tasks.send_email(email_to_dict(msg), backend_kwargs={})
114110
self.assertTrue(TracingBackend.called)
115111

116-
@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
112+
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
117113
def test_backend_parameters(self):
118114
""" It should pass kwargs like username and password to the backend. """
119115
TracingBackend.kwargs = None
120116
msg = mail.EmailMessage()
121117
tasks.send_email(email_to_dict(msg), backend_kwargs={'foo': 'bar'})
122118
self.assertEqual(TracingBackend.kwargs.get('foo'), 'bar')
123119

124-
@override_settings(CELERY_EMAIL_BACKEND='tester.tests.TracingBackend')
120+
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.TracingBackend')
125121
def test_backend_parameters_kwargs(self):
126122
""" It should pass on kwargs specified as keyword params. """
127123
TracingBackend.kwargs = None
@@ -165,7 +161,7 @@ def tearDown(self):
165161
super(TaskErrorTests, self).tearDown()
166162
tasks.send_emails.retry = self._old_retry
167163

168-
@override_settings(CELERY_EMAIL_BACKEND='tester.tests.EvenErrorBackend')
164+
@override_settings(CELERY_EMAIL_BACKEND='tests.tests.EvenErrorBackend')
169165
def test_send_multiple_emails(self):
170166
N = 10
171167
msgs = [mail.EmailMessage(subject="msg %d" % i) for i in range(N)]

0 commit comments

Comments
 (0)