# coding:utf-8 from __future__ import absolute_import from talon import utils as u from . import * def test_get_delimiter(): eq_('\r\n', u.get_delimiter('abc\r\n123')) eq_('\n', u.get_delimiter('abc\n123')) eq_('\n', u.get_delimiter('abc')) def test_html_to_text(): html = """

Hello world!


Haha

""" text = u.html_to_text(html) eq_("Hello world! \n\n * One! \n * Two \nHaha", text) eq_(u"привет!", u.html_to_text("привет!")) html = '

Hi' eq_('Hi', u.html_to_text(html)) html = """Hi """ eq_('Hi', u.html_to_text(html)) html = """
TEXT 1

TEXT 2

""" eq_('TEXT 1 \nTEXT 2', u.html_to_text(html)) def test_comment_no_parent(): s = ' no comment' d = u.html_document_fromstring(s) eq_("no comment", u.html_tree_to_text(d)) @patch.object(u, 'html_fromstring', Mock(return_value=None)) def test_bad_html_to_text(): bad_html = "one
two
three" eq_(None, u.html_to_text(bad_html))