Skip to content
Myr

Improved test invokation. Picks up doctests within Jinja now, changed

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 92622e9 · Browse files · 5 files+18 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+18 added−14 removed

  • tests:+5 added−4 removed
  • other:+13 added−10 removed

5 files+18 added−14 removed

modified:jinja2/loaders.py+9 added-9 removed
162 unmodified lines
163164class PackageLoader(BaseLoader):165 """Load templates from python eggs or packages. It is constructed with166 the name of the python package and the path to the templates in that167 package:167 package::168169 >>> loader = PackageLoader('mypackage', 'views')169 loader = PackageLoader('mypackage', 'views')170171 If the package path is not given, ``'templates'`` is assumed.172173 Per default the template encoding is ``'utf-8'`` which can be changed
58 unmodified lines
232 an unicode string with the template source, a tuple in the form ``(source,233 filename, uptodatefunc)`` or `None` if the template does not exist.234235 >>> def load_template(name):236 ... if name == 'index.html'236 ... if name == 'index.html':237 ... return '...'238 ...239 >>> loader = FunctionLoader(load_template)240
18 unmodified lines
259class PrefixLoader(BaseLoader):260 """A loader that is passed a dict of loaders where each loader is bound261 to a prefix. The prefix is delimited from the template by a slash per262 default, which can be changed by setting the `delimiter` argument to263 something else.263 something else::264265 >>> loader = PrefixLoader({266 ... 'app1': PackageLoader('mypackage.app1'),267 ... 'app2': PackageLoader('mypackage.app2')268 ... })265 loader = PrefixLoader({266 'app1': PackageLoader('mypackage.app1'),267 'app2': PackageLoader('mypackage.app2')268 })269270 By loading ``'app1/index.html'`` the file from the app1 package is loaded,271 by loading ``'app2/index.html'`` the file from the second.272 """
17 unmodified lines
290 is tried.291292 >>> loader = ChoiceLoader([293 ... FileSystemLoader('/path/to/user/templates'),294 ... PackageLoader('mypackage')294 ... FileSystemLoader('/path/to/system/templates')295 ... ])296297 This is useful if you want to allow users to override builtin templates298 from a different location.
12 unmodified lines
modified:jinja2/tests.py+3 added
9 unmodified lines
10"""11import re12from jinja2.runtime import Undefined1314# nose, nothing here to test15__test__ = False161718number_re = re.compile(r'^-?\d+(\.\d+)?$')19regex_type = type(number_re)2021
125 unmodified lines
modified:tests/test_debug.py+3 added-3 removed
30 unmodified lines
31 '''32>>> tmpl = env.get_template('syntaxerror.html')33Traceback (most recent call last):34 ...35TemplateSyntaxError: unknown tag 'endif'36 File "loaderres/templates\\syntaxerror.html", line 437 {% endif %}35 File "tests/loaderres/templates/syntaxerror.html", line 4, in template36 {% endif %}37TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.38'''394041def test_regular_syntax_error():
10 unmodified lines
modified:tests/test_loaders.py+2 added-1 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import os11import time12import tempfile13from jinja2 import Environment, loaders14from jinja2.loaders import split_template_path
5 unmodified lines
20dict_loader = loaders.DictLoader({21 'justdict.html': 'FOO'22})23package_loader = loaders.PackageLoader('loaderres', 'templates')23filesystem_loader = loaders.FileSystemLoader('loaderres/templates')24filesystem_loader = loaders.FileSystemLoader('tests/loaderres/templates')25function_loader = loaders.FunctionLoader({'justfunction.html': 'FOO'}.get)26choice_loader = loaders.ChoiceLoader([dict_loader, package_loader])27prefix_loader = loaders.PrefixLoader({28 'a': filesystem_loader,
84 unmodified lines
modified:Makefile+1 added-1 removed
1test:2 cd tests; nosetests -v2 nosetests --with-doctest jinja2 tests342to3:5 rm -rf py3k6 mkdir py3k
6 unmodified lines