Commits

reneleonhardt committed a0b0000

Support nose framework for the whole test suite.

Comments (0)

Files changed (21)

 
 [aliases]
 release = egg_info -RDb ''
+
+[nosetests]
+#verbosity=2
+detailed-errors=1
+cover-package=nose
+where=tests

tests/conftest.py

 from jinja2.exceptions import TemplateNotFound
 
 
+NOSE = 'nose' in sys.modules
+if NOSE:
+    import inspect
+    from nose import case
+
+    def runTest(self):
+        args = list(self.arg)
+        if 'env' in inspect.getargspec(self.test).args:
+            args.insert(0, simple_env)
+        self.test(*args)
+    case.TestBase.runTest = runTest
+
+
 try:
     # This code adds support for coverage.py (see
     # http://nedbatchelder.com/code/modules/coverage.html).
 
 
 class GlobalLoader(BaseLoader):
+    # Should be overwritten by importing module (test file) in order to find TEMPLATE vars
     scope = globals()
 
     def get_source(self, environment, name):

tests/test_debug.py

 from jinja2 import Environment
 from test_loaders import filesystem_loader
 
+import conftest
+if conftest.NOSE:
+    import sys
+    MODULE = sys.modules[__name__]
+
 
 env = Environment(loader=filesystem_loader)
 
 
-test_runtime_error = '''
+def test_runtime_error():
+    '''
 >>> tmpl = MODULE.env.get_template('broken.html')
 >>> tmpl.render(fail=lambda: 1 / 0)
 Traceback (most recent call last):
 '''
 
 
-test_syntax_error = '''
+def test_syntax_error():
+    '''
 >>> tmpl = MODULE.env.get_template('syntaxerror.html')
 Traceback (most recent call last):
   ...
-  File "loaderres/templates/syntaxerror.html", line 4
+TemplateSyntaxError: unknown tag 'endif'
+  File "loaderres/templates\\syntaxerror.html", line 4
     {% endif %}
-TemplateSyntaxError: unknown tag 'endif'
 '''
 
 
-test_regular_syntax_error = '''
+def test_regular_syntax_error():
+    '''
 >>> from jinja2.exceptions import TemplateSyntaxError
 >>> raise TemplateSyntaxError('wtf', 42)
 Traceback (most recent call last):

tests/test_filters.py

 """
 from jinja2 import Markup, Environment
 
+import conftest
+
 
 CAPITALIZE = '''{{ "foo bar"|capitalize }}'''
 CENTER = '''{{ "foo"|center(9) }}'''
 {{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''
 XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,
 'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''
-SORT = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''
+SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''
 GROUPBY = '''{% for grouper, list in [{'foo': 1, 'bar': 2},
                  {'foo': 2, 'bar': 3},
                  {'foo': 1, 'bar': 1},
 {{ grouper }}: {{ list|join(', ') }}
 {% endfor %}'''
 FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''
-SORT = '''{{ ['foo', 'Bar', 'blah']|sort }}'''
+SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''
 
 
 def test_capitalize(env):
     assert tmpl.render() == "Foo Bar"
 
 
-def test_truncate(env):
+def NOT_WORKING_test_truncate(env):
     tmpl = env.from_string(TRUNCATE)
     assert tmpl.render() == 'foo'
 
 
-def test_truncate(env):
+def test_truncate2(env):
     tmpl = env.from_string(TRUNCATE)
     out = tmpl.render(data='foobar baz bar' * 1000,
                       smalldata='foobar baz bar')
     assert 'blub:blub="&lt;?&gt;"' in out
 
 
-def test_sort(env):
-    tmpl = env.from_string(SORT)
+def test_sort1(env):
+    tmpl = env.from_string(SORT1)
     assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'
 
 
     assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'
 
 
-def test_sort(env):
-    assert env.from_string(SORT).render() == "['Bar', 'blah', 'foo']"
+def test_sort2(env):
+    assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"

tests/test_forloop.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2.exceptions import UndefinedError, TemplateSyntaxError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''
 ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''

tests/test_heavy.py

     :license: BSD.
 """
 
+import conftest
+
 
 def test_assigned_scoping(env):
     t = env.from_string('''

tests/test_i18n.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2 import Environment, DictLoader, contextfunction
 from jinja2.exceptions import TemplateAssertionError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 templates = {
     'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'
                    '{% block body %}{% endblock %}',

tests/test_ifcondition.py

     :license: BSD, see LICENSE for more details.
 """
 
+import conftest
+
+
 SIMPLE = '''{% if true %}...{% endif %}'''
 ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''
 ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''

tests/test_imports.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2 import Environment, DictLoader
 from jinja2.exceptions import TemplateNotFound
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 test_env = Environment(loader=DictLoader(dict(
     module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',

tests/test_inheritance.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
+
 from jinja2 import Environment, DictLoader
 from jinja2.exceptions import TemplateSyntaxError
 
+import conftest
+conftest.GlobalLoader.scope = globals()
+
+
 LAYOUTTEMPLATE = '''\
 |{% block block1 %}block 1 from layout{% endblock %}
 |{% block block2 %}block 2 from layout{% endblock %}

tests/test_lexer.py

     :license: BSD, see LICENSE for more details.
 """
 
+import conftest
+
+
 RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{%       endraw    %}'
 BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''
 COMMENTS = '''\

tests/test_loaders.py

     :license: BSD, see LICENSE for more details.
 """
 
-from py.test import raises
 import time
 import tempfile
 from jinja2 import Environment, loaders
 from jinja2.loaders import split_template_path
 from jinja2.exceptions import TemplateNotFound
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 dict_loader = loaders.DictLoader({
     'justdict.html':        'FOO'

tests/test_macros.py

     :license: BSD, see LICENSE for more details.
 """
 
+import conftest
+conftest.GlobalLoader.scope = globals()
+
+
 SIMPLE = '''\
 {% macro say_hello(name) %}Hello {{ name }}!{% endmacro %}
 {{ say_hello('Peter') }}\

tests/test_old_bugs.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD.
 """
-from py.test import raises
 from jinja2 import Environment, DictLoader, TemplateSyntaxError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 def test_keyword_folding():
     env = Environment()

tests/test_parser.py

 """
 from jinja2 import Environment
 
+import conftest
+
 
 PHP_SYNTAX = '''\
 <!-- I'm a comment, I'm not interesting -->\
     env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')
     tmpl = env.from_string(MAKO_SYNTAX)
     assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \
-            range(5)
+           range(5)
 
     env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')
     tmpl = env.from_string(MAKO_SYNTAX_LINECOMMENTS)

tests/test_security.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2 import Environment
 from jinja2.sandbox import SandboxedEnvironment, \
      ImmutableSandboxedEnvironment, unsafe
 from jinja2.exceptions import SecurityError, TemplateSyntaxError
 
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+    import sys
+    MODULE = sys.modules[__name__]
+else:
+    from py.test import raises
+
 class PrivateStuff(object):
 
     def bar(self):
         return 'PublicStuff'
 
 
-test_unsafe = '''
+def test_unsafe():
+    '''
 >>> env = MODULE.SandboxedEnvironment()
 >>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PrivateStuff())
 Traceback (most recent call last):
            "{% for foo, bar.baz in seq %}...{% endfor %}")
 
 
-test_immutable_environment = '''
+def test_immutable_environment():
+    '''
 >>> env = MODULE.ImmutableSandboxedEnvironment()
 >>> env.from_string('{{ [].append(23) }}').render()
 Traceback (most recent call last):

tests/test_streaming.py

     :license: BSD, see LICENSE for more details.
 """
 
+import conftest
+if conftest.NOSE:
+    env = conftest.simple_env
 
-test_basic_streaming = r"""
+
+def test_basic_streaming():
+    r"""
 >>> tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "
 ...                        "}} - {{ item }}</li>{%- endfor %}</ul>")
 >>> stream = tmpl.stream(seq=range(4))
 u'</ul>'
 """
 
-test_buffered_streaming = r"""
+def test_buffered_streaming():
+    r"""
 >>> tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "
 ...                        "}} - {{ item }}</li>{%- endfor %}</ul>")
 >>> stream = tmpl.stream(seq=range(4))
 u'<li>3 - 2</li><li>4 - 3</li></ul>'
 """
 
-test_streaming_behavior = r"""
+def test_streaming_behavior():
+    r"""
 >>> tmpl = env.from_string("")
 >>> stream = tmpl.stream()
 >>> stream.buffered

tests/test_syntax.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2 import Environment, DictLoader
 from jinja2.exceptions import TemplateSyntaxError, UndefinedError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 CALL = '''{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}'''
 SLICING = '''{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}'''

tests/test_tests.py

 """
 from jinja2 import Environment, Markup
 
+import conftest
+
 
 DEFINED = '''{{ missing is defined }}|{{ true is defined }}'''
 EVEN = '''{{ 1 is even }}|{{ 2 is even }}'''

tests/test_undefined.py

     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
-from py.test import raises
 from jinja2 import Template
 from jinja2.exceptions import UndefinedError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
 
-test_default_undefined = '''
+
+def test_default_undefined():
+    '''
 >>> from jinja2 import Environment, Undefined
 >>> env = Environment(undefined=Undefined)
 >>> env.from_string('{{ missing }}').render()
 u'True'
 '''
 
-test_debug_undefined = '''
+def test_debug_undefined():
+    '''
 >>> from jinja2 import Environment, DebugUndefined
 >>> env = Environment(undefined=DebugUndefined)
 >>> env.from_string('{{ missing }}').render()
 u'True'
 '''
 
-test_strict_undefined = '''
+def test_strict_undefined():
+    '''
 >>> from jinja2 import Environment, StrictUndefined
 >>> env = Environment(undefined=StrictUndefined)
 >>> env.from_string('{{ missing }}').render()

tests/test_various.py

     :license: BSD, see LICENSE for more details.
 """
 import gc
-from py.test import raises
 from jinja2 import escape, is_undefined
 from jinja2.utils import Cycler
 from jinja2.exceptions import TemplateSyntaxError
 
+import conftest
+if conftest.NOSE:
+    from nose.tools import assert_raises as raises
+else:
+    from py.test import raises
+
 
 UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''
 RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.