summaryrefslogtreecommitdiff
path: root/test/test_xhtml.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-10-31 19:15:57 +0100
committermathieui <mathieui@mathieui.net>2014-10-31 19:16:44 +0100
commit1c1ab3cb839e5509db52770e10c7190f844eb2e5 (patch)
treeb331060b3dc42651e61e4ccb2dfe6af5e2e97752 /test/test_xhtml.py
parentcedc5a6ec80a46437f42464415fd1806049c593d (diff)
parentea2b703bfd07d293ba9fdd85ac657275d43da2a7 (diff)
downloadpoezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.gz
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.bz2
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.xz
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.zip
Merge branch 'master' of git.poez.io:poezio into slix
Conflicts: src/bookmark.py src/config.py src/connection.py src/core/commands.py src/core/core.py src/core/handlers.py src/windows/info_bar.py src/windows/muc.py src/windows/roster_win.py src/windows/text_win.py src/xhtml.py
Diffstat (limited to 'test/test_xhtml.py')
-rw-r--r--test/test_xhtml.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/test_xhtml.py b/test/test_xhtml.py
new file mode 100644
index 00000000..58857d67
--- /dev/null
+++ b/test/test_xhtml.py
@@ -0,0 +1,50 @@
+"""
+Test the functions in the `xhtml` module
+"""
+
+import pytest
+import sys
+import xml
+sys.path.append('src')
+
+from xhtml import (poezio_colors_to_html, xhtml_to_poezio_colors,
+ parse_css, clean_text)
+
+def test_clean_text():
+ example_string = '\x191}Toto \x192,-1}titi\x19b Tata'
+ assert clean_text(example_string) == 'Toto titi Tata'
+
+ clean_string = 'toto titi tata'
+ assert clean_text(clean_string) == clean_string
+
+def test_poezio_colors_to_html():
+ base = "<body xmlns='http://www.w3.org/1999/xhtml'><p>"
+ end = "</p></body>"
+ text = '\x191}coucou'
+ assert poezio_colors_to_html(text) == base + '<span style="color: red;">coucou</span>' + end
+
+ text = '\x19bcoucou\x19o toto \x194}titi'
+ assert poezio_colors_to_html(text) == base + '<span style="font-weight: bold;">coucou</span> toto <span style="color: blue;">titi</span>' + end
+
+def test_xhtml_to_poezio_colors():
+ start = b'<body xmlns="http://www.w3.org/1999/xhtml"><p>'
+ end = b'</p></body>'
+ xhtml = start + b'test' + end
+ assert xhtml_to_poezio_colors(xhtml) == 'test'
+
+ xhtml = start + b'<a href="http://perdu.com">salut</a>' + end
+ assert xhtml_to_poezio_colors(xhtml) == '\x19usalut\x19o (http://perdu.com)'
+
+ xhtml = start + b'<a href="http://perdu.com">http://perdu.com</a>' + end
+ assert xhtml_to_poezio_colors(xhtml) == '\x19uhttp://perdu.com\x19o'
+
+ with pytest.raises(xml.sax._exceptions.SAXParseException):
+ xhtml_to_poezio_colors(b'<p>Invalid xml')
+
+def test_parse_css():
+ example_css = 'text-decoration: underline; color: red;'
+ assert parse_css(example_css) == '\x19u\x19196}'
+
+ example_css = 'text-decoration: underline coucou color: red;'
+ assert parse_css(example_css) == ''
+