summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2017-10-14 21:57:12 +0200
committermathieui <mathieui@mathieui.net>2017-10-14 21:57:12 +0200
commitc8e04d929c22a1a9a4b15b827162065fb5599f1a (patch)
treeb8edd3afab916f6989262228088a5623e04fbbfd
parent74ba7a85e6aace87fb4993cb99c83619a205a419 (diff)
downloadpoezio-c8e04d929c22a1a9a4b15b827162065fb5599f1a.tar.gz
poezio-c8e04d929c22a1a9a4b15b827162065fb5599f1a.tar.bz2
poezio-c8e04d929c22a1a9a4b15b827162065fb5599f1a.tar.xz
poezio-c8e04d929c22a1a9a4b15b827162065fb5599f1a.zip
Fix xhtml tests, and add tests with css disabled
-rw-r--r--test/test_xhtml.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/test/test_xhtml.py b/test/test_xhtml.py
index d81505da..4f0f2b4f 100644
--- a/test/test_xhtml.py
+++ b/test/test_xhtml.py
@@ -4,10 +4,19 @@ Test the functions in the `xhtml` module
import pytest
import xml
-
+import poezio.xhtml
from poezio.xhtml import (poezio_colors_to_html, xhtml_to_poezio_colors,
_parse_css as parse_css, clean_text)
+class ConfigShim(object):
+ def __init__(self):
+ self.value = True
+ def get(self, *args, **kwargs):
+ return self.value
+
+config = ConfigShim()
+poezio.xhtml.config = config
+
def test_clean_text():
example_string = '\x191}Toto \x192,-1}titi\x19b Tata'
assert clean_text(example_string) == 'Toto titi Tata'
@@ -47,10 +56,32 @@ def test_xhtml_to_poezio_colors():
with pytest.raises(xml.sax._exceptions.SAXParseException):
xhtml_to_poezio_colors(b'<p>Invalid xml')
+def test_xhtml_to_poezio_colors_disabled():
+ config.value = False
+ 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'
+
+ xhtml = b'<div style="font-weight:bold">Allo <div style="color:red">test <div style="color: blue">test2</div></div></div>'
+ assert xhtml_to_poezio_colors(xhtml, force=True) == 'Allo test test2'
+
+ xhtml = (b'<div style="color:blue"><div style="color:yellow">'
+ b'<div style="color:blue">Allo <div style="color:red">'
+ b'test <div style="color: blue">test2</div></div></div></div></div>')
+ assert xhtml_to_poezio_colors(xhtml, force=True) == 'Allo test test2'
+
+ config.value = True
+
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) == ''
-