#!/usr/bin/env python
# coding: utf-8
"""
html2creole tests
~~~~~~~~~~~~~~~~~
special html to creole convert tests, witch can't tests in "cross compare"
:copyleft: 2008-2011 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
import unittest
from creole import html2creole
from creole.shared.unknown_tags import (
escape_unknown_nodes,
raise_unknown_node,
transparent_unknown_nodes,
use_html_macro,
)
from creole.tests.utils.base_unittest import BaseCreoleTest
class TestHtml2Creole(unittest.TestCase):
"""
Tests around html2creole API.
"""
pass
class TestHtml2CreoleMarkup(BaseCreoleTest):
# def assertCreole(self, raw_markup, raw_html, debug=False, **kwargs):
# self.assert_html2creole(raw_markup, raw_html, debug=debug, **kwargs)
# --------------------------------------------------------------------------
def test_not_used(self):
"""
Some other html tags -> convert.
"""
self.assert_html2creole(r"""
**Bold text**
**Big text**
//em tag//
//italic//
""", """
Bold text
Big text em tag italic
""")
# --------------------------------------------------------------------------
def test_raise_unknown_node(self):
"""
Test creole.html2creole.raise_unknown_node callable:
Raise NotImplementedError on unknown tags.
"""
self.assertRaises(NotImplementedError,
html2creole,
html_string="",
unknown_emit=raise_unknown_node
)
def test_use_html_macro(self):
"""
Test creole.html2creole.use_html_macro callable:
Use the <> macro to mask unknown tags.
"""
self.assert_html2creole(r"""
111 <><>foo<><> 222
333<><>foobar<><>444
555<><>666
""", """
111 foo 222
333foobar444
555666
""",
unknown_emit=use_html_macro
)
def test_escape_unknown_nodes(self):
"""
Test creole.html2creole.escape_unknown_nodes callable:
All unknown tags should be escaped.
"""
self.assert_html2creole(r"""
111 <unknown>foo</unknown> 222
333<unknown foo1="bar1" foo2="bar2">foobar</unknown>444
555<unknown />666
""", """
111 foo 222
333foobar444
555666
""",
unknown_emit=escape_unknown_nodes
)
def test_escape_unknown_nodes2(self):
"""
HTMLParser has problems with
""",
unknown_emit=escape_unknown_nodes
)
def test_transparent_unknown_nodes(self):
"""
Test creole.html2creole.transparent_unknown_nodes callable:
All unknown tags should be "transparent" and show only
their child nodes' content.
"""
self.assert_html2creole(r"""
//baz//, **quux**
""", """
""", unknown_emit=transparent_unknown_nodes
)
def test_transparent_unknown_nodes2(self):
"""
HTMLParser has problems with BAR
""", unknown_emit=transparent_unknown_nodes
)
def test_transparent_unknown_nodes_block_elements(self):
"""
Test that block elements insert linefeeds into the stream.
"""
self.assert_html2creole(r"""
//baz//,
**quux**
spam, ham, and eggs
""", """
""")
def test_html_entity_nbsp(self):
""" Non breaking spaces is not in htmlentitydefs """
self.assert_html2creole(r"""
a non braking space: [ ] !
""", """