Author: batiste.bieler
Date: Wed Jul 1 06:11:51 2009
New Revision: 591
Added:
trunk/example/test_runner.py
Modified:
trunk/example/settings.py
trunk/pages/admin/__init__.py
trunk/pages/templates/pages/menu.html
trunk/pages/templatetags/pages_tags.py
Log:
Add test coverage test runner
Modified: trunk/example/settings.py
==============================================================================
--- trunk/example/settings.py (original)
+++ trunk/example/settings.py Wed Jul 1 06:11:51 2009
@@ -139,6 +139,9 @@
('pages/editor.html', 'raw editor'),
)
+# A test runner that use the coverage module
+TEST_RUNNER = "test_runner.run_tests"
+
try:
from local_settings import *
except ImportError:
Added: trunk/example/test_runner.py
==============================================================================
--- (empty file)
+++ trunk/example/test_runner.py Wed Jul 1 06:11:51 2009
@@ -0,0 +1,51 @@
+from coverage import coverage
+import os
+from inspect import getmembers, ismodule
+
+from django.conf import settings
+from django.test.simple import run_tests as django_test_runner
+from django.db.models import get_app, get_apps
+
+def get_all_coverage_modules(app_module, exclude_files=[]):
+ """Returns all possible modules to report coverage on, even if they
+ aren't loaded.
+ """
+ # We start off with the imported models.py, so we need to import
+ # the parent app package to find the path.
+ app_path = app_module.__name__.split('.')[:-1]
+ app_package = __import__('.'.join(app_path), {}, {}, app_path[-1])
+ app_dirpath = app_package.__path__[-1]
+
+ mod_list = []
+ for root, dirs, files in os.walk(app_dirpath):
+ root_path = app_path +
root[len(app_dirpath):].split(os.path.sep)[1:]
+ for file in files:
+ if file not in exclude_files:
+ if file.lower().endswith('.py'):
+ mod_name = file[:-3].lower()
+ try:
+ mod = __import__('.'.join(root_path + [mod_name]),
+ {}, {}, mod_name)
+ except ImportError:
+ pass
+ else:
+ mod_list.append(mod)
+
+ return mod_list
+
+
+def run_tests(test_labels, verbosity=1, interactive=True,
+ extra_tests=[]):
+ cov = coverage()
+ cov.erase()
+ cov.use_cache(0)
+ cov.start()
+
+ app = get_app('pages')
+ modules = get_all_coverage_modules(app, exclude_files=['tests.py'])
+ results = django_test_runner(test_labels, verbosity, interactive,
+ extra_tests)
+ cov.stop()
+ cov.html_report(modules, directory='coverage')
+
+ return results
Modified: trunk/pages/admin/__init__.py
==============================================================================
--- trunk/pages/admin/__init__.py (original)
+++ trunk/pages/admin/__init__.py Wed Jul 1 06:11:51 2009
@@ -11,6 +11,7 @@
from django.db import models
from django.http import HttpResponseRedirect
from django.contrib.admin.util import unquote
+from django.contrib.admin.sites import AlreadyRegistered
from pages import settings
from pages.models import Page, Content
@@ -383,7 +384,10 @@
template_name='admin/pages/page/change_list_table.html')
return HttpResponseRedirect('../../')
-admin.site.register(Page, PageAdmin)
+try:
+ admin.site.register(Page, PageAdmin)
+except AlreadyRegistered:
+ pass
class ContentAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'type', 'language', 'page')
@@ -394,4 +398,8 @@
if settings.PAGE_PERMISSION:
from pages.models import PagePermission
- admin.site.register(PagePermission)
+ try:
+ admin.site.register(PagePermission)
+ except AlreadyRegistered:
+ pass
+
Modified: trunk/pages/templates/pages/menu.html
==============================================================================
--- trunk/pages/templates/pages/menu.html (original)
+++ trunk/pages/templates/pages/menu.html Wed Jul 1 06:11:51 2009
@@ -5,7 +5,7 @@
{% if children %}
<ul>
{% for child in children %}
- {% pages_menu child url %}
+ {% pages_menu child %}
{% endfor %}
</ul>
{% endif %}
Modified: trunk/pages/templatetags/pages_tags.py
==============================================================================
--- trunk/pages/templatetags/pages_tags.py (original)
+++ trunk/pages/templatetags/pages_tags.py Wed Jul 1 06:11:51 2009
@@ -43,7 +43,7 @@
c = Content.objects.get_content(page, absolute_lang, content_type,
fallback)
return c
-"""Fitlers"""
+"""Filters"""
def has_content_in(page, language):
"""Tell if the page has any content in a particular language"""
@@ -59,7 +59,8 @@
"""Inclusion tags"""
def pages_menu(context, page, url='/'):
- """render a nested list of all children of the pages"""
+ """Render a nested list of all children of the given page, including
+ this page"""
request = context['request']
site_id = None
children = page.get_children_for_frontend()
@@ -70,7 +71,7 @@
takes_context=True)(pages_menu)
def pages_sub_menu(context, page, url='/'):
- """Get the root page of the current page and
+ """Get the root page of the given page and
render a nested list of all root's children pages"""
request = context['request']
root = page.get_root()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-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/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---