From 29942d38bb88e4654879bcaff0a004c646e1a315 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 27 Oct 2014 20:01:22 +0100 Subject: Add some unit tests using py.test - we need to have more --- test/test_xhtml.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/test_xhtml.py (limited to 'test/test_xhtml.py') 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 = "

" + end = "

" + text = '\x191}coucou' + assert poezio_colors_to_html(text) == base + 'coucou' + end + + text = '\x19bcoucou\x19o toto \x194}titi' + assert poezio_colors_to_html(text) == base + 'coucou toto titi' + end + +def test_xhtml_to_poezio_colors(): + 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' + + with pytest.raises(xml.sax._exceptions.SAXParseException): + xhtml_to_poezio_colors(b'

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) == '' + -- cgit v1.2.3