diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6df6b36 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +sudo: false +language: python +python: + - "2.7" + - "3.4" + - "3.5" + - "3.6" +install: pip install tox-travis +script: tox diff --git a/AUTHORS.txt b/AUTHORS.txt index 9399eb3..8a697a9 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -3,3 +3,4 @@ contributions by: Jessamyn Smith Simon Charette +Pamela McA'Nulty diff --git a/README.rst b/README.rst index 20f1322..89877f4 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,12 @@ A `coverage.py`_ plugin to measure the coverage of Django templates. | |license| |versions| |djversions| |status| | |kit| |downloads| -Supported Python versions are 2.7, 3.4, and 3.5. Supported Django versions are -1.4 through 1.9. +Supported Python versions are 2.7, 3.4, 3.5 and 3.6. + +Supported Django versions are 1.4 through 1.10. + +Supported coverage.py versions are 4.0 and higher. + The plugin is pip installable:: @@ -23,7 +27,7 @@ To run it, add this setting to your .coveragerc file:: plugins = django_coverage_plugin -Then run your tests under coverage.py. It requires coverage.py 4.0 or later. +Then run your tests under coverage.py. You will see your templates listed in your coverage report along with your Python modules. @@ -43,6 +47,8 @@ template files are included in the report. Caveats ~~~~~~~ +Support for Django versions 1.4 through 1.7 should be considered deprecated. + Files included by the ``{% ssi %}`` tag are not included in the coverage measurements. @@ -54,6 +60,22 @@ Changes ~~~~~~~ +v1.4 --- 2017-01-15 +--------------------- + +Django 1.10.5 is now supported. + +Checking settings configuration is deferred so that settings.py is included +in coverage reporting. Fixes `issue 28`_. + +Only the ``django.template.backends.django.DjangoTemplates`` template engine is +supported, and it must be configured with ``['OPTIONS']['debug'] = True``. Fixes +`issue 27`_. + +.. _issue 28: https://github.com/nedbat/django_coverage_plugin/issues/28 +.. _issue 27: https://github.com/nedbat/django_coverage_plugin/issues/27 + + v1.3.1 --- 2016-06-02 --------------------- @@ -140,7 +162,7 @@ To run the tests:: .. |versions| image:: https://img.shields.io/pypi/pyversions/django_coverage_plugin.svg :target: https://pypi.python.org/pypi/django_coverage_plugin :alt: Python versions supported -.. |djversions| image:: https://img.shields.io/badge/Django-1.4, 1.5, 1.6, 1.7, 1.8, 1.9-44b78b.svg +.. |djversions| image:: https://img.shields.io/badge/Django-1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10 :target: https://pypi.python.org/pypi/django_coverage_plugin :alt: Django versions supported .. |status| image:: https://img.shields.io/pypi/status/django_coverage_plugin.svg diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 961088e..c9fdeac 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -13,7 +13,6 @@ import django import django.template -from django.core.exceptions import ImproperlyConfigured from django.template.base import ( Lexer, TextNode, NodeList, Template, TOKEN_BLOCK, TOKEN_MAPPING, TOKEN_TEXT, TOKEN_VAR, @@ -43,28 +42,29 @@ def check_debug(): to do its work. Check that the setting is correct, and raise an exception if it is not. + Returns True if the debug check was performed, False otherwise """ - # The settings for templates changed in Django 1.8 from TEMPLATE_DEBUG to - # TEMPLATES[..]['debug']. Django 1.9 tolerated both forms, 1.10 insists on - # the new form. Don't try to be version-specific here. If the new - # settings exist, use them, otherwise use the old. - from django.conf import settings - try: - templates = getattr(settings, 'TEMPLATES', []) - except ImproperlyConfigured: - # Maybe there are no settings at all. We are fine with this. Our - # code will need settings, but if this program we're in runs without - # settings, then it must be that it never uses templates, and our code - # will never try to use the settings anyway. - return - - if templates: - for template_settings in templates: - if template_settings['BACKEND'] != 'django.template.backends.django.DjangoTemplates': - raise DjangoTemplatePluginException("Can't use non-Django templates.") - if not template_settings.get('OPTIONS', {}).get('debug', False): + if not settings.configured: + return False + + if django.VERSION >= (1, 8): + # Django 1.8+ handles both old and new-style settings and converts them + # into template engines, so we don't need to depend on settings values + # directly and can look at the resulting configured objects + if not hasattr(django.template.backends, "django"): + raise DjangoTemplatePluginException("Can't use non-Django templates.") + + if not hasattr(django.template.backends.django, "DjangoTemplates"): + raise DjangoTemplatePluginException("Can't use non-Django templates.") + + for engine in django.template.engines.all(): + if not isinstance(engine, django.template.backends.django.DjangoTemplates): + raise DjangoTemplatePluginException( + "Can't use non-Django templates." + ) + if not engine.engine.debug: raise DjangoTemplatePluginException( "Template debugging must be enabled in settings." ) @@ -75,6 +75,8 @@ def check_debug(): "Template debugging must be enabled in settings." ) + return True + if django.VERSION >= (1, 9): # Since we are grabbing at internal details, we have to adapt as they @@ -151,8 +153,9 @@ def sys_info(self): def file_tracer(self, filename): if filename.startswith(self.django_template_dir): if not self.debug_checked: - check_debug() - self.debug_checked = True + # Keep calling check_debug until it returns True, which it + # will only do after settings have been configured + self.debug_checked = check_debug() return self return None diff --git a/setup.py b/setup.py index d18563e..c45e061 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.4 Programming Language :: Python :: 3.5 +Programming Language :: Python :: 3.6 Programming Language :: Python :: Implementation :: CPython Programming Language :: Python :: Implementation :: PyPy Topic :: Software Development :: Quality Assurance diff --git a/tests/__init__.py b/tests/__init__.py index 14ca376..038b3ad 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,6 +12,7 @@ def index(request): """A bogus view to use in the urls below.""" pass + urlpatterns = [ url(r'^home$', index, name='index'), ] diff --git a/tests/plugin_test.py b/tests/plugin_test.py index 5eb1d8b..db1698e 100644 --- a/tests/plugin_test.py +++ b/tests/plugin_test.py @@ -61,15 +61,18 @@ def test_settings(): return the_settings + settings.configure(**test_settings()) if hasattr(django, "setup"): django.setup() +from django.template import Context, Template # noqa +from django.template.loader import get_template # noqa +from django.test import TestCase # noqa -from django.template import Context, Template # noqa -from django.template.loader import get_template # noqa -from django.test import TestCase # noqa +if django.VERSION >= (1, 8): + from django.template.backends.django import DjangoTemplates # noqa class DjangoPluginTestCase(StdStreamCapturingMixin, TempDirMixin, TestCase): diff --git a/tox.ini b/tox.ini index 340ca79..747f472 100644 --- a/tox.ini +++ b/tox.ini @@ -14,9 +14,10 @@ [tox] envlist = - py27-django{14,15,16,17,18,19,19tip,tip}, - py34-django{15,16,17,18,19,19tip,tip}, - py35-django{18,19,19tip,tip}, + py27-django{14,15,16,17,18,19,110,110tip,tip}, + py34-django{15,16,17,18,19,110,110tip,tip}, + py35-django{18,19,110,110tip,tip}, + py36-django{18,19,110,110tip,tip}, check,doc [testenv] @@ -28,7 +29,8 @@ deps = django17: Django >=1.7, <1.8 django18: Django >=1.8, <1.9 django19: Django >=1.9, <1.10 - django19tip: https://github.com/django/django/archive/stable/1.9.x.tar.gz + django110: Django >=1.10, <1.11 + django110tip: https://github.com/django/django/archive/stable/1.10.x.tar.gz djangotip: https://github.com/django/django/archive/master.tar.gz commands =