bundled/jinja2/jinja2-debug.py @ 9030dc9517cf

web: add basic tests

This patch adds a new test module `test_web` to automate testing of web
requests. For now the tests are rather simple and only check for
expected status codes.

To set up the flask app within the tests, it has to be configured
properly. This is the reason why the app configuration part in `web.py`
has been moved into an own function - now it may also be used by the
test module.
author Oben Sonne <obensonne@googlemail.com>
date Mon, 02 Jul 2012 22:32:48 +0200
parents 256716e3a3d7
children (none)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Jinja2 Debug Interface
    ~~~~~~~~~~~~~~~~~~~~~~

    Helper script for internal Jinja2 debugging.  Requires Werkzeug.

    :copyright: Copyright 2010 by Armin Ronacher.
    :license: BSD.
"""
import sys
import jinja2
from werkzeug import script

env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
                                     'jinja2.ext.loopcontrols'])

def shell_init_func():
    def _compile(x):
        print env.compile(x, raw=True)
    result = {
        'e':        env,
        'c':        _compile,
        't':        env.from_string,
        'p':        env.parse
    }
    for key in jinja2.__all__:
        result[key] = getattr(jinja2, key)
    return result


def action_compile():
    print env.compile(sys.stdin.read(), raw=True)

action_shell = script.make_shell(shell_init_func)


if __name__ == '__main__':
    script.run()