Author: kkubasik
Date: 2009-06-09 06:21:57 -0500 (Tue, 09 Jun 2009)
New Revision: 10960
Modified:
django/branches/soc2009/test-improvements/django/test/test_coverage.py
Log:
Making new reports more accurate
Modified: django/branches/soc2009/test-improvements/django/test/test_coverage.py
===================================================================
--- django/branches/soc2009/test-improvements/django/test/test_coverage.py
2009-06-09 04:57:26 UTC (rev 10959)
+++ django/branches/soc2009/test-improvements/django/test/test_coverage.py
2009-06-09 11:21:57 UTC (rev 10960)
@@ -1,11 +1,11 @@
-import coverage
+import coverage, time
import os, sys
from django.conf import settings
from django.db.models import get_app, get_apps
from django.test.simple import DefaultTestRunner as base_run_tests
-from django.utils.module_tools import get_all_modules
+from django.utils.module_tools import get_all_modules, find_or_load_module
from django.utils.translation import ugettext as _
def _get_app_package(app_model_module):
@@ -30,6 +30,7 @@
Runs the specified tests while generating code coverage statistics.
Upon
the tests' completion, the results are printed to stdout.
"""
+ coverage.erase()
#Allow an on-disk cache of coverage stats.
#coverage.use_cache(0)
for e in getattr(settings, 'COVERAGE_CODE_EXCLUDES', []):
@@ -55,7 +56,8 @@
packages, self.modules, self.excludes, self.errors = get_all_modules(
coverage_modules, getattr(settings, 'COVERAGE_MODULE_EXCLUDES',
[]),
getattr(settings, 'COVERAGE_PATH_EXCLUDES', []))
-
+ for mods in self.modules.keys():
+ coverage.analysis2(ModuleVars(mods, self.modules[mods]))
coverage.report(self.modules.values(), show_missing=1)
if self.excludes:
print >> sys.stdout
@@ -69,6 +71,7 @@
for e in self.errors:
print >> sys.stderr, e,
print >> sys.stdout
+ coverage._the_coverage.save()
return results
@@ -98,8 +101,51 @@
with the results
"""
res = BaseCoverageRunner.run_tests(self, *args, **kwargs)
- coverage._the_coverage.html_report(self.modules.values(), self.outdir)
+ coverage._the_coverage.load()
+ cov = coverage.html.HtmlReporter(coverage._the_coverage)
+ cov.report(self.modules.values(), self.outdir)
+ #coverage._the_coverage.html_report(self.modules.values(), self.outdir)
print >>sys.stdout
print >>sys.stdout, _("HTML reports were output to '%s'") %self.outdir
return res
+
+
+try:
+ set
+except:
+ from sets import Set as set
+
+
+class ModuleVars(object):
+ modules = dict()
+ def __new__(cls, module_name, module=None):
+ if cls.modules.get(module_name, None):
+ return cls.modules.get(module_name)
+ else:
+ obj=super(ModuleVars, cls).__new__(cls)
+ obj._init(module_name, module)
+ cls.modules[module_name] = obj
+ return obj
+
+ def _init(self, module_name, module):
+ source_file, stmts, excluded, missed, missed_display =
coverage.analysis2(module)
+ executed = list(set(stmts).difference(missed))
+ total = list(set(stmts).union(excluded))
+ total.sort()
+ title = module.__name__
+ total_count = len(total)
+ executed_count = len(executed)
+ excluded_count = len(excluded)
+ missed_count = len(missed)
+ try:
+ percent_covered = float(len(executed))/len(stmts)*100
+ except ZeroDivisionError:
+ percent_covered = 100
+ test_timestamp = time.strftime('%a %Y-%m-%d %H:%M %Z')
+ severity = 'normal'
+ if percent_covered < 75: severity = 'warning'
+ if percent_covered < 50: severity = 'critical'
+
+ for k, v in locals().iteritems():
+ setattr(self, k, v)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---