From 43bc9fe13c5ff479208de8fab84db91efaec0b47 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 Jan 2017 21:27:09 -0500 Subject: [PATCH 01/13] =?UTF-8?q?Don=E2=80=99t=20check=20settings=20until?= =?UTF-8?q?=20it=E2=80=99s=20been=20configured?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django_coverage_plugin/plugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 961088e..685ff19 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -43,6 +43,7 @@ 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 @@ -51,6 +52,9 @@ def check_debug(): from django.conf import settings + if not settings.configured: + return False + try: templates = getattr(settings, 'TEMPLATES', []) except ImproperlyConfigured: @@ -58,7 +62,7 @@ def check_debug(): # 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 + return True if templates: for template_settings in templates: @@ -75,6 +79,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 +157,7 @@ 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 + self.debug_checked = check_debug() return self return None From b805e95cde9fd0a663aa0b645a6e53818ae37adb Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 Jan 2017 21:36:46 -0500 Subject: [PATCH 02/13] Fix tox check failures --- tests/__init__.py | 1 + tests/plugin_test.py | 1 + 2 files changed, 2 insertions(+) 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..05e0075 100644 --- a/tests/plugin_test.py +++ b/tests/plugin_test.py @@ -61,6 +61,7 @@ def test_settings(): return the_settings + settings.configure(**test_settings()) if hasattr(django, "setup"): From f97e0d39d9e308b01f58b93a60db94dba362871f Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 Jan 2017 21:49:44 -0500 Subject: [PATCH 03/13] Add check_debug comment in file_tracer --- django_coverage_plugin/plugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 685ff19..4cc6bf1 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -157,6 +157,8 @@ def sys_info(self): def file_tracer(self, filename): if filename.startswith(self.django_template_dir): if not self.debug_checked: + # 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 From 764ea0654223162fdb5be1b6f4726c616cddfbb9 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sat, 14 Jan 2017 14:20:12 -0500 Subject: [PATCH 04/13] check_debug uses django.template.engines For DJ versions 1.8+ --- django_coverage_plugin/plugin.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 4cc6bf1..0e0ac85 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -55,20 +55,17 @@ def check_debug(): if not settings.configured: return False - 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 True - - 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 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 + for engine in django.template.engines.all(): + if not isinstance(engine, django.template.backends.django.DjangoTemplates): + raise DjangoTemplatePluginException( + "Can't use non-Django templates. Found '%s': %s" % + (engine.name, engine) + ) + if not engine.engine.debug: raise DjangoTemplatePluginException( "Template debugging must be enabled in settings." ) From 5f06a73d93d3ee6cc1108e9816a8cd4ea8f5ea83 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sat, 14 Jan 2017 14:24:05 -0500 Subject: [PATCH 05/13] Remove unused import, and redundant comment --- django_coverage_plugin/plugin.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 0e0ac85..9b2133a 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, @@ -45,11 +44,6 @@ def check_debug(): 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 if not settings.configured: @@ -58,7 +52,7 @@ def check_debug(): 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 + # directly and can look at the resulting configured objects for engine in django.template.engines.all(): if not isinstance(engine, django.template.backends.django.DjangoTemplates): raise DjangoTemplatePluginException( From bee7d68da2dde268fc7b0f535b04a5bd2778fa48 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 09:34:46 -0500 Subject: [PATCH 06/13] Fix check_debug --- django_coverage_plugin/plugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 9b2133a..c9fdeac 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -53,11 +53,16 @@ def check_debug(): # 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. Found '%s': %s" % - (engine.name, engine) + "Can't use non-Django templates." ) if not engine.engine.debug: raise DjangoTemplatePluginException( From dc47974efbf54d49eeba211bea6364bf9ab00003 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 09:35:03 -0500 Subject: [PATCH 07/13] Fix issue #26 - Django 1.10 support --- tests/plugin_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/plugin_test.py b/tests/plugin_test.py index 05e0075..db1698e 100644 --- a/tests/plugin_test.py +++ b/tests/plugin_test.py @@ -67,10 +67,12 @@ def 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): From 5a9fb78839f47c5829c64e0788264e4b12e63b2a Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 09:35:31 -0500 Subject: [PATCH 08/13] Add django 1.10 to tox --- tox.ini | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 340ca79..1c01b7d 100644 --- a/tox.ini +++ b/tox.ini @@ -14,9 +14,9 @@ [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}, check,doc [testenv] @@ -28,7 +28,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 = From 0e1eb6f54570b4a2bfacb92ed691ddd98c23c155 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 12:27:13 -0500 Subject: [PATCH 09/13] Add python 3.6 to tox.ini --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 1c01b7d..747f472 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ envlist = 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] From efc60b7cb91d5267876f57eec26c23a5cf07626b Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 12:39:47 -0500 Subject: [PATCH 10/13] Add travis-ci support --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml 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 From 8709cbc4a2ec3171c560173f7352c03ccb5c62bf Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 16:30:19 -0500 Subject: [PATCH 11/13] Add Pam to authors and update the README.rst --- AUTHORS.txt | 1 + README.rst | 26 +++++++++++++++++++++++--- setup.py | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) 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..d3c06eb 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,10 @@ 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 +25,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 +45,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 +58,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 --------------------- 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 From 911ebf418afe552c2b3ff791833472688f2c9008 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 16:33:51 -0500 Subject: [PATCH 12/13] Fix readme layout --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index d3c06eb..705bc0b 100644 --- a/README.rst +++ b/README.rst @@ -67,7 +67,7 @@ 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 +supported, and it must be configured with ``['OPTIONS']['debug'] = True``. Fixes `issue 27`_. .. _issue 28: https://github.com/nedbat/django_coverage_plugin/issues/28 @@ -160,7 +160,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 From 41aec8ec4cb7b29b8b0601928660b04a37d41765 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sun, 15 Jan 2017 16:35:12 -0500 Subject: [PATCH 13/13] Readme layout stuff --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 705bc0b..89877f4 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,9 @@ A `coverage.py`_ plugin to measure the coverage of Django templates. | |kit| |downloads| 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. @@ -66,7 +68,7 @@ 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 +Only the ``django.template.backends.django.DjangoTemplates`` template engine is supported, and it must be configured with ``['OPTIONS']['debug'] = True``. Fixes `issue 27`_.