Permalink
Browse files

much improved test coverage

  • Loading branch information...
Peter Bengtsson
Peter Bengtsson committed May 31, 2010
1 parent 2fb3fad commit cab493b30eded0f00cce95eb26446f3278c3b2c1
Showing with 494 additions and 7 deletions.
  1. +2 −1 .gitignore
  2. +7 −0 coverage_settings.py
  3. +45 −0 coverage_test_runner.py
  4. +1 −1 django_static/__init__.py
  5. +9 −4 django_static/templatetags/django_static.py
  6. +429 −0 django_static/tests.py
  7. +1 −1 setup.py
View
@@ -15,4 +15,5 @@ media/images/icon1_icon2.*.png
media/images/icon3.*.png
media/javascript/shit_code.*.js
media/css/reset_styles.*.css
-media/css/reset.*.css
+media/css/reset.*.css
+coverage_report/
View
@@ -0,0 +1,7 @@
+from settings import *
+
+TEST_RUNNER='coverage_test_runner.test_runner_with_coverage'
+
+COVERAGE_MODULES = [
+ 'django_static.templatetags.django_static',
+]
View
@@ -0,0 +1,45 @@
+from time import time
+import os
+import shutil
+from django.test.simple import DjangoTestSuiteRunner
+
+from django.conf import settings
+
+
+import coverage
+def test_runner_with_coverage(test_labels, verbosity=1, interactive=True,
+ failfast=None, extra_tests=[]):
+ """
+ Custom test runner. Follows the django.test.simple.run_tests() interface.
+ """
+ # Start code coverage before anything else if necessary
+ if hasattr(settings, 'COVERAGE_MODULES'):
+ cov = coverage.coverage()
+ #coverage.use_cache(0) # Do not cache any of the coverage.py stuff
+ cov.use_cache(0) # Do not cache any of the coverage.py stuff
+ cov.start()
+
+ test_runner = DjangoTestSuiteRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
+ test_results = test_runner.run_tests(test_labels, extra_tests=extra_tests)
+
+ # Stop code coverage after tests have completed
+ if hasattr(settings, 'COVERAGE_MODULES'):
+ cov.stop()
+
+ # Print code metrics header
+ print ''
+ print '----------------------------------------------------------------------'
+ print ' Unit Test Code Coverage Results'
+ print '----------------------------------------------------------------------'
+
+ # Report code coverage metrics
+ if hasattr(settings, 'COVERAGE_MODULES'):
+ coverage_modules = []
+ for module in settings.COVERAGE_MODULES:
+ coverage_modules.append(__import__(module, globals(), locals(), ['']))
+ cov.report(coverage_modules, show_missing=1)
+ cov.html_report(coverage_modules, directory='coverage_report')
+ # Print code metrics footer
+ print '----------------------------------------------------------------------'
+
+ return test_results
@@ -1 +1 @@
-__version__ = '1.3.5' # remember to match with setup.py
+__version__ = '1.3.6' # remember to match with setup.py
@@ -8,13 +8,13 @@
from collections import defaultdict
from cStringIO import StringIO
from subprocess import Popen, PIPE
+import warnings
try:
from slimmer import css_slimmer, guessSyntax, html_slimmer, js_slimmer, xhtml_slimmer
slimmer = 'installed'
except ImportError:
slimmer = None
- import warnings
warnings.warn("slimmer is not installed. (easy_install slimmer)")
if sys.platform == "win32":
@@ -25,6 +25,7 @@
# django
from django import template
from django.conf import settings
+from django.template import TemplateSyntaxError
register = template.Library()
@@ -67,7 +68,9 @@ def render(self, context):
return xhtml_slimmer(code)
elif self.format == 'html':
return html_slimmer(code)
-
+ else:
+ raise TemplateSyntaxError("Unrecognized format for slimming content")
+
return code
@@ -127,7 +130,8 @@ def staticfile_node(parser, token, optimize_if_possible=False):
return StaticFileNode(filename,
symlink_if_possible=_CAN_SYMLINK,
- optimize_if_possible=optimize_if_possible)
+ optimize_if_possible=optimize_if_possible,
+ context_name=context_name)
class StaticFileNode(template.Node):
@@ -240,6 +244,7 @@ def image_replacer(match):
if new_filename != filename:
tag = tag.replace(filename, new_filename)
return tag
+
code = img_regex.sub(image_replacer, code)
new_css_filenames = defaultdict(list)
@@ -388,7 +393,7 @@ def wrap_up(filename):
filepath = _filename2filepath(filename, settings.MEDIA_ROOT)
if not os.path.isfile(filepath):
if warn_no_file:
- import warnings; warnings.warn("Can't find file %s" % filepath)
+ warnings.warn("Can't find file %s" % filepath)
return wrap_up(filename)
new_m_time = os.stat(filepath)[stat.ST_MTIME]
Oops, something went wrong.

0 comments on commit cab493b

Please sign in to comment.