Skip to content
Myr

more unittests

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 9cf9591 · Browse files · 3 files+65 added−25 removed
This commit

State

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

Diff stats

3 files+65 added−25 removed

  • tests:+64 added−24 removed
  • other:+1 added−1 removed

3 files+65 added−25 removed

modified:jinja2/_speedups.c+1 added-1 removed
90 unmodified lines
91 92 if (next_escp > inp) {93 /* copy unescaped chars between inp and next_escp */94 Py_UNICODE_COPY(outp, inp, next_escp-inp);95 outp += next_escp-inp;95 outp += next_escp - inp;96 }9798 /* escape 'next_escp' */99 Py_UNICODE_COPY(outp, escaped_chars_repl[*next_escp], delta_len);
113 unmodified lines
modified:tests/test_loaders.py+46 added-24 removed
15 unmodified lines
1617dict_loader = loaders.DictLoader({18 'justdict.html': 'FOO'19})2020package_loader = loaders.PackageLoader('loaderres', 'templates')2221filesystem_loader = loaders.FileSystemLoader('loaderres/templates')2422function_loader = loaders.FunctionLoader({'justfunction.html': 'FOO'}.get)2623choice_loader = loaders.ChoiceLoader([dict_loader, package_loader])24prefix_loader = loaders.PrefixLoader({25 'a': filesystem_loader,26 'b': dict_loader27})282930def test_dict_loader():31 env = Environment(loader=dict_loader)32 tmpl = env.get_template('justdict.html')33 assert tmpl.render().strip() == 'FOO'34 try:35 env.get_template('missing.html')36 except TemplateNotFound:37 pass38 else:39 raise AssertionError('expected template exception')34 raises(TemplateNotFound, env.get_template, 'missing.html')353637def test_package_loader():38 env = Environment(loader=package_loader)39 tmpl = env.get_template('test.html')40 assert tmpl.render().strip() == 'BAR'46 raises(TemplateNotFound, lambda: env.get_template('missing.html'))41 raises(TemplateNotFound, env.get_template, 'missing.html')424344def test_filesystem_loader():45 env = Environment(loader=filesystem_loader)46 tmpl = env.get_template('test.html')47 assert tmpl.render().strip() == 'BAR'48 tmpl = env.get_template('foo/test.html')49 assert tmpl.render().strip() == 'FOO'55 raises(TemplateNotFound, lambda: env.get_template('missing.html'))50 raises(TemplateNotFound, env.get_template, 'missing.html')515253def test_choice_loader():54 env = Environment(loader=choice_loader)55 tmpl = env.get_template('justdict.html')56 assert tmpl.render().strip() == 'FOO'57 tmpl = env.get_template('test.html')58 assert tmpl.render().strip() == 'BAR'64 try:65 env.get_template('missing.html')66 except TemplateNotFound:67 pass68 else:69 raise AssertionError('expected template exception')59 raises(TemplateNotFound, env.get_template, 'missing.html')606162def test_function_loader():63 env = Environment(loader=function_loader)64 tmpl = env.get_template('justfunction.html')65 assert tmpl.render().strip() == 'FOO'76 try:77 env.get_template('missing.html')78 except TemplateNotFound:79 pass80 else:81 raise AssertionError('expected template exception')66 raises(TemplateNotFound, env.get_template, 'missing.html')676869def test_prefix_loader():70 env = Environment(loader=prefix_loader)71 tmpl = env.get_template('a/test.html')72 assert tmpl.render().strip() == 'BAR'73 tmpl = env.get_template('b/justdict.html')74 assert tmpl.render().strip() == 'FOO'75 raises(TemplateNotFound, env.get_template, 'missing')767778def test_caching():79 changed = False80 class TestLoader(loaders.BaseLoader):81 def get_source(self, environment, template):82 return u'foo', None, lambda: not changed83 env = Environment(loader=TestLoader(), cache_size=-1)84 tmpl = env.get_template('template')85 assert tmpl is env.get_template('template')86 changed = True87 assert tmpl is not env.get_template('template')88 changed = False8990 env = Environment(loader=TestLoader(), cache_size=0)91 assert env.get_template('template') \92 is not env.get_template('template')9394 env = Environment(loader=TestLoader(), cache_size=2)95 t1 = env.get_template('one')96 t2 = env.get_template('two')97 print env.cache98 assert t2 is env.get_template('two')99 assert t1 is env.get_template('one')100 t3 = env.get_template('three')101 assert 'one' in env.cache102 assert 'two' not in env.cache103 assert 'three' in env.cache
modified:tests/test_macros.py+18 added
84 unmodified lines
8586def test_include(env):87 tmpl = env.from_string('{% from "include" import test %}{{ test("foo") }}')88 assert tmpl.render() == '[foo]'899091def test_macro_api(env):92 tmpl = env.from_string('{% macro foo(a, b) %}{% endmacro %}'93 '{% macro bar() %}{{ varargs }}{{ kwargs }}{% endmacro %}'94 '{% macro baz() %}{{ caller() }}{% endmacro %}')95 assert tmpl.module.foo.arguments == ('a', 'b')96 assert tmpl.module.foo.defaults == ()97 assert tmpl.module.foo.name == 'foo'98 assert not tmpl.module.foo.caller99 assert not tmpl.module.foo.catch_kwargs100 assert not tmpl.module.foo.catch_varargs101 assert tmpl.module.bar.arguments == ()102 assert tmpl.module.bar.defaults == ()103 assert not tmpl.module.bar.caller104 assert tmpl.module.bar.catch_kwargs105 assert tmpl.module.bar.catch_varargs106 assert tmpl.module.baz.caller