コード例 #1
0
def test_void_tag():
    t = Tag('img')
    assert t._opener_ == '<img>'
    assert t._closer_ == ''

    t = Tag('img', foo='bar')
    assert t._opener_ == '<img foo="bar">'
    assert t._closer_ == ''

    with raises(ChildNodeError):
        t.foo
コード例 #2
0
def test_raw_text_tag():
    t = Tag('style')
    assert t._opener_ == '<style>'
    assert t._closer_ == '</style>'

    t = Tag('style', foo='bar')
    assert t._opener_ == '<style foo="bar">'
    assert t._closer_ == '</style>'

    t += 'this is some text'
    t += 'this is more text'
    assert type(t._children_[0]) == Text
    assert type(t._children_[1]) == Text

    with raises(ChildNodeError):
        t.foo
コード例 #3
0
def test_tag():
    t = Tag('t')
    assert t._opener_ == '<t>'
    assert t._closer_ == '</t>'

    t = Tag('t', foo='bar')
    assert t._opener_ == '<t foo="bar">'
    assert t._closer_ == '</t>'

    t = Tag('t', _class='bar')
    assert t._opener_ == '<t class="bar">'
    assert t._closer_ == '</t>'

    t = Tag()
    assert t._opener_ == ''
    assert t._closer_ == ''
コード例 #4
0
def test_blocks_tag_content():
    r = Template()
    h = r.html
    h += Template('foo') + 'default'

    context = {'foo': Tag('p') + 'this is overwritten'}
    output = render(r, context=context, pretty=False)
    expected = '<html><p>this is overwritten</p></html>'
    assert output == expected
コード例 #5
0
def test_blocks_content():
    r = Template()
    h = r.html
    foo = Template('foo')
    foo.p += 'default'
    h += foo

    data = Tag('div')
    data += 'this is overwritten'

    context = {'foo': data}
    output = render(r, context=context, pretty=False)
    expected = '<html><div>this is overwritten</div></html>'
    assert output == expected
コード例 #6
0
def test_add_magic():
    r = Template()
    h = r.html
    h.p += ('this ', 'is ', 'a ', (Tag('em') + 'test'))
    foo = h.foo(foo='bar')
    foo += 'this is another'
    bar = h.bar
    bar += 'foo'
    bar += 'bar'
    bar += 'baz'
    output = render(r, pretty=False)
    expected = ('<html>'
                '<p>this is a <em>test</em></p>'
                '<foo foo="bar">this is another</foo>'
                '<bar>foobarbaz</bar>'
                '</html>')
    assert output == expected
コード例 #7
0
def test_add_basic():
    r = Tag('p') + 'hi'
    output = render(r, pretty=False)
    assert output == '<p>hi</p>'
コード例 #8
0
def test_attrs():
    t = Tag(foo='bar')
    assert t._attrs_['foo'] == 'bar'

    t.foo(level='child')
    assert t._children_[0]._attrs_ == {'level': 'child'}