Beispiel #1
0
def test_format_context():
    from kemmering import bind, format_context, tag

    doc = tag('doc')(tag('p')(format_context('Hello {name}!')), 'foo')
    assert REPR(doc) == ("tag('doc')(tag('p')"
                         "(format_context('Hello {name}!')), 'foo')")
    with pytest.raises(ValueError):
        STR(doc)
    bound = bind(doc, {'name': 'Fred'})
    assert STR(bound) == '<doc><p>Hello Fred!</p>foo</doc>'
Beispiel #2
0
def test_format_context():
    from kemmering import bind, format_context, tag

    doc = tag('doc')(tag('p')(format_context('Hello {name}!')), 'foo')
    assert REPR(doc) == ("tag('doc')(tag('p')"
                         "(format_context('Hello {name}!')), 'foo')")
    with pytest.raises(ValueError):
        STR(doc)
    bound = bind(doc, {'name': 'Fred'})
    assert STR(bound) == '<doc><p>Hello Fred!</p>foo</doc>'
Beispiel #3
0
def test_cond_deferred_children():
    from kemmering import bind, cond, tag, format_context

    def is_admin(context):
        return context['user'] == 'admin'
    doc = tag('doc')(tag('p')('Hi there.', cond(
        is_admin, format_context(' Hi {user}!'))))
    assert REPR(doc) == (
        "tag('doc')(tag('p')('Hi there.', cond("
        "is_admin, format_context(' Hi {user}!'))))")
    with pytest.raises(ValueError):
        STR(doc)
    bound = bind(doc, {'user': '******'})
    assert STR(bound) == '<doc><p>Hi there. Hi admin!</p></doc>'
    bound = bind(doc, {'user': '******'})
    assert STR(bound) == '<doc><p>Hi there.</p></doc>'
Beispiel #4
0
def test_cond_deferred_children():
    from kemmering import bind, cond, tag, format_context

    def is_admin(context):
        return context['user'] == 'admin'
    doc = tag('doc')(tag('p')('Hi there.', cond(
        is_admin, format_context(' Hi {user}!'))))
    assert REPR(doc) == (
        "tag('doc')(tag('p')('Hi there.', cond("
        "is_admin, format_context(' Hi {user}!'))))")
    with pytest.raises(ValueError):
        STR(doc)
    bound = bind(doc, {'user': '******'})
    assert STR(bound) == '<doc><p>Hi there. Hi admin!</p></doc>'
    bound = bind(doc, {'user': '******'})
    assert STR(bound) == '<doc><p>Hi there.</p></doc>'