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
Provenance
- Commit
599c136- Tree
6b04568- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
1c5f1e8
7 files changed+72 added−73 removed
modified:jinja2/environment.py+9 added-10 removed
877 unmodified lines878 that is probably shared with other templates created with the constructor879 and compatible settings.880 881 >>> template = Template('Hello {{ name }}!')882- >>> template.render(name='John Doe')883- u'Hello John Doe!'884-882+ >>> 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 lines1030 template runtime but is also useful if one wants to access1031 exported template variables from the Python layer:1032 1033 >>> 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 linesmodified:jinja2/meta.py+2 added-2 removed
37 unmodified lines38 39 >>> 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+ True44 45 .. admonition:: Implementation46 47 Internally the code generator is used for finding undeclared variables.56 unmodified linesmodified:jinja2/runtime.py+7 added-7 removed
442 unmodified lines443 444 @implements_to_string445 class 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`:448 449 >>> foo = Undefined(name='foo')450 >>> str(foo)451 ''1 unmodified line453 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 lines467 468 @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_name143 unmodified lines619 True620 >>> foo + 42621 Traceback (most recent call last):622 ...623- UndefinedError: 'foo' is undefined623+ jinja2.exceptions.UndefinedError: 'foo' is undefined624 """625 __slots__ = ()626 627 def __str__(self):16 unmodified lines644 >>> 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 linesmodified:jinja2/sandbox.py+9 added-10 removed
21 unmodified lines22 #: maximum number of items a range may produce23 MAX_RANGE = 10000024 25 #: attributes of function objects that are considered unsafe.26+if PY2:26-UNSAFE_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'])29+else: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()33 34+35 #: unsafe method attributes. function attributes are unsafe for methods too36 UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self'])37 38 #: unsafe generator attirbutes.39 UNSAFE_GENERATOR_ATTRIBUTES = set(['gi_frame', 'gi_code'])40 35-# On versions > python 2 the special attributes on functions are gone,36-# but they remain on methods and generators for whatever reason.37-if not PY2:38- UNSAFE_FUNCTION_ATTRIBUTES = set()39-41 import warnings42 43 # make sure we don't warn in python 2.6 about stuff we don't care about44 warnings.filterwarnings('ignore', 'the sets module', DeprecationWarning,79 unmodified lines124 python objects. This is useful if the environment method125 :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.126 127 >>> 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 linesadded:scripts/jinja2-debug.py+43 added
1+#!/usr/bin/env python2+# -*- coding: utf-8 -*-3+"""4+ Jinja2 Debug Interface5+ ~~~~~~~~~~~~~~~~~~~~~~6+7+ Helper script for internal Jinja2 debugging. Requires Werkzeug.8+9+ :copyright: Copyright 2010 by Armin Ronacher.10+ :license: BSD.11+"""12+import sys13+import jinja214+from werkzeug import script15+16+env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',17+ 'jinja2.ext.loopcontrols',18+ 'jinja2.ext.with_',19+ 'jinja2.ext.autoescape'],20+ autoescape=True)21+22+def 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 result34+35+36+def action_compile():37+ print(env.compile(sys.stdin.read(), raw=True))38+39+action_shell = script.make_shell(shell_init_func)40+41+42+if __name__ == '__main__':43+ script.run()deleted:jinja2-debug.py-43 removed
1-#!/usr/bin/env python2-# -*- coding: utf-8 -*-3-"""4- Jinja2 Debug Interface5- ~~~~~~~~~~~~~~~~~~~~~~6-7- Helper script for internal Jinja2 debugging. Requires Werkzeug.8-9- :copyright: Copyright 2010 by Armin Ronacher.10- :license: BSD.11-"""12-import sys13-import jinja214-from werkzeug import script15-16-env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',17- 'jinja2.ext.loopcontrols',18- 'jinja2.ext.with_',19- 'jinja2.ext.autoescape'],20- autoescape=True)21-22-def 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 result34-35-36-def action_compile():37- print env.compile(sys.stdin.read(), raw=True)38-39-action_shell = script.make_shell(shell_init_func)40-41-42-if __name__ == '__main__':43- script.run()modified:setup.cfg+2 added-1 removed
3 unmodified lines4 [aliases]5 release = egg_info -RDb ''6 7 [pytest]8-norecursedirs = .* *.egg *.egg-info env* artwork docs examples8+norecursedirs = .* *.egg *.egg-info env* artwork docs examples ext scripts9+addopts = --doctest-modules --ignore=setup.py