Start testing richtext
This commit is contained in:
parent
bc542b5e37
commit
414d9e8ff2
1 changed files with 45 additions and 0 deletions
45
tests/tui/test_rich_text.py
Normal file
45
tests/tui/test_rich_text.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from urwid import Divider, Filler, Pile
|
||||||
|
from toot.tui.richtext import url_to_widget
|
||||||
|
from urwidgets import Hyperlink, TextEmbed
|
||||||
|
|
||||||
|
from toot.tui.richtext.richtext import html_to_widgets
|
||||||
|
|
||||||
|
|
||||||
|
def test_url_to_widget():
|
||||||
|
url = "http://foo.bar"
|
||||||
|
embed_widget = url_to_widget(url)
|
||||||
|
assert isinstance(embed_widget, TextEmbed)
|
||||||
|
|
||||||
|
[(filler, length)] = embed_widget.embedded
|
||||||
|
assert length == len(url)
|
||||||
|
assert isinstance(filler, Filler)
|
||||||
|
|
||||||
|
link_widget: Hyperlink = filler.base_widget
|
||||||
|
assert isinstance(link_widget, Hyperlink)
|
||||||
|
|
||||||
|
assert link_widget.attrib == "link"
|
||||||
|
assert link_widget.text == url
|
||||||
|
assert link_widget.uri == url
|
||||||
|
|
||||||
|
|
||||||
|
def test_html_to_widgets():
|
||||||
|
html = """
|
||||||
|
<p>foo</p>
|
||||||
|
<p>foo <b>bar</b> <i>baz</i></p>
|
||||||
|
""".strip()
|
||||||
|
|
||||||
|
[foo, divider, bar] = html_to_widgets(html)
|
||||||
|
|
||||||
|
assert isinstance(foo, Pile)
|
||||||
|
assert isinstance(divider, Divider)
|
||||||
|
assert isinstance(bar, Pile)
|
||||||
|
|
||||||
|
[foo_embed] = foo.widget_list
|
||||||
|
assert foo_embed.embedded == []
|
||||||
|
assert foo_embed.attrib == []
|
||||||
|
assert foo_embed.text == "foo"
|
||||||
|
|
||||||
|
[bar_embed] = bar.widget_list
|
||||||
|
assert bar_embed.embedded == []
|
||||||
|
assert bar_embed.attrib == [(None, 4), ("b", 3), (None, 1), ("i", 3)]
|
||||||
|
assert bar_embed.text == "foo bar baz"
|
Loading…
Reference in a new issue