From c8e04d929c22a1a9a4b15b827162065fb5599f1a Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 14 Oct 2017 21:57:12 +0200 Subject: Fix xhtml tests, and add tests with css disabled --- test/test_xhtml.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'test') 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'

Invalid xml') +def test_xhtml_to_poezio_colors_disabled(): + config.value = False + start = b'

' + end = b'

' + xhtml = start + b'test' + end + assert xhtml_to_poezio_colors(xhtml) == 'test' + + xhtml = start + b'salut' + end + assert xhtml_to_poezio_colors(xhtml) == '\x19usalut\x19o (http://perdu.com)' + + xhtml = start + b'http://perdu.com' + end + assert xhtml_to_poezio_colors(xhtml) == '\x19uhttp://perdu.com\x19o' + + xhtml = b'
Allo
test
test2
' + assert xhtml_to_poezio_colors(xhtml, force=True) == 'Allo test test2' + + xhtml = (b'
' + b'
Allo
' + b'test
test2
') + 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) == '' - -- cgit v1.2.3