Skip to content

Commit 1612037

Browse files
vytisbauvipy
authored andcommitted
Resolved some warnings in tests. (#473)
1 parent 79d9689 commit 1612037

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

Changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949

5050
Fix contributed by Éloi Rivard
5151

52+
- Resolved some deprecation warnings in the test suite.
53+
54+
Fix contributed by Vytis Banaitis.
55+
5256
.. _version-3.1.17:
5357

5458
3.1.17

djcelery/loaders.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def find_related_module(app, related_name):
190190
return
191191

192192
try:
193-
imp.find_module(related_name, app_path)
193+
f, _, _ = imp.find_module(related_name, app_path)
194+
f.close()
194195
except ImportError:
195196
return
196197

djcelery/tests/test_schedulers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def test_entry(self):
8585
self.assertTrue(e.schedule)
8686
self.assertEqual(e.total_run_count, 0)
8787
self.assertIsInstance(e.last_run_at, datetime)
88-
self.assertDictContainsSubset({'queue': 'xaz',
89-
'exchange': 'foo',
90-
'routing_key': 'cpu'}, e.options)
88+
self.assertEqual(e.options.get('queue'), 'xaz')
89+
self.assertEqual(e.options.get('exchange'), 'foo')
90+
self.assertEqual(e.options.get('routing_key'), 'cpu')
9191

9292
right_now = celery.now()
9393
m2 = create_model_interval(schedule(timedelta(seconds=10)),

djcelery/tests/test_views.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import partial
66

77
from billiard.einfo import ExceptionInfo
8-
from django.core.urlresolvers import reverse
8+
99
from django.http import HttpResponse
1010
from django.test.testcases import TestCase as DjangoTestCase
1111
from django.template import TemplateDoesNotExist
@@ -20,6 +20,11 @@
2020
from djcelery.views import task_webhook
2121
from djcelery.tests.req import MockRequest
2222

23+
try:
24+
from django.urls import reverse # Django 1.10+
25+
except ImportError:
26+
from django.core.urlresolvers import reverse
27+
2328

2429
def reversestar(name, **kwargs):
2530
return reverse(name, kwargs=kwargs)
@@ -77,13 +82,10 @@ def assertIn(self, expected, source, *args):
7782
except AttributeError:
7883
self.assertTrue(expected in source)
7984

80-
def assertDictContainsSubset(self, a, b, *args):
81-
try:
82-
DjangoTestCase.assertDictContainsSubset(self, a, b, *args)
83-
except AttributeError:
84-
for key, value in a.items():
85-
self.assertTrue(key in b)
86-
self.assertEqual(b[key], value)
85+
def assertDictContainsSubset(self, subset, dictionary, *args):
86+
for key, value in subset.items():
87+
self.assertIn(key, dictionary)
88+
self.assertEqual(dictionary[key], value)
8789

8890

8991
class test_task_apply(ViewTestCase):

tests/settings.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
RuntimeWarning, r'django\.db\.models\.fields')
99

1010
# import source code dir
11-
sys.path.insert(0, os.getcwd())
12-
sys.path.insert(0, os.path.join(os.getcwd(), os.pardir))
11+
here = os.path.abspath(os.path.dirname(__file__))
12+
sys.path.insert(0, here)
13+
sys.path.insert(0, os.path.join(here, os.pardir))
1314

1415
import djcelery # noqa
1516
djcelery.setup_loader()
@@ -19,7 +20,6 @@
1920
SITE_ID = 300
2021

2122
DEBUG = True
22-
TEMPLATE_DEBUG = DEBUG
2323

2424
ROOT_URLCONF = 'tests.urls'
2525
SECRET_KEY = 'skskqlqlaskdsd'
@@ -32,7 +32,7 @@
3232

3333
if not NO_NOSE:
3434
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
35-
here = os.path.abspath(os.path.dirname(__file__))
35+
3636
COVERAGE_EXCLUDE_MODULES = (
3737
'djcelery',
3838
'djcelery.tests.*',
@@ -84,6 +84,13 @@
8484
},
8585
}
8686

87+
TEMPLATES = [
88+
{
89+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
90+
'APP_DIRS': True,
91+
},
92+
]
93+
8794
INSTALLED_APPS = (
8895
'django.contrib.auth',
8996
'django.contrib.contenttypes',
@@ -101,4 +108,4 @@
101108

102109
USE_TZ = True
103110
TIME_ZONE = 'UTC'
104-
MIDDLEWARE_CLASSES = []
111+
MIDDLEWARE = MIDDLEWARE_CLASSES = []

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27-django{1.8,1.9,1.10}, py33-django1.8, py{34,35}-django{1.8,1.9,1.10},flake8
2+
envlist = py27-django{1.8,1.9,1.10}, py33-django1.8, py{34,35}-django{1.8,1.9,1.10}, flake8
33

44
[testenv]
55
sitepackages = False
@@ -14,7 +14,7 @@ setenv =
1414
PYTHONPATH={toxinidir}/tests
1515
DJANGO_SETTINGS_MODULE=settings
1616
commands =
17-
{posargs:python tests/manage.py test}
17+
{envpython} -Wall tests/manage.py test {posargs}
1818

1919
[testenv:flake8]
2020
basepython = python2.7

0 commit comments

Comments
 (0)