Skip to content
Myr

[svn] moved all jinja tests into a runtime folder so that we have enough space for the new unittests

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

--HG-- branch : trunk rename : tests/bigtable.py => tests/runtime/bigtable.py rename : tests/exception.py => tests/runtime/exception.py rename : tests/inheritance.py => tests/runtime/inheritance.py rename : tests/layout.py => tests/runtime/layout.py rename : tests/templates/a.html => tests/runtime/templates/a.html rename : tests/templates/b.html => tests/runtime/templates/b.html rename : tests/templates/c.html => tests/runtime/templates/c.html rename : tests/templates/error.html => tests/runtime/templates/error.html rename : tests/templates/included_error.html => tests/runtime/templates/included_error.html rename : tests/templates/index.html => tests/runtime/templates/index.html rename : tests/templates/layout.html => tests/runtime/templates/layout.html

authored by Armin Ronacher · committed by Armin Ronacher · parent 3f8ba8d · Browse files · 22 files+250 added−250 removed
This commit

State

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

Diff stats

22 files+250 added−250 removed

  • tests:+250 added−250 removed

22 files+250 added−250 removed

added:tests/runtime/templates/a.html+12 added
added:tests/runtime/templates/b.html+8 added
added:tests/runtime/templates/c.html+7 added
added:tests/runtime/templates/error.html+6 added
added:tests/runtime/templates/included_error.html+2 added
added:tests/runtime/templates/index.html+13 added
added:tests/runtime/templates/layout.html+23 added
added:tests/runtime/bigtable.py+148 added
1# -*- coding: utf-8 -*_2# Template language benchmarks3#4# Objective: Generate a 1000x10 HTML table as fast as possible.5# adapted for jinja 16#7# Author: Jonas Borgström <jonas@edgewall.com>8# Author: Armin Ronacher <armin.ronacher@active-4.com>910import cgi11import sys12import timeit13from StringIO import StringIO1415from genshi.builder import tag16from genshi.template import MarkupTemplate1718from jinja import Environment1920try:21 from django.conf import settings22 settings.configure()23 from django.template import Context as DjangoContext24 from django.template import Template as DjangoTemplate25 have_django = True26except ImportError:27 have_django = False2829from Cheetah.Template import Template as CheetahTemplate3031try:32 from mako.template import Template as MakoTemplate33 have_mako = True34except ImportError:35 have_mako = False3637table = [dict(a='1',b='2',c='3',d='4',e='5',f='6',g='7',h='8',i='9',j='10')38 for x in range(1000)]3940genshi_tmpl = MarkupTemplate("""41<table xmlns:py="http://genshi.edgewall.org/">42<tr py:for="row in table">43<td py:for="c in row.values()" py:content="c"/>44</tr>45</table>46""")4748if have_django:49 django_tmpl = DjangoTemplate("""50<table>51{% for row in table %}52<tr>{% for col in row.values %}{{ col|escape }}{% endfor %}</tr>53{% endfor %}54</table>55""")5657jinja_tmpl = Environment().from_string('''58<table>59{% for row in table %}60<tr>{% for col in row.values() %}{{ col|escape }}{% endfor %}</tr>61{% endfor %}62</table>63''')6465cheetah_tmpl = CheetahTemplate('''66# filter escape67<table>68#for $row in $table69<tr>70#for $col in $row.values()71$col72#end for73</tr>74#end for75</table>76''', searchList=[{'table': table, 'escape': cgi.escape}])7778if have_mako:79 mako_tmpl = MakoTemplate('''80<table>81% for row in table:82<tr>83% for col in row.values():84 ${col|h}85% endfor86</tr>87% endfor88</table>89''')9091def test_django():92 """Django Templates"""93 if not have_django:94 return95 context = DjangoContext({'table': table})96 django_tmpl.render(context)9798def test_jinja():99 """Jinja Templates"""100 jinja_tmpl.render(table=table)101102def test_genshi():103 """Genshi Templates"""104 stream = genshi_tmpl.generate(table=table)105 stream.render('html', strip_whitespace=False)106107def test_cheetah():108 """Cheetah Templates"""109 cheetah_tmpl.respond()110111def test_mako():112 """Mako Templates"""113 if not have_mako:114 return115 mako_tmpl.render(table=table)116117118def run(which=None, number=10):119 tests = ['test_django', 'test_jinja', 'test_genshi', 'test_cheetah', 'test_mako']120121 if which:122 tests = filter(lambda n: n[5:] in which, tests)123124 for test in [t for t in tests if hasattr(sys.modules[__name__], t)]:125 t = timeit.Timer(setup='from __main__ import %s;' % test,126 stmt='%s()' % test)127 time = t.timeit(number=number) / number128129 if time < 0.00001:130 result = ' (not installed?)'131 else:132 result = '%16.2f ms' % (1000 * time)133 print '%-35s %s' % (getattr(sys.modules[__name__], test).__doc__, result)134135136if __name__ == '__main__':137 which = [arg for arg in sys.argv[1:] if arg[0] != '-']138139 if '-p' in sys.argv:140 import hotshot, hotshot.stats141 prof = hotshot.Profile("template.prof")142 benchtime = prof.runcall(run, which, number=1)143 stats = hotshot.stats.load("template.prof")144 stats.strip_dirs()145 stats.sort_stats('time', 'calls')146 stats.print_stats()147 else:148 run(which)
added:tests/runtime/exception.py+10 added
1from jinja import Environment, FileSystemLoader2from colubrid.debug import DebuggedApplication3from wsgiref.simple_server import make_server4e = Environment(loader=FileSystemLoader('templates'))56def test(*args):7 tmpl = e.loader.load('error.html')8 tmpl.render(items=range(10))910make_server("localhost", 7000, DebuggedApplication(test)).serve_forever()
added:tests/runtime/inheritance.py+8 added
1from jinja import Environment, FileSystemLoader2e = Environment(loader=FileSystemLoader('templates'))34from jinja.parser import Parser5from jinja.translators.python import PythonTranslator67tmpl = e.loader.load('c.html')8print tmpl.render()
added:tests/runtime/layout.py+13 added
1from jinja import Environment, FileSystemLoader2e = Environment(loader=FileSystemLoader('templates'))34from jinja.parser import Parser5from jinja.translators.python import PythonTranslator67print PythonTranslator(e, e.loader.parse('index.html')).translate()89tmpl = e.loader.load('index.html')10print tmpl.render(navigation_items=[{11 'url': '/',12 'caption': 'Index'13}])
deleted:tests/templates/a.html-12 removed
1{% block block1 %}from template a.html{% endblock %}2{% block block2 %}from template a.html{% endblock %}3{% block block3 %}from template a.html{% endblock %}4{% block block4 %}5 nested block from template a.html6 {% block block5 %}7 contents of the nested block from a.html8 {% block block6 %}9 double nested block.10 {% endblock %}11 {% endblock %}12{% endblock %}
deleted:tests/templates/b.html-8 removed
1{% extends 'a.html' %}2{% block block1 %}from template b.html{% endblock %}3{% block block5 %}4 contents of nested block from b.html5 {% block block7 %}6 new nested block introduced in b.html7 {% endblock %}8{% endblock %}
deleted:tests/templates/c.html-7 removed
1{% extends 'b.html' %}2{% block block2 %}from template c.html{% endblock %}3{% block block3 %}from template c.html{% endblock %}4{% block block7 %}5 nested block from b.html, overridden in c.html6 {{ 1 / 0 }}7{% endblock %}
deleted:tests/templates/error.html-6 removed
1<ul>2<meta http-equiv="Content-Type" content="" />3{% for item in items %}4 {% include "included_error.html" %}5{% endfor %}6</ul>
deleted:tests/templates/included_error.html-2 removed
1This breaks the template:2{{ 1 / 0 }}
deleted:tests/templates/index.html-13 removed
1{% extends "layout.html" %}23{% macro say_hello name %}4Hello {{ name }}!.5{% endmacro %}67{% set greet = say_hello %}89{% block page_title %}Index{% endblock %}10{% block body %}11 This is the index page.<br />12 {{ greet('John Doe') }}13{% endblock %}
deleted:tests/templates/layout.html-23 removed
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">3<html>4 <head>5 <title>{% block page_title %}Untitled{% endblock %} | My Webpage</title>6 {% block page_head %}{% endblock %}7 </head>8 <body>9 <div id="header">10 <h1>My Webpage</h1>11 <ul id="navigation">12 {% for item in navigation_items %}13 <li><a href="{{ item.url|escape }}">{{ item.caption|escape }}</a></li>14 {% endfor %}15 </ul>16 </div>17 <div id="body">18 {% block body %}19 content goes here.20 {% endblock %}21 </div>22 </body>23</html>
deleted:tests/bigtable.py-148 removed
1# -*- coding: utf-8 -*_2# Template language benchmarks3#4# Objective: Generate a 1000x10 HTML table as fast as possible.5# adapted for jinja 16#7# Author: Jonas Borgström <jonas@edgewall.com>8# Author: Armin Ronacher <armin.ronacher@active-4.com>910import cgi11import sys12import timeit13from StringIO import StringIO1415from genshi.builder import tag16from genshi.template import MarkupTemplate1718from jinja import Environment1920try:21 from django.conf import settings22 settings.configure()23 from django.template import Context as DjangoContext24 from django.template import Template as DjangoTemplate25 have_django = True26except ImportError:27 have_django = False2829from Cheetah.Template import Template as CheetahTemplate3031try:32 from mako.template import Template as MakoTemplate33 have_mako = True34except ImportError:35 have_mako = False3637table = [dict(a='1',b='2',c='3',d='4',e='5',f='6',g='7',h='8',i='9',j='10')38 for x in range(1000)]3940genshi_tmpl = MarkupTemplate("""41<table xmlns:py="http://genshi.edgewall.org/">42<tr py:for="row in table">43<td py:for="c in row.values()" py:content="c"/>44</tr>45</table>46""")4748if have_django:49 django_tmpl = DjangoTemplate("""50<table>51{% for row in table %}52<tr>{% for col in row.values %}{{ col|escape }}{% endfor %}</tr>53{% endfor %}54</table>55""")5657jinja_tmpl = Environment().from_string('''58<table>59{% for row in table %}60<tr>{% for col in row.values() %}{{ col|escape }}{% endfor %}</tr>61{% endfor %}62</table>63''')6465cheetah_tmpl = CheetahTemplate('''66# filter escape67<table>68#for $row in $table69<tr>70#for $col in $row.values()71$col72#end for73</tr>74#end for75</table>76''', searchList=[{'table': table, 'escape': cgi.escape}])7778if have_mako:79 mako_tmpl = MakoTemplate('''80<table>81% for row in table:82<tr>83% for col in row.values():84 ${col|h}85% endfor86</tr>87% endfor88</table>89''')9091def test_django():92 """Django Templates"""93 if not have_django:94 return95 context = DjangoContext({'table': table})96 django_tmpl.render(context)9798def test_jinja():99 """Jinja Templates"""100 jinja_tmpl.render(table=table)101102def test_genshi():103 """Genshi Templates"""104 stream = genshi_tmpl.generate(table=table)105 stream.render('html', strip_whitespace=False)106107def test_cheetah():108 """Cheetah Templates"""109 cheetah_tmpl.respond()110111def test_mako():112 """Mako Templates"""113 if not have_mako:114 return115 mako_tmpl.render(table=table)116117118def run(which=None, number=10):119 tests = ['test_django', 'test_jinja', 'test_genshi', 'test_cheetah', 'test_mako']120121 if which:122 tests = filter(lambda n: n[5:] in which, tests)123124 for test in [t for t in tests if hasattr(sys.modules[__name__], t)]:125 t = timeit.Timer(setup='from __main__ import %s;' % test,126 stmt='%s()' % test)127 time = t.timeit(number=number) / number128129 if time < 0.00001:130 result = ' (not installed?)'131 else:132 result = '%16.2f ms' % (1000 * time)133 print '%-35s %s' % (getattr(sys.modules[__name__], test).__doc__, result)134135136if __name__ == '__main__':137 which = [arg for arg in sys.argv[1:] if arg[0] != '-']138139 if '-p' in sys.argv:140 import hotshot, hotshot.stats141 prof = hotshot.Profile("template.prof")142 benchtime = prof.runcall(run, which, number=1)143 stats = hotshot.stats.load("template.prof")144 stats.strip_dirs()145 stats.sort_stats('time', 'calls')146 stats.print_stats()147 else:148 run(which)
deleted:tests/exception.py-10 removed
1from jinja import Environment, FileSystemLoader2from colubrid.debug import DebuggedApplication3from wsgiref.simple_server import make_server4e = Environment(loader=FileSystemLoader('templates'))56def test(*args):7 tmpl = e.loader.load('error.html')8 tmpl.render(items=range(10))910make_server("localhost", 7000, DebuggedApplication(test)).serve_forever()
deleted:tests/inheritance.py-8 removed
1from jinja import Environment, FileSystemLoader2e = Environment(loader=FileSystemLoader('templates'))34from jinja.parser import Parser5from jinja.translators.python import PythonTranslator67tmpl = e.loader.load('c.html')8print tmpl.render()
deleted:tests/layout.py-13 removed
1from jinja import Environment, FileSystemLoader2e = Environment(loader=FileSystemLoader('templates'))34from jinja.parser import Parser5from jinja.translators.python import PythonTranslator67print PythonTranslator(e, e.loader.parse('index.html')).translate()89tmpl = e.loader.load('index.html')10print tmpl.render(navigation_items=[{11 'url': '/',12 'caption': 'Index'13}])