Skip to content

Commit eb36ec4

Browse files
authored
Merge pull request #35 from PamelaM/pm/remove_support_pre_dj18_and_support_dj111
Pm/remove support prior to Django 1.8 and support Django 1.11
2 parents e469822 + 4167ba8 commit eb36ec4

File tree

9 files changed

+69
-104
lines changed

9 files changed

+69
-104
lines changed

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A `coverage.py`_ plugin to measure the coverage of Django templates.
1414
1515
Supported Python versions are 2.7, 3.4, 3.5 and 3.6.
1616

17-
Supported Django versions are 1.4 through 1.10.
17+
Supported Django versions are 1.8 through 1.11b1.
1818

1919
Supported coverage.py versions are 4.0 and higher.
2020

@@ -49,8 +49,6 @@ template files are included in the report.
4949
Caveats
5050
~~~~~~~
5151

52-
Support for Django versions 1.4 through 1.7 should be considered deprecated.
53-
5452
Files included by the ``{% ssi %}`` tag are not included in the coverage
5553
measurements.
5654

@@ -61,6 +59,12 @@ plural text, so both are marked as used if the tag is used.
6159
Changes
6260
~~~~~~~
6361

62+
63+
v1.5.0 --- 2017-02-23
64+
---------------------
65+
66+
Removes support for Django versions below 1.8. Validates support for Django version 1.11b1
67+
6468
v1.4.2 --- 2017-02-06
6569
---------------------
6670

@@ -179,7 +183,7 @@ To run the tests::
179183
.. |versions| image:: https://img.shields.io/pypi/pyversions/django_coverage_plugin.svg
180184
:target: https://pypi.python.org/pypi/django_coverage_plugin
181185
:alt: Python versions supported
182-
.. |djversions| image:: https://img.shields.io/badge/Django-1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10-44b78b.svg
186+
.. |djversions| image:: https://img.shields.io/badge/Django-1.8, 1.9, 1.10, 1.11b1.svg
183187
:target: https://pypi.python.org/pypi/django_coverage_plugin
184188
:alt: Django versions supported
185189
.. |status| image:: https://img.shields.io/pypi/status/django_coverage_plugin.svg

django_coverage_plugin/plugin.py

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,27 @@ def check_debug():
4949
if not settings.configured:
5050
return False
5151

52-
if django.VERSION >= (1, 8):
53-
# Django 1.8+ handles both old and new-style settings and converts them
54-
# into template engines, so we don't need to depend on settings values
55-
# directly and can look at the resulting configured objects
56-
57-
# I _think_ this check is all that's needed and the 3 "hasattr" checks
58-
# below can be removed, but it's not clear how to verify that
59-
from django.apps import apps
60-
if not apps.ready:
61-
return False
62-
63-
# django.template.backends.django gets loaded lazily, so return false
64-
# until they've been loaded
65-
if not hasattr(django.template, "backends"):
66-
return False
67-
if not hasattr(django.template.backends, "django"):
68-
return False
69-
70-
if not hasattr(django.template.backends.django, "DjangoTemplates"):
71-
raise DjangoTemplatePluginException("Can't use non-Django templates.")
72-
73-
for engine in django.template.engines.all():
74-
if not isinstance(engine, django.template.backends.django.DjangoTemplates):
75-
raise DjangoTemplatePluginException(
76-
"Can't use non-Django templates."
77-
)
78-
if not engine.engine.debug:
79-
raise DjangoTemplatePluginException(
80-
"Template debugging must be enabled in settings."
81-
)
82-
else:
83-
# Old-style settings.
84-
if not settings.TEMPLATE_DEBUG:
52+
# I _think_ this check is all that's needed and the 3 "hasattr" checks
53+
# below can be removed, but it's not clear how to verify that
54+
from django.apps import apps
55+
if not apps.ready:
56+
return False
57+
58+
# django.template.backends.django gets loaded lazily, so return false
59+
# until they've been loaded
60+
if not hasattr(django.template, "backends"):
61+
return False
62+
if not hasattr(django.template.backends, "django"):
63+
return False
64+
if not hasattr(django.template.backends.django, "DjangoTemplates"):
65+
raise DjangoTemplatePluginException("Can't use non-Django templates.")
66+
67+
for engine in django.template.engines.all():
68+
if not isinstance(engine, django.template.backends.django.DjangoTemplates):
69+
raise DjangoTemplatePluginException(
70+
"Can't use non-Django templates."
71+
)
72+
if not engine.engine.debug:
8573
raise DjangoTemplatePluginException(
8674
"Template debugging must be enabled in settings."
8775
)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
setup(
2424
name='django_coverage_plugin',
25-
version='1.4.2',
25+
version='1.5.0',
2626
description='Django template coverage.py plugin',
2727
author='Ned Batchelder',
2828
author_email='[email protected]',
2929
url='https://github.com/nedbat/django_coverage_plugin',
3030
packages=['django_coverage_plugin'],
3131
install_requires=[
32-
'Django >= 1.4',
32+
'Django >= 1.8',
3333
'coverage >= 4.0',
3434
'six >= 1.4.0',
3535
],

tests/plugin_test.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,22 @@ def test_settings():
3535
'ROOT_URLCONF': 'tests',
3636
}
3737

38-
if django.VERSION >= (1, 8):
39-
the_settings.update({
40-
'TEMPLATES': [
41-
{
42-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
43-
'DIRS': ['templates'], # where the tests put things.
44-
'OPTIONS': {
45-
'debug': True,
46-
},
38+
the_settings.update({
39+
'TEMPLATES': [
40+
{
41+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
42+
'DIRS': ['templates'], # where the tests put things.
43+
'OPTIONS': {
44+
'debug': True,
4745
},
48-
],
49-
})
46+
},
47+
],
48+
})
5049

51-
if django.VERSION < (1, 10):
52-
# for {% ssi %}
53-
the_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']
50+
if django.VERSION < (1, 10):
51+
# for {% ssi %}
52+
the_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']
5453

55-
else:
56-
the_settings.update({
57-
'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %}
58-
'TEMPLATE_DEBUG': True,
59-
'TEMPLATE_DIRS': ['templates'], # where the tests put things.
60-
})
6154

6255
return the_settings
6356

@@ -68,12 +61,10 @@ def test_settings():
6861
django.setup()
6962

7063
from django.template import Context, Template # noqa
64+
from django.template.backends.django import DjangoTemplates # noqa
7165
from django.template.loader import get_template # noqa
7266
from django.test import TestCase # noqa
7367

74-
if django.VERSION >= (1, 8):
75-
from django.template.backends.django import DjangoTemplates # noqa
76-
7768

7869
class DjangoPluginTestCase(StdStreamCapturingMixin, TempDirMixin, TestCase):
7970
"""A base class for all our tests."""
@@ -116,7 +107,7 @@ def run_django_coverage(
116107
str: the text produced by the template.
117108
118109
"""
119-
use_real_context = (django.VERSION < (1, 8))
110+
use_real_context = False
120111

121112
if options is None:
122113
options = {'source': ["."]}
@@ -256,7 +247,7 @@ def squashed(s):
256247
def django_start_at(*needed_version):
257248
"""A decorator for tests to require a minimum version of Django.
258249
259-
@django_start_at(1, 8) # Don't run the test on 1.7 or lower.
250+
@django_start_at(1, 10) # Don't run the test on 1.10 or lower.
260251
def test_thing(self):
261252
...
262253
@@ -267,10 +258,10 @@ def test_thing(self):
267258
return unittest.skip("Django version must be newer")
268259

269260

270-
def django_stop_at(*needed_version):
261+
def django_stop_before(*needed_version):
271262
"""A decorator for tests to require a maximum version of Django.
272263
273-
@django_stop_at(1, 8) # Don't run the test on 1.8 or higher.
264+
@django_stop_before(1, 10) # Don't run the test on 1.10 or higher.
274265
def test_thing(self):
275266
...
276267

tests/test_engines.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33

44
"""Tests of multiple engines for django_coverage_plugin."""
55

6-
from .plugin_test import DjangoPluginTestCase, django_start_at
6+
from .plugin_test import DjangoPluginTestCase
7+
from django.test import modify_settings
78

89

9-
@django_start_at(1, 8)
1010
class MultipleEngineTests(DjangoPluginTestCase):
1111
def setUp(self):
1212
super(MultipleEngineTests, self).setUp()
1313

14-
# Move to module imports once we drop support for Django < 1.7
15-
from django.test import modify_settings
1614
engine = {
1715
'NAME': 'other',
1816
'BACKEND': 'django.template.backends.django.DjangoTemplates',
@@ -38,7 +36,6 @@ def test_string_template(self):
3836
self.assertEqual(text, 'Hello')
3937

4038
def test_third_engine_not_debug(self):
41-
from django.test import modify_settings
4239
engine3 = {
4340
'NAME': 'notdebug',
4441
'BACKEND': 'django.template.backends.django.DjangoTemplates',

tests/test_extends.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""Tests of template inheritance for django_coverage_plugin."""
55

6-
from .plugin_test import DjangoPluginTestCase, django_start_at, django_stop_at
6+
from .plugin_test import DjangoPluginTestCase, django_stop_before
77

88

99
class BlockTest(DjangoPluginTestCase):
@@ -148,9 +148,8 @@ def test_include(self):
148148
self.assert_analysis([1, 2], name="nested.html")
149149

150150

151-
# {% ssi %} is in earlier Djangos than 1.5, but doesn't trace properly.
152-
@django_start_at(1, 5)
153-
@django_stop_at(1, 10)
151+
# {% ssi %} is in earlier Djangos than 1.9, but doesn't trace properly.
152+
@django_stop_before(1, 10)
154153
class SsiTest(DjangoPluginTestCase):
155154
"""Test {% ssi %}, which does not trace the included file."""
156155

tests/test_settings.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,23 @@
33

44
"""Settings tests for django_coverage_plugin."""
55

6-
import django
76
from django.test.utils import override_settings
87

9-
from .plugin_test import DjangoPluginTestCase, test_settings, django_start_at
8+
from .plugin_test import DjangoPluginTestCase, test_settings
109

1110

1211
# Make settings overrides for tests below.
13-
if django.VERSION >= (1, 8):
14-
NON_DJANGO_BACKEND = 'django.template.backends.dummy.TemplateStrings'
12+
NON_DJANGO_BACKEND = 'django.template.backends.dummy.TemplateStrings'
1513

16-
DEBUG_FALSE_OVERRIDES = test_settings()
17-
DEBUG_FALSE_OVERRIDES['TEMPLATES'][0]['OPTIONS']['debug'] = False
14+
DEBUG_FALSE_OVERRIDES = test_settings()
15+
DEBUG_FALSE_OVERRIDES['TEMPLATES'][0]['OPTIONS']['debug'] = False
1816

19-
NO_OPTIONS_OVERRIDES = test_settings()
20-
del NO_OPTIONS_OVERRIDES['TEMPLATES'][0]['OPTIONS']
17+
NO_OPTIONS_OVERRIDES = test_settings()
18+
del NO_OPTIONS_OVERRIDES['TEMPLATES'][0]['OPTIONS']
2119

22-
OTHER_ENGINE_OVERRIDES = test_settings()
23-
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['BACKEND'] = NON_DJANGO_BACKEND
24-
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['OPTIONS'] = {}
25-
else:
26-
DEBUG_FALSE_OVERRIDES = {'TEMPLATE_DEBUG': False}
27-
NO_OPTIONS_OVERRIDES = OTHER_ENGINE_OVERRIDES = {}
20+
OTHER_ENGINE_OVERRIDES = test_settings()
21+
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['BACKEND'] = NON_DJANGO_BACKEND
22+
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['OPTIONS'] = {}
2823

2924

3025
class SettingsTest(DjangoPluginTestCase):
@@ -36,14 +31,12 @@ def test_debug_false(self):
3631
with self.assert_plugin_disabled("Template debugging must be enabled in settings."):
3732
self.run_django_coverage()
3833

39-
@django_start_at(1, 8)
4034
@override_settings(**NO_OPTIONS_OVERRIDES)
4135
def test_no_options(self):
4236
self.make_template('Hello')
4337
with self.assert_plugin_disabled("Template debugging must be enabled in settings."):
4438
self.run_django_coverage()
4539

46-
@django_start_at(1, 8)
4740
@override_settings(**OTHER_ENGINE_OVERRIDES)
4841
def test_other_engine(self):
4942
self.make_template('Hello')

tests/test_simple.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"""Simple tests for django_coverage_plugin."""
66

7-
from .plugin_test import DjangoPluginTestCase, django_start_at
7+
from .plugin_test import DjangoPluginTestCase
88

99

1010
# 200 Unicode chars: snowman + poo.
@@ -155,7 +155,6 @@ def test_firstof(self):
155155
self.assertEqual(text, "B\nB\nquux\n")
156156
self.assert_analysis([1, 2, 3])
157157

158-
@django_start_at(1, 8)
159158
def test_lorem(self):
160159
self.make_template("""\
161160
First
@@ -176,7 +175,6 @@ def test_now(self):
176175
self.assertEqual(text, "Now:\nnow\n.\n")
177176
self.assert_analysis([1, 2, 3])
178177

179-
@django_start_at(1, 8)
180178
def test_now_as(self):
181179
self.make_template("""\
182180
{% now "\\n\\o\\w" as right_now %}
@@ -196,7 +194,6 @@ def test_templatetag(self):
196194
self.assertEqual(text, "{%\nurl 'entry_list'\n%}\n")
197195
self.assert_analysis([1, 2, 3])
198196

199-
@django_start_at(1, 5) # 1.4 had different syntax for {% url %}
200197
def test_url(self):
201198
self.make_template("""\
202199
{% url 'index' %}
@@ -206,7 +203,6 @@ def test_url(self):
206203
self.assertEqual(text, "/home\nnice.\n")
207204
self.assert_analysis([1, 2])
208205

209-
@django_start_at(1, 5) # {% verbatim %} is new in 1.5
210206
def test_verbatim(self):
211207
self.make_template("""\
212208
1

tox.ini

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@
1414

1515
[tox]
1616
envlist =
17-
py27-django{14,15,16,17,18,19,110,110tip,tip},
18-
py34-django{15,16,17,18,19,110,110tip,tip},
19-
py35-django{18,19,110,110tip,tip},
20-
py36-django{18,19,110,110tip,tip},
17+
py27-django{18,19,110,110tip,111tip},
18+
py34-django{18,19,110,110tip,111tip,tip},
19+
py35-django{18,19,110,110tip,111tip,tip},
20+
py36-django{18,19,110,110tip,111tip,tip},
2121
check,doc
2222

2323
[testenv]
2424
deps =
2525
unittest-mixins==1.1
26-
django14: Django >=1.4, <1.5
27-
django15: Django >=1.5, <1.6
28-
django16: Django >=1.6, <1.7
29-
django17: Django >=1.7, <1.8
3026
django18: Django >=1.8, <1.9
3127
django19: Django >=1.9, <1.10
3228
django110: Django >=1.10, <1.11
3329
django110tip: https://github.com/django/django/archive/stable/1.10.x.tar.gz
30+
django111tip: https://github.com/django/django/archive/stable/1.11.x.tar.gz
3431
djangotip: https://github.com/django/django/archive/master.tar.gz
3532

3633
commands =

0 commit comments

Comments
 (0)