Skip to content

Commit 6a4a001

Browse files
authored
Support Django 2.0 (#521)
* tox: use shorter names with Django factors * tox: add dj20 * Fix test_urls * Travis: a single pypy3 test is enough for now * tox.ini: cleanup/fix default envlist * Travis: drop TOXENV=py27-pytest3-dj20-postgres * tox: use default options for -r * fixes for dj20 * .travis.yml: fix travis_retry_pip hack more
1 parent 3e5d16f commit 6a4a001

File tree

4 files changed

+72
-51
lines changed

4 files changed

+72
-51
lines changed

.travis.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,54 @@ matrix:
66
fast_finish: true
77
include:
88
- python: 3.6
9-
env: TOXENV=py36-pytest3-djangomaster-postgres
9+
env: TOXENV=py36-pytest3-djmaster-postgres
1010
- python: 3.6
11-
env: TOXENV=py36-pytest3-django1.11-postgres
11+
env: TOXENV=py36-pytest3-dj20-postgres
1212
- python: 3.6
13-
env: TOXENV=py36-pytest3-django1.10-postgres
13+
env: TOXENV=py36-pytest3-dj111-postgres
1414
- python: 3.6
15-
env: TOXENV=py36-pytest3-django1.9-postgres
15+
env: TOXENV=py36-pytest3-dj110-postgres
1616
- python: 3.6
17-
env: TOXENV=py36-pytest3-django1.8-postgres
17+
env: TOXENV=py36-pytest3-dj19-postgres
18+
- python: 3.6
19+
env: TOXENV=py36-pytest3-dj18-postgres
1820
- python: 3.6
1921
env: TOXENV=py36-checkqa
2022

2123
- python: 3.5
22-
env: TOXENV=py35-pytest3-django1.11-postgres
24+
env: TOXENV=py35-pytest3-dj111-postgres
2325

2426
- python: 3.4
25-
env: TOXENV=py34-pytest3-django1.11-postgres
27+
env: TOXENV=py34-pytest3-dj111-postgres
2628

2729
- python: 3.3
28-
env: TOXENV=py34-pytest3-django1.8-postgres
30+
env: TOXENV=py34-pytest3-dj18-postgres
2931

3032
- python: 2.7
31-
env: TOXENV=py27-pytest3-django1.11-mysql_innodb
33+
env: TOXENV=py27-pytest3-dj111-mysql_innodb
3234
- python: 2.7
33-
env: TOXENV=py27-pytest3-django1.11-mysql_myisam
35+
env: TOXENV=py27-pytest3-dj111-mysql_myisam
3436
- python: 2.7
35-
env: TOXENV=py27-pytest3-django1.11-postgres
37+
env: TOXENV=py27-pytest3-dj111-postgres
3638
- python: 2.7
37-
env: TOXENV=py27-pytest3-django1.10-postgres
39+
env: TOXENV=py27-pytest3-dj110-postgres
3840
- python: 2.7
39-
env: TOXENV=py27-pytest3-django1.9-postgres
41+
env: TOXENV=py27-pytest3-dj19-postgres
4042
- python: 2.7
41-
env: TOXENV=py27-pytest3-django1.8-postgres
43+
env: TOXENV=py27-pytest3-dj18-postgres
4244
- python: 2.7
43-
env: TOXENV=py27-pytest3-django1.7-postgres
45+
env: TOXENV=py27-pytest3-dj17-postgres
4446
- python: 2.7
4547
env: TOXENV=py27-checkqa
4648

4749
- python: pypy
48-
env: TOXENV=pypy-pytest3-django1.11-sqlite_file
50+
env: TOXENV=pypy-pytest3-dj111-sqlite_file
4951

5052
- python: pypy3
51-
env: TOXENV=pypy3-pytest3-django1.8-sqlite
52-
- python: pypy3
53-
env: TOXENV=pypy3-pytest3-django1.10-sqlite_file
53+
env: TOXENV=pypy3-pytest3-dj110-sqlite_file
5454

5555
allow_failures:
56-
- env: TOXENV=py36-pytest3-djangomaster-postgres
56+
- env: TOXENV=py36-pytest3-djmaster-postgres
5757

5858
cache:
5959
directories:
@@ -68,9 +68,8 @@ install:
6868
- declare -f travis_retry >> bin/travis_retry_pip
6969
- printf '\necho "Using pip-wrapper.." >&2\ntravis_retry pip "$@"' >> bin/travis_retry_pip
7070
- chmod +x bin/travis_retry_pip
71-
- sed -i.bak 's/^\[testenv\]/\0\ninstall_command = travis_retry_pip install {opts} {packages}/' tox.ini
71+
- sed -i.bak 's/^\[testenv\]/\0\nwhitelist_externals = travis_retry_pip\ninstall_command = travis_retry_pip install {opts} {packages}/' tox.ini
7272
- if diff tox.ini tox.ini.bak; then exit 1; fi
73-
- printf '\nwhitelist_externals = travis_retry_pip' >> tox.ini
7473

7574
- pip install tox==2.7.0
7675
- |

tests/test_django_settings_module.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,22 @@ class TestApp(AppConfig):
291291
name = 'tpkg.app'
292292
293293
def ready(self):
294-
print ('READY(): populating=%r' % apps._lock.locked())
294+
try:
295+
populating = apps.loading
296+
except AttributeError: # Django < 2.0
297+
populating = apps._lock.locked()
298+
print('READY(): populating=%r' % populating)
295299
""", 'apps.py')
296300

297301
django_testdir.create_app_file("""
298302
from django.apps import apps
299303
300-
print ('IMPORT: populating=%r,ready=%r' % (
301-
apps._lock.locked(), apps.ready))
304+
try:
305+
populating = apps.loading
306+
except AttributeError: # Django < 2.0
307+
populating = apps._lock.locked()
308+
309+
print('IMPORT: populating=%r,ready=%r' % (populating, apps.ready))
302310
SOME_THING = 1234
303311
""", 'models.py')
304312

@@ -308,14 +316,21 @@ def ready(self):
308316
from tpkg.app.models import SOME_THING
309317
310318
def test_anything():
311-
print ('TEST: populating=%r,ready=%r' % (
312-
apps._lock.locked(), apps.ready))
319+
try:
320+
populating = apps.loading
321+
except AttributeError: # Django < 2.0
322+
populating = apps._lock.locked()
323+
324+
print('TEST: populating=%r,ready=%r' % (populating, apps.ready))
313325
""")
314326

315327
result = django_testdir.runpytest_subprocess('-s', '--tb=line')
316328
result.stdout.fnmatch_lines(['*IMPORT: populating=True,ready=False*'])
317329
result.stdout.fnmatch_lines(['*READY(): populating=True*'])
318-
result.stdout.fnmatch_lines(['*TEST: populating=False,ready=True*'])
330+
if django.VERSION < (2, 0):
331+
result.stdout.fnmatch_lines(['*TEST: populating=False,ready=True*'])
332+
else:
333+
result.stdout.fnmatch_lines(['*TEST: populating=True,ready=True*'])
319334
assert result.ret == 0
320335

321336

tests/test_urls.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import pytest
22
from django.conf import settings
3-
from django.core.urlresolvers import is_valid_path
43
from django.utils.encoding import force_text
54

65

76
@pytest.mark.urls('pytest_django_test.urls_overridden')
87
def test_urls():
8+
try:
9+
from django.urls import is_valid_path
10+
except ImportError:
11+
from django.core.urlresolvers import is_valid_path
912
assert settings.ROOT_URLCONF == 'pytest_django_test.urls_overridden'
1013
assert is_valid_path('/overridden_url/')
1114

@@ -28,7 +31,10 @@ def fake_view(request):
2831
""")
2932

3033
testdir.makepyfile("""
31-
from django.core.urlresolvers import reverse, NoReverseMatch
34+
try:
35+
from django.urls import reverse, NoReverseMatch
36+
except ImportError: # Django < 2.0
37+
from django.core.urlresolvers import reverse, NoReverseMatch
3238
import pytest
3339
3440
@pytest.mark.urls('myurls')
@@ -68,7 +74,10 @@ def fake_view(request):
6874
""")
6975

7076
testdir.makepyfile("""
71-
from django.core.urlresolvers import reverse, NoReverseMatch
77+
try:
78+
from django.urls import reverse, NoReverseMatch
79+
except ImportError: # Django < 2.0
80+
from django.core.urlresolvers import reverse, NoReverseMatch
7281
import pytest
7382
7483
@pytest.mark.urls('myurls')

tox.ini

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
[tox]
22
envlist =
3-
- py{35,36}-pytest3-django{master,1.11,1.10,1.9,1.8}-postgres
4-
- py34-pytest3-django{1.11,1.10}-postgres
5-
- py33-pytest3-django1.8-postgres
6-
- py27-pytest3-django{1.11,1.10}-{mysql_innodb,mysql_myisam,postgres}
7-
- py27-pytest3-django{1.11,1.10,1.9,1.8,1.7}-postgres
8-
- pypy3-pytest3-django1.8-{sqlite,sqlite_file}
9-
- pypy3-pytest2-django1.8-sqlite_file
10-
- pypy-pytest3-django1.10-sqlite_file
11-
- py{36,27}-checkqa
3+
- py{35,36}-pytest3-dj{20,111,110,19,18}-postgres
4+
- py34-pytest3-dj{20,111,110}-postgres
5+
- py33-pytest3-dj18-postgres
6+
- py27-pytest3-dj{111,110}-{mysql_innodb,mysql_myisam,postgres}
7+
- py27-pytest3-dj{111,110,19,18,17}-postgres
8+
- py{36,py27}-checkqa
129

1310
[testenv]
1411
deps =
@@ -18,12 +15,13 @@ deps =
1815

1916
checkqa: flake8
2017

21-
djangomaster: https://github.com/django/django/archive/master.tar.gz
22-
django1.11: Django>=1.11,<1.12
23-
django1.10: Django>=1.10,<1.11
24-
django1.9: Django>=1.9,<1.10
25-
django1.8: Django>=1.8,<1.9
26-
django1.7: Django>=1.7,<1.8
18+
djmaster: https://github.com/django/django/archive/master.tar.gz
19+
dj20: Django>=2.0a1,<2.1
20+
dj111: Django>=1.11,<1.12
21+
dj110: Django>=1.10,<1.11
22+
dj19: Django>=1.9,<1.10
23+
dj18: Django>=1.8,<1.9
24+
dj17: Django>=1.7,<1.8
2725

2826
mysql_myisam: mysql-python==1.2.5
2927
mysql_innodb: mysql-python==1.2.5
@@ -40,11 +38,11 @@ usedevelop = True
4038
commands =
4139
checkqa: flake8 --version
4240
checkqa: flake8 --show-source --statistics {posargs:pytest_django pytest_django_test}
43-
mysql_innodb: pytest --ds=pytest_django_test.settings_mysql_innodb --strict -r fEsxXw {posargs:tests}
44-
mysql_myisam: pytest --ds=pytest_django_test.settings_mysql_myisam --strict -r fEsxXw {posargs:tests}
45-
postgres: pytest --ds=pytest_django_test.settings_postgres --strict -r fEsxXw {posargs:tests}
46-
sqlite: pytest --ds=pytest_django_test.settings_sqlite --strict -r fEsxXw {posargs:tests}
47-
sqlite_file: pytest --ds=pytest_django_test.settings_sqlite_file --strict -r fEsxXw {posargs:tests}
41+
mysql_innodb: pytest --ds=pytest_django_test.settings_mysql_innodb --strict {posargs:tests}
42+
mysql_myisam: pytest --ds=pytest_django_test.settings_mysql_myisam --strict {posargs:tests}
43+
postgres: pytest --ds=pytest_django_test.settings_postgres --strict {posargs:tests}
44+
sqlite: pytest --ds=pytest_django_test.settings_sqlite --strict {posargs:tests}
45+
sqlite_file: pytest --ds=pytest_django_test.settings_sqlite_file --strict {posargs:tests}
4846

4947
[testenv:doc8]
5048
basepython = python3.6

0 commit comments

Comments
 (0)