Skip to content

Commit 6e72ff3

Browse files
author
Pamela McA'Nulty
committed
Remove support for pre-1.8 django versions
1 parent d1d086f commit 6e72ff3

File tree

7 files changed

+49
-85
lines changed

7 files changed

+49
-85
lines changed

README.rst

Lines changed: 1 addition & 3 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.11a1.
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

django_coverage_plugin/plugin.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,22 @@ 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-
# django.template.backends.django gets loaded lazily, so return false
58-
# until they've been loaded
59-
if not hasattr(django.template, "backends"):
60-
return False
61-
if not hasattr(django.template.backends, "django"):
62-
return False
63-
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:
73-
raise DjangoTemplatePluginException(
74-
"Template debugging must be enabled in settings."
75-
)
76-
else:
77-
# Old-style settings.
78-
if not settings.TEMPLATE_DEBUG:
52+
# django.template.backends.django gets loaded lazily, so return false
53+
# until they've been loaded
54+
if not hasattr(django.template, "backends"):
55+
return False
56+
if not hasattr(django.template.backends, "django"):
57+
return False
58+
59+
if not hasattr(django.template.backends.django, "DjangoTemplates"):
60+
raise DjangoTemplatePluginException("Can't use non-Django templates.")
61+
62+
for engine in django.template.engines.all():
63+
if not isinstance(engine, django.template.backends.django.DjangoTemplates):
64+
raise DjangoTemplatePluginException(
65+
"Can't use non-Django templates."
66+
)
67+
if not engine.engine.debug:
7968
raise DjangoTemplatePluginException(
8069
"Template debugging must be enabled in settings."
8170
)

tests/plugin_test.py

Lines changed: 17 additions & 26 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."""
@@ -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 & 4 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
@@ -196,7 +195,6 @@ def test_templatetag(self):
196195
self.assertEqual(text, "{%\nurl 'entry_list'\n%}\n")
197196
self.assert_analysis([1, 2, 3])
198197

199-
@django_start_at(1, 5) # 1.4 had different syntax for {% url %}
200198
def test_url(self):
201199
self.make_template("""\
202200
{% url 'index' %}
@@ -206,7 +204,6 @@ def test_url(self):
206204
self.assertEqual(text, "/home\nnice.\n")
207205
self.assert_analysis([1, 2])
208206

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

0 commit comments

Comments
 (0)