Mercurial > hg > ltpdarepo
changeset 96:e7e0258660aa
Test to check that all templates have a title block.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Sun, 21 Aug 2011 18:17:27 +0200 |
parents | 601d49a7c353 |
children | cd4a15072c97 |
files | src/ltpdarepo/tests/test_templates.py |
diffstat | 1 files changed, 50 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/test_templates.py Sun Aug 21 18:17:27 2011 +0200 @@ -0,0 +1,50 @@ +import os +import re +import unittest2 as unittest + + +def templates(): + path = os.path.join(os.path.dirname(__file__), '..', 'templates') + path = os.path.normpath(path) + plen = len(path) + 1 + for root, dirs, files in os.walk(path): + for f in files: + if f.endswith('.html'): + path = os.path.join(root, f) + name = path[plen:] + yield name, path + + +class TestCase(unittest.TestCase): + + def test_templates_have_title_block(self): + # templates to skip in this test + blacklist = frozenset(( + 'forms.html', # forms rendering macros + 'form.html', # generic form rendering + 'pagination.html', # pagination rendering macros + 'browse.html', # extends template with title + 'query.html', # ditto + 'timerange.html', # ditto + )) + + # regular expression to obtain the title block + title = re.compile(r'{% block title %}\s*(.*)\s*{% endblock %}', re.MULTILINE) + + # list of templates that miss a title block + missing = [] + + for name, path in templates(): + if name in blacklist: + continue + with open(path) as fd: + template = fd.read() + match = title.search(template) + if not match: + missing.append(name) + continue + # print '%-30s %s' % (name, match.group(1)) + + if missing: + self.fail('%d templates do not define a title block: %s' + % (len(missing), ', '.join(missing)))