]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fix doctests
authorMarkus Unterwaditzer <markus@unterwaditzer.net>
Sun, 22 Mar 2015 13:22:40 +0000 (14:22 +0100)
committerMarkus Unterwaditzer <markus@unterwaditzer.net>
Sun, 22 Mar 2015 13:22:52 +0000 (14:22 +0100)
Fix #427

jinja2/environment.py
jinja2/meta.py
jinja2/runtime.py
jinja2/sandbox.py
scripts/jinja2-debug.py [moved from jinja2-debug.py with 91% similarity]
setup.cfg

index b406b5ad9b445344b4c73c9379967468c7fd1af3..1f6496b786c421e5c2322c9d08ab7c2f39d9d849 100644 (file)
@@ -879,13 +879,12 @@ class Template(object):
     and compatible settings.
 
     >>> template = Template('Hello {{ name }}!')
-    >>> template.render(name='John Doe')
-    u'Hello John Doe!'
-
+    >>> template.render(name='John Doe') == u'Hello John Doe!'
+    True
     >>> stream = template.stream(name='John Doe')
-    >>> stream.next()
-    u'Hello John Doe!'
-    >>> stream.next()
+    >>> next(stream) == u'Hello John Doe!'
+    True
+    >>> next(stream)
     Traceback (most recent call last):
         ...
     StopIteration
@@ -1032,10 +1031,10 @@ class Template(object):
         exported template variables from the Python layer:
 
         >>> t = Template('{% macro foo() %}42{% endmacro %}23')
-        >>> unicode(t.module)
-        u'23'
-        >>> t.module.foo()
-        u'42'
+        >>> str(t.module)
+        '23'
+        >>> t.module.foo() == u'42'
+        True
         """
         if self._module is not None:
             return self._module
index 3110cff6066a0160df1b01c63b117afd60245288..3dbab7c22d5dbaa92a2daba71b4c1500c7c5880d 100644 (file)
@@ -39,8 +39,8 @@ def find_undeclared_variables(ast):
     >>> from jinja2 import Environment, meta
     >>> env = Environment()
     >>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
-    >>> meta.find_undeclared_variables(ast)
-    set(['bar'])
+    >>> meta.find_undeclared_variables(ast) == set(['bar'])
+    True
 
     .. admonition:: Implementation
 
index 792fb9a61d760ea6016c913addec015d2dc9b33a..9e818df10d3087d7333d01fc8a8e9a7bd84bb7d7 100644 (file)
@@ -444,7 +444,7 @@ class Macro(object):
 @implements_to_string
 class Undefined(object):
     """The default undefined type.  This undefined type can be printed and
-    iterated over, but every other access will raise an :exc:`UndefinedError`:
+    iterated over, but every other access will raise an :exc:`jinja2.exceptions.UndefinedError`:
 
     >>> foo = Undefined(name='foo')
     >>> str(foo)
@@ -454,7 +454,7 @@ class Undefined(object):
     >>> foo + 42
     Traceback (most recent call last):
       ...
-    UndefinedError: 'foo' is undefined
+    jinja2.exceptions.UndefinedError: 'foo' is undefined
     """
     __slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name',
                  '_undefined_exception')
@@ -468,7 +468,7 @@ class Undefined(object):
     @internalcode
     def _fail_with_undefined_error(self, *args, **kwargs):
         """Regular callback function for undefined objects that raises an
-        `UndefinedError` on call.
+        `jinja2.exceptions.UndefinedError` on call.
         """
         if self._undefined_hint is None:
             if self._undefined_obj is missing:
@@ -620,7 +620,7 @@ class DebugUndefined(Undefined):
     >>> foo + 42
     Traceback (most recent call last):
       ...
-    UndefinedError: 'foo' is undefined
+    jinja2.exceptions.UndefinedError: 'foo' is undefined
     """
     __slots__ = ()
 
@@ -645,15 +645,15 @@ class StrictUndefined(Undefined):
     >>> str(foo)
     Traceback (most recent call last):
       ...
-    UndefinedError: 'foo' is undefined
+    jinja2.exceptions.UndefinedError: 'foo' is undefined
     >>> not foo
     Traceback (most recent call last):
       ...
-    UndefinedError: 'foo' is undefined
+    jinja2.exceptions.UndefinedError: 'foo' is undefined
     >>> foo + 42
     Traceback (most recent call last):
       ...
-    UndefinedError: 'foo' is undefined
+    jinja2.exceptions.UndefinedError: 'foo' is undefined
     """
     __slots__ = ()
     __iter__ = __str__ = __len__ = __nonzero__ = __eq__ = \
index 0b6383a202585bc91010984215f86eba4065d158..7e40ab30850707104a139d1fa95c5c177a482aa5 100644 (file)
@@ -23,8 +23,14 @@ from jinja2._compat import string_types, PY2
 MAX_RANGE = 100000
 
 #: attributes of function objects that are considered unsafe.
-UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict',
-                                  'func_defaults', 'func_globals'])
+if PY2:
+    UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict',
+                                      'func_defaults', 'func_globals'])
+else:
+    # On versions > python 2 the special attributes on functions are gone,
+    # but they remain on methods and generators for whatever reason.
+    UNSAFE_FUNCTION_ATTRIBUTES = set()
+
 
 #: unsafe method attributes.  function attributes are unsafe for methods too
 UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self'])
@@ -32,11 +38,6 @@ UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self'])
 #: unsafe generator attirbutes.
 UNSAFE_GENERATOR_ATTRIBUTES = set(['gi_frame', 'gi_code'])
 
-# On versions > python 2 the special attributes on functions are gone,
-# but they remain on methods and generators for whatever reason.
-if not PY2:
-    UNSAFE_FUNCTION_ATTRIBUTES = set()
-
 import warnings
 
 # make sure we don't warn in python 2.6 about stuff we don't care about
@@ -124,9 +125,7 @@ def is_internal_attribute(obj, attr):
     :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
 
     >>> from jinja2.sandbox import is_internal_attribute
-    >>> is_internal_attribute(lambda: None, "func_code")
-    True
-    >>> is_internal_attribute((lambda x:x).func_code, 'co_code')
+    >>> is_internal_attribute(str, "mro")
     True
     >>> is_internal_attribute(str, "upper")
     False
similarity index 91%
rename from jinja2-debug.py
rename to scripts/jinja2-debug.py
index 80bbc628a050ee9f77cafa1fc4d140452c169d79..d052adc37e57535979ed48ec2a5f24ccca3b5c04 100755 (executable)
@@ -21,7 +21,7 @@ env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
 
 def shell_init_func():
     def _compile(x):
-        print env.compile(x, raw=True)
+        print(env.compile(x, raw=True))
     result = {
         'e':        env,
         'c':        _compile,
@@ -34,7 +34,7 @@ def shell_init_func():
 
 
 def action_compile():
-    print env.compile(sys.stdin.read(), raw=True)
+    print(env.compile(sys.stdin.read(), raw=True))
 
 action_shell = script.make_shell(shell_init_func)
 
index 058cdfc1c68e178a7eebd3f0286bdbc1ea7a903d..573a4ee0db6f0805a1aac4a774c6c2caafba71da 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,4 +5,5 @@ universal = 1
 release = egg_info -RDb ''
 
 [pytest]
-norecursedirs = .* *.egg *.egg-info env* artwork docs examples
+norecursedirs = .* *.egg *.egg-info env* artwork docs examples ext scripts
+addopts = --doctest-modules --ignore=setup.py