From: Armin Ronacher Date: Sun, 7 Feb 2010 01:00:11 +0000 (+0100) Subject: Improved test invokation. Picks up doctests within Jinja now, changed X-Git-Tag: 2.3~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e64adfc0576341fa688489c23c0026a819d1703;p=thirdparty%2Fjinja.git Improved test invokation. Picks up doctests within Jinja now, changed doctests that just show usage that would not work on their own so that they are standard code blocks now and do not disturb testing. --HG-- branch : trunk --- diff --git a/Makefile b/Makefile index 85ed64de..124b253d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - cd tests; nosetests -v + nosetests --with-doctest jinja2 tests 2to3: rm -rf py3k diff --git a/jinja2/loaders.py b/jinja2/loaders.py index 5d5723d7..7dda2aec 100644 --- a/jinja2/loaders.py +++ b/jinja2/loaders.py @@ -164,9 +164,9 @@ class FileSystemLoader(BaseLoader): class PackageLoader(BaseLoader): """Load templates from python eggs or packages. It is constructed with the name of the python package and the path to the templates in that - package: + package:: - >>> loader = PackageLoader('mypackage', 'views') + loader = PackageLoader('mypackage', 'views') If the package path is not given, ``'templates'`` is assumed. @@ -233,7 +233,7 @@ class FunctionLoader(BaseLoader): filename, uptodatefunc)`` or `None` if the template does not exist. >>> def load_template(name): - ... if name == 'index.html' + ... if name == 'index.html': ... return '...' ... >>> loader = FunctionLoader(load_template) @@ -260,12 +260,12 @@ class PrefixLoader(BaseLoader): """A loader that is passed a dict of loaders where each loader is bound to a prefix. The prefix is delimited from the template by a slash per default, which can be changed by setting the `delimiter` argument to - something else. + something else:: - >>> loader = PrefixLoader({ - ... 'app1': PackageLoader('mypackage.app1'), - ... 'app2': PackageLoader('mypackage.app2') - ... }) + loader = PrefixLoader({ + 'app1': PackageLoader('mypackage.app1'), + 'app2': PackageLoader('mypackage.app2') + }) By loading ``'app1/index.html'`` the file from the app1 package is loaded, by loading ``'app2/index.html'`` the file from the second. @@ -291,7 +291,7 @@ class ChoiceLoader(BaseLoader): >>> loader = ChoiceLoader([ ... FileSystemLoader('/path/to/user/templates'), - ... PackageLoader('mypackage') + ... FileSystemLoader('/path/to/system/templates') ... ]) This is useful if you want to allow users to override builtin templates diff --git a/jinja2/tests.py b/jinja2/tests.py index 2d72dcbe..d257eca0 100644 --- a/jinja2/tests.py +++ b/jinja2/tests.py @@ -11,6 +11,9 @@ import re from jinja2.runtime import Undefined +# nose, nothing here to test +__test__ = False + number_re = re.compile(r'^-?\d+(\.\d+)?$') regex_type = type(number_re) diff --git a/tests/test_debug.py b/tests/test_debug.py index d8e8a440..921b3350 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -32,9 +32,9 @@ def test_syntax_error(): >>> tmpl = env.get_template('syntaxerror.html') Traceback (most recent call last): ... -TemplateSyntaxError: unknown tag 'endif' - File "loaderres/templates\\syntaxerror.html", line 4 - {% endif %} + File "tests/loaderres/templates/syntaxerror.html", line 4, in template + {% endif %} +TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'. ''' diff --git a/tests/test_loaders.py b/tests/test_loaders.py index 17e6bf1d..64193f33 100644 --- a/tests/test_loaders.py +++ b/tests/test_loaders.py @@ -7,6 +7,7 @@ :license: BSD, see LICENSE for more details. """ +import os import time import tempfile from jinja2 import Environment, loaders @@ -20,7 +21,7 @@ dict_loader = loaders.DictLoader({ 'justdict.html': 'FOO' }) package_loader = loaders.PackageLoader('loaderres', 'templates') -filesystem_loader = loaders.FileSystemLoader('loaderres/templates') +filesystem_loader = loaders.FileSystemLoader('tests/loaderres/templates') function_loader = loaders.FunctionLoader({'justfunction.html': 'FOO'}.get) choice_loader = loaders.ChoiceLoader([dict_loader, package_loader]) prefix_loader = loaders.PrefixLoader({