Exemple #1
0
def test_html_parser_with_templates():
    for _, html in ((JinjaTemplate, '{{ name }} <a href="{{ link }}">_</a>'),
                    (StringTemplate, '${name} <a href="${link}">_</a>'),
                    (MakoTemplate, '${name} <a href="${link}">_</a>')):
        # Test that html parser doesn't break template code
        t = HTMLParser(html=html, method='html')
        assert html in t.to_string()
def test_html_parser_with_templates():
    for _, html in (
            (JinjaTemplate, '{{ name }} <a href="{{ link }}">_</a>'),
            (StringTemplate, '${name} <a href="${link}">_</a>'),
            (MakoTemplate, '${name} <a href="${link}">_</a>')
    ):
        # Test that html parser doesn't break template code
        t = HTMLParser(html=html, method='html')
        assert html in t.to_string()
Exemple #3
0
def test_parser_inputs():
    def _cleaned_body(s):
        for el in ('html', 'body'):
            s = s.replace('<%s>' % el, '').replace('</%s>' % el, '')
        return s

    # This is a fixation of de-facto rendering results

    for html, result in (("<html><!-- comment -->", "<!-- comment -->"),
                         ("<a href='[]&'>_</a>", '<a href="[]&amp;">_</a>'),
                         ('<p>a\r\n', '<p>a</p>')):
        r = HTMLParser(html=html).to_string()
        print("html=", html.__repr__(), "result=", r.__repr__(), sep='')
        assert _cleaned_body(r) == result
def test_parser_inputs():

    def _cleaned_body(s):
        for el in ('html', 'body'):
            s = s.replace('<%s>' % el, '').replace('</%s>' % el, '')
        return s

    # This is a fixation of de-facto rendering results

    for html, result in (
            ("<html><!-- comment -->", "<!-- comment -->"),
            ("<a href='[]&'>_</a>", '<a href="[]&amp;">_</a>'),
            ('<p>a\r\n', '<p>a</p>')
    ):
        r = HTMLParser(html=html).to_string()
        print("html=", html.__repr__(), "result=", r.__repr__(), sep='')
        assert _cleaned_body(r) == result
Exemple #5
0
def test_breaking_title():
    # xml-styled <title/> breaks html rendering, we should remove it (#43)
    assert '<title/>' not in HTMLParser(html="<title></title>").to_string()