# Path: genshi/template/directives.py
# class DirectiveMeta(type):
# class Directive(object):
# class AttrsDirective(Directive):
# class ContentDirective(Directive):
# class DefDirective(Directive):
# class ForDirective(Directive):
# class IfDirective(Directive):
# class MatchDirective(Directive):
# class ReplaceDirective(Directive):
# class StripDirective(Directive):
# class ChooseDirective(Directive):
# class WhenDirective(Directive):
# class OtherwiseDirective(Directive):
# class WithDirective(Directive):
#     def __new__(cls, name, bases, d):
#     def __init__(self, value, template=None, namespaces=None, lineno=-1,
#                  offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def _parse_expr(cls, expr, template, lineno=-1, offset=-1):
# def _assignment(ast):
#     def _names(node):
#     def _assign(data, value, names=_names(ast)):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def _generate():
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __init__(self, args, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def function(*args, **kwargs):
#     def __repr__(self):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, hints=None, namespaces=None,
#                  lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def _generate():
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):


import doctest
import re
import sys
import unittest
from genshi.template import directives, MarkupTemplate, TextTemplate, \
                            TemplateRuntimeError, TemplateSyntaxError

    def test_function_raising_typeerror(self):
        def badfunc():
            raise TypeError
        tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
          <div py:def="dobadfunc()">
            ${badfunc()}
          </div>
          <div py:content="dobadfunc()"/>
        </html>""")
        self.assertRaises(TypeError, list, tmpl.generate(badfunc=badfunc))

    def test_def_in_matched(self):
        tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/">
          <head py:match="head">${select('*')}</head>
          <head>
            <py:def function="maketitle(test)"><b py:replace="test" /></py:def>
            <title>${maketitle(True)}</title>
          </head>
        </doc>""")
        self.assertEqual("""<doc>
          <head><title>True</title></head>
        </doc>""", tmpl.generate().render(encoding=None))

    def test_in_text_template(self):
        """
        Verify that the directive works as expected in a text template.
        """
        tmpl = TextTemplate("""
          #def echo(greeting, name='world')

# Path: genshi/template/directives.py
# class DirectiveMeta(type):
# class Directive(object):
# class AttrsDirective(Directive):
# class ContentDirective(Directive):
# class DefDirective(Directive):
# class ForDirective(Directive):
# class IfDirective(Directive):
# class MatchDirective(Directive):
# class ReplaceDirective(Directive):
# class StripDirective(Directive):
# class ChooseDirective(Directive):
# class WhenDirective(Directive):
# class OtherwiseDirective(Directive):
# class WithDirective(Directive):
#     def __new__(cls, name, bases, d):
#     def __init__(self, value, template=None, namespaces=None, lineno=-1,
#                  offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def _parse_expr(cls, expr, template, lineno=-1, offset=-1):
# def _assignment(ast):
#     def _names(node):
#     def _assign(data, value, names=_names(ast)):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def _generate():
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __init__(self, args, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def function(*args, **kwargs):
#     def __repr__(self):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, hints=None, namespaces=None,
#                  lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#         def _generate():
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
#     def attach(cls, template, stream, value, namespaces, pos):
#     def __call__(self, stream, directives, ctxt, **vars):
#     def __repr__(self):


# Path: genshi/template/tests/directives.py
import doctest
import re
import sys
import unittest
from genshi.template import directives, MarkupTemplate, TextTemplate, \
                            TemplateRuntimeError, TemplateSyntaxError


    def test_function_raising_typeerror(self):
        def badfunc():
            raise TypeError
        tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
          <div py:def="dobadfunc()">
            ${badfunc()}
          </div>
          <div py:content="dobadfunc()"/>
        </html>""")
        self.assertRaises(TypeError, list, tmpl.generate(badfunc=badfunc))

    def test_def_in_matched(self):
        tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/">
          <head py:match="head">${select('*')}</head>
          <head>
            <py:def function="maketitle(test)"><b py:replace="test" /></py:def>
            <title>${maketitle(True)}</title>
          </head>
        </doc>""")
        self.assertEqual("""<doc>
          <head><title>True</title></head>
        </doc>""", tmpl.generate().render(encoding=None))

    def test_in_text_template(self):
        """
        Verify that the directive works as expected in a text template.
        """
        tmpl = TextTemplate("""
          #def echo(greeting, name='world')

            ${greeting}, ${name}!