Skip to content
Myr

Fix doctests

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

Fix #427

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 1c5f1e8 · Browse files · 7 files+72 added−73 removed
This commit

State

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

Diff stats

7 files+72 added−73 removed

  • other:+72 added−73 removed

7 files+72 added−73 removed

modified:jinja2/environment.py+9 added-10 removed
877 unmodified lines
878 that is probably shared with other templates created with the constructor879 and compatible settings.880881 >>> template = Template('Hello {{ name }}!')882 >>> template.render(name='John Doe')883 u'Hello John Doe!'884882 >>> template.render(name='John Doe') == u'Hello John Doe!'883 True884 >>> stream = template.stream(name='John Doe')886 >>> stream.next()887 u'Hello John Doe!'888 >>> stream.next()885 >>> next(stream) == u'Hello John Doe!'886 True887 >>> next(stream)888 Traceback (most recent call last):889 ...890 StopIteration891 """
138 unmodified lines
1030 template runtime but is also useful if one wants to access1031 exported template variables from the Python layer:10321033 >>> t = Template('{% macro foo() %}42{% endmacro %}23')1035 >>> unicode(t.module)1036 u'23'1037 >>> t.module.foo()1038 u'42'1034 >>> str(t.module)1035 '23'1036 >>> t.module.foo() == u'42'1037 True1038 """1039 if self._module is not None:1040 return self._module1041 self._module = rv = self.make_module()
164 unmodified lines
modified:jinja2/meta.py+2 added-2 removed
37 unmodified lines
3839 >>> from jinja2 import Environment, meta40 >>> env = Environment()41 >>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')42 >>> meta.find_undeclared_variables(ast)43 set(['bar'])42 >>> meta.find_undeclared_variables(ast) == set(['bar'])43 True4445 .. admonition:: Implementation4647 Internally the code generator is used for finding undeclared variables.
56 unmodified lines
modified:jinja2/runtime.py+7 added-7 removed
442 unmodified lines
443444@implements_to_string445class Undefined(object):446 """The default undefined type. This undefined type can be printed and447 iterated over, but every other access will raise an :exc:`UndefinedError`:447 iterated over, but every other access will raise an :exc:`jinja2.exceptions.UndefinedError`:448449 >>> foo = Undefined(name='foo')450 >>> str(foo)451 ''
1 unmodified line
453 True454 >>> foo + 42455 Traceback (most recent call last):456 ...457 UndefinedError: 'foo' is undefined457 jinja2.exceptions.UndefinedError: 'foo' is undefined458 """459 __slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name',460 '_undefined_exception')461
5 unmodified lines
467468 @internalcode469 def _fail_with_undefined_error(self, *args, **kwargs):470 """Regular callback function for undefined objects that raises an471 `UndefinedError` on call.471 `jinja2.exceptions.UndefinedError` on call.472 """473 if self._undefined_hint is None:474 if self._undefined_obj is missing:475 hint = '%r is undefined' % self._undefined_name
143 unmodified lines
619 True620 >>> foo + 42621 Traceback (most recent call last):622 ...623 UndefinedError: 'foo' is undefined623 jinja2.exceptions.UndefinedError: 'foo' is undefined624 """625 __slots__ = ()626627 def __str__(self):
16 unmodified lines
644 >>> foo = StrictUndefined(name='foo')645 >>> str(foo)646 Traceback (most recent call last):647 ...648 UndefinedError: 'foo' is undefined648 jinja2.exceptions.UndefinedError: 'foo' is undefined649 >>> not foo650 Traceback (most recent call last):651 ...652 UndefinedError: 'foo' is undefined652 jinja2.exceptions.UndefinedError: 'foo' is undefined653 >>> foo + 42654 Traceback (most recent call last):655 ...656 UndefinedError: 'foo' is undefined656 jinja2.exceptions.UndefinedError: 'foo' is undefined657 """658 __slots__ = ()659 __iter__ = __str__ = __len__ = __nonzero__ = __eq__ = \660 __ne__ = __bool__ = __hash__ = \
6 unmodified lines
modified:jinja2/sandbox.py+9 added-10 removed
21 unmodified lines
22#: maximum number of items a range may produce23MAX_RANGE = 1000002425#: attributes of function objects that are considered unsafe.26if PY2:26UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict',27 'func_defaults', 'func_globals'])27 UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict',28 'func_defaults', 'func_globals'])29else:30 # On versions > python 2 the special attributes on functions are gone,31 # but they remain on methods and generators for whatever reason.32 UNSAFE_FUNCTION_ATTRIBUTES = set()333435#: unsafe method attributes. function attributes are unsafe for methods too36UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self'])3738#: unsafe generator attirbutes.39UNSAFE_GENERATOR_ATTRIBUTES = set(['gi_frame', 'gi_code'])4035# On versions > python 2 the special attributes on functions are gone,36# but they remain on methods and generators for whatever reason.37if not PY2:38 UNSAFE_FUNCTION_ATTRIBUTES = set()3941import warnings4243# make sure we don't warn in python 2.6 about stuff we don't care about44warnings.filterwarnings('ignore', 'the sets module', DeprecationWarning,
79 unmodified lines
124 python objects. This is useful if the environment method125 :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.126127 >>> from jinja2.sandbox import is_internal_attribute127 >>> is_internal_attribute(lambda: None, "func_code")128 >>> is_internal_attribute(str, "mro")129 True129 >>> is_internal_attribute((lambda x:x).func_code, 'co_code')130 True130 >>> is_internal_attribute(str, "upper")131 False132 """133 if isinstance(obj, types.FunctionType):
234 unmodified lines
added:scripts/jinja2-debug.py+43 added
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4 Jinja2 Debug Interface5 ~~~~~~~~~~~~~~~~~~~~~~67 Helper script for internal Jinja2 debugging. Requires Werkzeug.89 :copyright: Copyright 2010 by Armin Ronacher.10 :license: BSD.11"""12import sys13import jinja214from werkzeug import script1516env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',17 'jinja2.ext.loopcontrols',18 'jinja2.ext.with_',19 'jinja2.ext.autoescape'],20 autoescape=True)2122def shell_init_func():23 def _compile(x):24 print(env.compile(x, raw=True))25 result = {26 'e': env,27 'c': _compile,28 't': env.from_string,29 'p': env.parse30 }31 for key in jinja2.__all__:32 result[key] = getattr(jinja2, key)33 return result343536def action_compile():37 print(env.compile(sys.stdin.read(), raw=True))3839action_shell = script.make_shell(shell_init_func)404142if __name__ == '__main__':43 script.run()
deleted:jinja2-debug.py-43 removed
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4 Jinja2 Debug Interface5 ~~~~~~~~~~~~~~~~~~~~~~67 Helper script for internal Jinja2 debugging. Requires Werkzeug.89 :copyright: Copyright 2010 by Armin Ronacher.10 :license: BSD.11"""12import sys13import jinja214from werkzeug import script1516env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',17 'jinja2.ext.loopcontrols',18 'jinja2.ext.with_',19 'jinja2.ext.autoescape'],20 autoescape=True)2122def shell_init_func():23 def _compile(x):24 print env.compile(x, raw=True)25 result = {26 'e': env,27 'c': _compile,28 't': env.from_string,29 'p': env.parse30 }31 for key in jinja2.__all__:32 result[key] = getattr(jinja2, key)33 return result343536def action_compile():37 print env.compile(sys.stdin.read(), raw=True)3839action_shell = script.make_shell(shell_init_func)404142if __name__ == '__main__':43 script.run()
modified:setup.cfg+2 added-1 removed
3 unmodified lines
4[aliases]5release = egg_info -RDb ''67[pytest]8norecursedirs = .* *.egg *.egg-info env* artwork docs examples8norecursedirs = .* *.egg *.egg-info env* artwork docs examples ext scripts9addopts = --doctest-modules --ignore=setup.py