1 # -*- coding: utf-8 -*-
6 All the unittests of Jinja2. These tests can be executed by
7 either running run-tests.py using multiple Python versions at
10 :copyright: (c) 2010 by the Jinja Team.
11 :license: BSD, see LICENSE for more details.
17 from traceback
import format_exception
18 from jinja2
import loaders
21 here
= os
.path
.dirname(os
.path
.abspath(__file__
))
23 dict_loader
= loaders
.DictLoader({
24 'justdict.html': 'FOO'
26 package_loader
= loaders
.PackageLoader('jinja2.testsuite.res', 'templates')
27 filesystem_loader
= loaders
.FileSystemLoader(here
+ '/res/templates')
28 function_loader
= loaders
.FunctionLoader({'justfunction.html': 'FOO'}.get
)
29 choice_loader
= loaders
.ChoiceLoader([dict_loader
, package_loader
])
30 prefix_loader
= loaders
.PrefixLoader({
31 'a': filesystem_loader
,
36 class JinjaTestCase(unittest
.TestCase
):
38 ### use only these methods for testing. If you need standard
39 ### unittest method, wrap them!
53 def assert_equal(self
, a
, b
):
54 return self
.assertEqual(a
, b
)
56 def assert_raises(self
, *args
, **kwargs
):
57 return self
.assertRaises(*args
, **kwargs
)
59 def assert_traceback_matches(self
, callback
, expected_tb
):
63 tb
= format_exception(*sys
.exc_info())
64 if re
.search(expected_tb
.strip(), ''.join(tb
)) is None:
65 raise self
.fail('Traceback did not match:\n\n%s\nexpected:\n%s'
66 % (''.join(tb
), expected_tb
))
68 self
.fail('Expected exception')
72 from jinja2
.testsuite
import ext
, filters
, tests
, core_tags
, \
73 loader
, inheritance
, imports
, lexnparse
, security
, api
, \
74 regression
, debug
, utils
, doctests
75 suite
= unittest
.TestSuite()
76 suite
.addTest(ext
.suite())
77 suite
.addTest(filters
.suite())
78 suite
.addTest(tests
.suite())
79 suite
.addTest(core_tags
.suite())
80 suite
.addTest(loader
.suite())
81 suite
.addTest(inheritance
.suite())
82 suite
.addTest(imports
.suite())
83 suite
.addTest(lexnparse
.suite())
84 suite
.addTest(security
.suite())
85 suite
.addTest(api
.suite())
86 suite
.addTest(regression
.suite())
87 suite
.addTest(debug
.suite())
88 suite
.addTest(utils
.suite())
90 # doctests will not run on python 3 currently. Too many issues
91 # with that, do not test that on that platform.
92 if sys
.version_info
< (3, 0):
93 suite
.addTest(doctests
.suite())