def test_tag_half(): tag = TagFactory(xml=False) assert html(tag.foo(bar='baz', _open=False)) == '</foo>' assert html(tag.foo(bar='baz', _close=False)) == '<foo bar="baz">' assert html(tag.br(foo='bar', _close=False)) == '<br foo="bar">' assert html(tag.br(foo='bar', _open=False)) == '' assert html(tag.br(foo='bar', _open=False, _close=True)) == '</br>' tag = TagFactory(xml=True) assert html(tag.foo(bar='baz', _open=False)) == '</foo>' # XXX Surely this is wrong? assert html(tag.foo(bar='baz', _close=False)) == '<foo bar="baz"/>' assert html(tag.br(foo='bar', _close=False)) == '<br foo="bar"/>' assert html(tag.br(foo='bar', _open=False)) == '' assert html(tag.br(foo='bar', _open=False, _close=True)) == '</br>'
def test_xml_tag_attrs(): tag = TagFactory(xml=True) assert html(tag.foo(bar='baz')) == '<foo bar="baz"></foo>' assert html(tag.foo(bar=101)) == '<foo bar="101"></foo>' assert html(tag.foo(bar=True)) == '<foo bar="bar"></foo>' assert html(tag.foo(bar=False)) == '<foo></foo>' assert html(tag.foo(bar=None)) == '<foo></foo>' assert html(tag.br(foo='bar')) == '<br foo="bar"/>' assert html(tag.foo(bar=b'baz')) == '<foo bar="baz"></foo>' assert html(tag.br(foo=b'm\xc2\xb5')) == '<br foo="mµ"/>' assert html(tag.foo(bar=range(5))) == '<foo bar="01234"></foo>'
def test_tag_contents(): tag = TagFactory(xml=False) assert html(tag.foo(tag.bar('baz'))) == '<foo><bar>baz</bar></foo>' assert html(tag.foo('bar', 'baz')) == '<foo>barbaz</foo>' assert html(tag.foo(1, ' ', 2, ' ', 3)) == '<foo>1 2 3</foo>'
def test_html_tag_basics(): tag = TagFactory(xml=False) assert html(tag.a()) == '<a></a>' assert html(tag.br()) == '<br>' assert html(tag.foo()) == '<foo></foo>'
def test_str(): assert html('foo') == 'foo' assert html('<foo>') == '<foo>' assert html('foo & bar') == 'foo & bar'
def test_content(): assert html(content('foo')) == 'foo' assert html(content('<foo>')) == '<foo>' assert html(content('foo & bar')) == 'foo & bar'
def test_literals(): assert html(literal('foo')) == 'foo' assert html(literal('<foo>')) == '<foo>' assert html(literal('foo & bar')) == 'foo & bar'