diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..ed14f2e --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +combine_as_imports=True +force_grid_wrap=0 +include_trailing_comma=True +line_length=79 +multi_line_output=3 +known_third_party = coverage,django,setuptools,six,unittest_mixins diff --git a/AUTHORS.txt b/AUTHORS.txt index c1bf993..d6d8b5c 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -1,7 +1,10 @@ The Django coverage plugin was written by Ned Batchelder, with other contributions by: +Andrew Pinkham +Aron Griffis +Emil Madsen +Federico Bond Jessamyn Smith -Simon Charette Pamela McA'Nulty -Emil Madsen +Simon Charette diff --git a/HISTORY.rst b/HISTORY.rst new file mode 100644 index 0000000..028b9d0 --- /dev/null +++ b/HISTORY.rst @@ -0,0 +1,124 @@ +======= +History +======= + + +v1.6.0 --- 2018-09-04 +--------------------- + +Add support for Django 2.1. + + +v1.5.2 --- 2017-10-18 +--------------------- + +Validates support for Django version 2.0b1. Improves discovery of +template files. + + +v1.5.1a --- 2017-04-05 +---------------------- + +Validates support for Django version 1.11. Testing for new package +maintainer Pamela McA'Nulty + + +v1.5.0 --- 2017-02-23 +--------------------- + +Removes support for Django versions below 1.8. Validates support for +Django version 1.11b1 + + +v1.4.2 --- 2017-02-06 +--------------------- + +Fixes another instance of `issue 32`_, which was the result of an +initialization order problem. + + + +v1.4.1 --- 2017-01-25 +--------------------- + +Fixes `issue 32`_, which was the result of an initialization order +problem. + +.. _issue 32: https://github.com/nedbat/django_coverage_plugin/issues/32 + + + +v1.4 --- 2017-01-16 +------------------- + +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 +--------------------- + +Settings are read slightly differently, so as to not interfere with +programs that don't need settings. Fixes `issue 18`_. + +.. _issue 18: https://github.com/nedbat/django_coverage_plugin/issues/18 + + + +v1.3 --- 2016-04-03 +------------------- + +Multiple template engines are allowed. Thanks, Simon Charette. + + + +v1.2.2 --- 2016-02-01 +--------------------- + +No change in code, but Django 1.9.2 is now supported. + + + +v1.2.1 --- 2016-01-28 +--------------------- + +The template debug settings are checked properly for people still using +``TEMPLATE_DEBUG`` in newer versions of Django. + + + +v1.2 --- 2016-01-16 +------------------- + +Check if template debugging is enabled in the settings, and raise a +visible warning if not. This prevents mysterious failures of the +plugin, and fixes `issue 17`_. + +Potential Django 1.9 support is included, but the patch to Django hasn't +been applied yet. + +.. _issue 17: https://github.com/nedbat/django_coverage_plugin/issues/17 + + + +v1.1 --- 2015-11-12 +------------------- + +Explicitly configure settings if need be to get things to work. + + + +v1.0 --- 2015-09-20 +------------------- + +First version :) diff --git a/MANIFEST.in b/MANIFEST.in index 2e9b830..200b65c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,15 @@ -# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt +# Licensed under the Apache 2.0 License +# - http://www.apache.org/licenses/LICENSE-2.0 +# - https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt -include requirements.txt +exclude .isort.cfg +exclude howto.txt +exclude Makefile +exclude requirements.txt +exclude tox.ini +include AUTHORS.txt +include HISTORY.rst +include LICENSE.txt +include NOTICE.txt +include README.rst +prune tests diff --git a/README.rst b/README.rst index 7660613..a4a0c94 100644 --- a/README.rst +++ b/README.rst @@ -1,24 +1,37 @@ -.. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -.. For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt +.. start-badges + +|status| |kit| |license| |versions| |djversions| + +.. |status| image:: https://img.shields.io/pypi/status/django_coverage_plugin.svg + :target: https://pypi.python.org/pypi/django_coverage_plugin + :alt: Package stability +.. |kit| image:: https://badge.fury.io/py/django_coverage_plugin.svg + :target: https://pypi.python.org/pypi/django_coverage_plugin + :alt: Latest PyPI Version +.. |license| image:: https://img.shields.io/pypi/l/django_coverage_plugin.svg + :target: https://pypi.python.org/pypi/django_coverage_plugin + :alt: Apache 2.0 License +.. |versions| image:: https://img.shields.io/pypi/pyversions/django_coverage_plugin.svg + :target: https://pypi.python.org/pypi/django_coverage_plugin + :alt: Supported Python Versions +.. |djversions| image:: https://img.shields.io/badge/Django-1.8%20%7C%201.11%20%7C%202.0%20%7C%202.1-44b78b.svg + :target: https://pypi.python.org/pypi/django_coverage_plugin + :alt: Supported Django Versions + +.. end-badges ================================== Django Template Coverage.py Plugin ================================== -A `coverage.py`_ plugin to measure the coverage of Django templates. - -| |license| |versions| |djversions| |status| -| |kit| - -.. downloads badge seems to be broken... |downloads| +A `coverage.py`_ plugin to measure test coverage of Django templates. -Supported Python versions are 2.7, 3.4, 3.5 and 3.6. +Supported Python versions: 2.7, 3.4, 3.5 and 3.6. -Supported Django versions are 1.8 through 2.0b1. +Supported Django versions: 1.8, 1.11, 2.0, and 2.1. Supported coverage.py versions are 4.0 and higher. - The plugin is pip installable:: $ pip install django_coverage_plugin @@ -29,143 +42,43 @@ To run it, add this setting to your .coveragerc file:: plugins = django_coverage_plugin -Then run your tests under coverage.py. +Then run your tests under `coverage.py`_. -You will see your templates listed in your coverage report along with your -Python modules. +You will see your templates listed in your coverage report along with +your Python modules. -If you get a django.core.exceptions.ImproperlyConfigured error, you need to set -the DJANGO_SETTINGS_MODULE environment variable. +If you get a :code:`django.core.exceptions.ImproperlyConfigured` error, +you need to set the :code:`DJANGO_SETTINGS_MODULE` environment variable. Configuration ~~~~~~~~~~~~~ -The Django template plugin uses some existing settings from your .coveragerc -file. The ``source=``, ``include=``, and ``omit=`` options control what -template files are included in the report. +The Django template plugin uses some existing settings from your +.coveragerc file. The ``source=``, ``include=``, and ``omit=`` options +control what template files are included in the report. Caveats ~~~~~~~ -Coverage.py can't tell whether a ``{% blocktrans %}`` tag used the singular or -plural text, so both are marked as used if the tag is used. - - -Changes -~~~~~~~ - -v1.5.2 --- 2017-10-18 ----------------------- - -Validates support for Django version 2.0b1. Improves discovery of template files. - -v1.5.1a --- 2017-04-05 ----------------------- - -Validates support for Django version 1.11. Testing for new package maintainer Pamela McA'Nulty - -v1.5.0 --- 2017-02-23 ---------------------- - -Removes support for Django versions below 1.8. Validates support for Django version 1.11b1 - -v1.4.2 --- 2017-02-06 ---------------------- - -Fixes another instance of `issue 32`_, which was the result of an initialization order problem. - - -v1.4.1 --- 2017-01-25 ---------------------- - -Fixes `issue 32`_, which was the result of an initialization order problem. - -.. _issue 32: https://github.com/nedbat/django_coverage_plugin/issues/32 - - -v1.4 --- 2017-01-16 -------------------- - -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 ---------------------- - -Settings are read slightly differently, so as to not interfere with programs -that don't need settings. Fixes `issue 18`_. - -.. _issue 18: https://github.com/nedbat/django_coverage_plugin/issues/18 - - -v1.3 --- 2016-04-03 -------------------- - -Multiple template engines are allowed. Thanks, Simon Charette. - - -v1.2.2 --- 2016-02-01 ---------------------- - -No change in code, but Django 1.9.2 is now supported. - - -v1.2.1 --- 2016-01-28 ---------------------- - -The template debug settings are checked properly for people still using -``TEMPLATE_DEBUG`` in newer versions of Django. - - -v1.2 --- 2016-01-16 -------------------- - -Check if template debugging is enabled in the settings, and raise a visible -warning if not. This prevents mysterious failures of the plugin, and fixes -`issue 17`_. - -Potential Django 1.9 support is included, but the patch to Django hasn't been -applied yet. - -.. _issue 17: https://github.com/nedbat/django_coverage_plugin/issues/17 - - -v1.1 --- 2015-11-12 -------------------- - -Explicitly configure settings if need be to get things to work. - - -v1.0 --- 2015-09-20 -------------------- - -First version :) +Coverage.py can't tell whether a ``{% blocktrans %}`` tag used the +singular or plural text, so both are marked as used if the tag is used. What the? How? ~~~~~~~~~~~~~~ -The technique used to measure the coverage is the same that Dmitry Trofimov -used in `dtcov`_, but integrated into coverage.py as a plugin, and made more -performant. I'd love to see how well it works in a real production project. If -you want to help me with it, feel free to drop me an email. +The technique used to measure the coverage is the same that Dmitry +Trofimov used in `dtcov`_, but integrated into coverage.py as a plugin, +and made more performant. I'd love to see how well it works in a real +production project. If you want to help me with it, feel free to drop me +an email. -The coverage.py plugin mechanism is designed to be generally useful for hooking -into the collection and reporting phases of coverage.py, specifically to -support non-Python files. If you have non-Python files you'd like to support -in coverage.py, let's talk. +The coverage.py plugin mechanism is designed to be generally useful for +hooking into the collection and reporting phases of coverage.py, +specifically to support non-Python files. If you have non-Python files +you'd like to support in coverage.py, let's talk. Tests @@ -176,26 +89,5 @@ To run the tests:: $ pip install -r requirements.txt $ tox - .. _coverage.py: http://nedbatchelder.com/code/coverage .. _dtcov: https://github.com/traff/dtcov - - -.. |license| image:: https://img.shields.io/pypi/l/django_coverage_plugin.svg - :target: https://pypi.python.org/pypi/django_coverage_plugin - :alt: License -.. |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.8%2C%201.9%2C%201.10%2C%201.11b1-44b78b.svg - :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 - :target: https://pypi.python.org/pypi/django_coverage_plugin - :alt: Package stability -.. |kit| image:: https://badge.fury.io/py/django_coverage_plugin.svg - :target: https://pypi.python.org/pypi/django_coverage_plugin - :alt: PyPI status -.. |downloads| image:: https://img.shields.io/pypi/dm/django_coverage_plugin.svg - :target: https://pypi.python.org/pypi/django_coverage_plugin - :alt: Monthly PyPI downloads diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index a8c6ed2..60c61df 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -8,20 +8,13 @@ import os.path import re -from six.moves import range - import coverage.plugin - import django import django.template -from django.template.base import Lexer, TextNode, NodeList, Template +from django.template.base import Lexer, NodeList, Template, TextNode +from django.template.defaulttags import VerbatimNode from django.templatetags.i18n import BlockTranslateNode - -try: - from django.template.defaulttags import VerbatimNode -except ImportError: - # Django 1.4 didn't have VerbatimNode - VerbatimNode = None +from six.moves import range try: from django.template.base import TokenType diff --git a/setup.py b/setup.py index 36446bf..d3822c1 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,32 @@ #!/usr/bin/env python -# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt +# -*- encoding: utf-8 -*- +"""Setup for Django Coverage Plugin + +Licensed under the Apache 2.0 License +- http://www.apache.org/licenses/LICENSE-2.0 +- https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt + +""" +from __future__ import absolute_import, print_function + +import io +import re +from os.path import dirname, join from setuptools import setup + +def read(*names, **kwargs): + """Read and return contents of file + + Parameter: encoding kwarg may be set + """ + return io.open( + join(dirname(__file__), *names), + encoding=kwargs.get('encoding', 'utf8') + ).read() + + classifiers = """\ Environment :: Console Intended Audience :: Developers @@ -17,13 +40,24 @@ Programming Language :: Python :: Implementation :: PyPy Topic :: Software Development :: Quality Assurance Topic :: Software Development :: Testing -Development Status :: 3 - Alpha +Development Status :: 5 - Production/Stable +Framework :: Django +Framework :: Django :: 1.8 +Framework :: Django :: 1.11 +Framework :: Django :: 2.0 +Framework :: Django :: 2.1 """ setup( name='django_coverage_plugin', - version='1.5.2', + version='1.6rc1', description='Django template coverage.py plugin', + long_description=( + re.compile( + '^.. start-badges.*^.. end-badges', + re.M | re.S, + ).sub('', read('README.rst')) + ), author='Ned Batchelder', author_email='ned@nedbatchelder.com', url='https://github.com/nedbat/django_coverage_plugin', diff --git a/tests/banner.py b/tests/banner.py index ad569a2..2febc6e 100644 --- a/tests/banner.py +++ b/tests/banner.py @@ -6,6 +6,7 @@ from __future__ import print_function import platform + import django print( diff --git a/tests/plugin_test.py b/tests/plugin_test.py index 8139ee7..ea35fd1 100644 --- a/tests/plugin_test.py +++ b/tests/plugin_test.py @@ -9,11 +9,14 @@ import re import unittest -from unittest_mixins import StdStreamCapturingMixin, TempDirMixin - import coverage import django from django.conf import settings +from django.template import Context, Template # noqa +from django.template.backends.django import DjangoTemplates # noqa +from django.template.loader import get_template # noqa +from django.test import TestCase # noqa +from unittest_mixins import StdStreamCapturingMixin, TempDirMixin from django_coverage_plugin.plugin import DjangoTemplatePlugin @@ -59,11 +62,6 @@ def test_settings(): if hasattr(django, "setup"): django.setup() -from django.template import Context, Template # noqa -from django.template.backends.django import DjangoTemplates # noqa -from django.template.loader import get_template # noqa -from django.test import TestCase # noqa - class DjangoPluginTestCase(StdStreamCapturingMixin, TempDirMixin, TestCase): """A base class for all our tests.""" diff --git a/tests/test_engines.py b/tests/test_engines.py index b5bb7ae..76c713f 100644 --- a/tests/test_engines.py +++ b/tests/test_engines.py @@ -3,9 +3,10 @@ """Tests of multiple engines for django_coverage_plugin.""" -from .plugin_test import DjangoPluginTestCase from django.test import modify_settings +from .plugin_test import DjangoPluginTestCase + class MultipleEngineTests(DjangoPluginTestCase): def setUp(self): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 2f41050..d0e919c 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -5,7 +5,7 @@ import unittest -from django_coverage_plugin.plugin import make_line_map, get_line_number +from django_coverage_plugin.plugin import get_line_number, make_line_map class HelperTest(unittest.TestCase): diff --git a/tests/test_settings.py b/tests/test_settings.py index 1d5f7b7..c3ef4d5 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -7,7 +7,6 @@ from .plugin_test import DjangoPluginTestCase, test_settings - # Make settings overrides for tests below. NON_DJANGO_BACKEND = 'django.template.backends.dummy.TemplateStrings' diff --git a/tests/test_simple.py b/tests/test_simple.py index a748f31..7ca9188 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -6,7 +6,6 @@ from .plugin_test import DjangoPluginTestCase - # 200 Unicode chars: snowman + poo. UNIUNI = u"\u26C4\U0001F4A9"*100 if isinstance(UNIUNI, str): diff --git a/tox.ini b/tox.ini index 91d4e40..58250ca 100644 --- a/tox.ini +++ b/tox.ini @@ -13,25 +13,24 @@ # [tox] -# Don't test 'tip' on python27! envlist = py27-django{18,19,110,111,111tip}, py34-django{18,19,110,111,111tip,20}, py35-django{18,19,110,111,111tip,20,21,tip}, py36-django{18,19,110,111,111tip,20,21,tip}, py37-django{20,21,tip}, - check,doc + check,pkgcheck,doc [testenv] deps = - unittest-mixins==1.1 - django18: Django >=1.8, <1.9 - django19: Django >=1.9, <1.10 - django110: Django >=1.10, <1.11 - django111: Django >=1.11, <2.0 + unittest-mixins==1.6 + django18: Django>=1.8,<1.9 + django19: Django>=1.9,<1.10 + django110: Django>=1.10,<1.11 + django111: Django>=1.11,<2.0 django111tip: https://github.com/django/django/archive/stable/1.11.x.tar.gz - django20: Django>=2.0b1,<2.1 - django21: Django>=2.1, <2.2 + django20: Django>=2.0,<2.1 + django21: Django>=2.1,<2.2 djangotip: https://github.com/django/django/archive/master.tar.gz commands = @@ -45,9 +44,22 @@ passenv = * [testenv:check] deps = flake8 + isort commands = - flake8 --max-line-length=100 setup.py django_coverage_plugin tests + flake8 --max-line-length=100 setup.py django_coverage_plugin tests setup.py + isort --verbose --check-only --diff --recursive django_coverage_plugin tests setup.py + +[testenv:pkgcheck] +skip_install = true +deps = + docutils + check-manifest + readme-renderer + +commands = + python setup.py check --strict --metadata --restructuredtext + check-manifest {toxinidir} [testenv:doc] deps =