#!/usr/bin/env python # coding: utf-8 """ html2rest unittest ~~~~~~~~~~~~~~~~~~~~~ Unittests for special cases which only works in the html2rest way. Note: This only works fine if there is no problematic whitespace handling. :copyleft: 2011-2012 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ import unittest from creole.emitter.html2rest_emitter import Html2restException from creole.tests.utils.base_unittest import BaseCreoleTest class ReStTests(BaseCreoleTest): def test_line_breaks(self): """ Line breaks in HTML are lost. """ self.assert_html2rest( rest_string=""" first block, line 1 and line 2 second block, line 1 and line 2 """, html_string="""

first block, line 1 and line 2

second block, line 1 and line 2

""", # debug=True ) def test_substitution_image_without_alt_or_title(self): self.assert_html2rest( rest_string=""" A inline |image.png| image. .. |image.png| image:: /url/to/image.png ...and some text below. """, html_string="""

A inline image.

...and some text below.

""" ) def test_substitution_image_with_title(self): self.assert_html2rest( rest_string=""" A inline |foo bar| image. .. |foo bar| image:: /url/to/image.png ...and some text below. """, html_string="""

A inline image.

...and some text below.

""" ) def test_substitution_image_without_p(self): self.assert_html2rest( rest_string=""" |image.png| .. |image.png| image:: /url/to/image.png """, html_string=""" """ ) def test_pre_code1(self): self.assert_html2rest( rest_string=""" Text line :: >>> from creole import creole2html >>> creole2html("This is **creole //markup//**") '

This is creole markup

' """, html_string="""

Text line

                >>> from creole import creole2html
                >>> creole2html("This is **creole //markup//**")
                '<p>This is <strong>creole <i>markup</i></strong></p>'
                
""" ) def test_escape(self): self.assert_html2rest( rest_string=""" * Use when {{{ ... }}} is inline and not
, or not?
            """,
            html_string="""
                
            """
        )

    def test_inline_literals(self):
        self.assert_html2rest(
            rest_string="""
                This text is an example of ``inline literals``.
            """,
            html_string="""
                
            """
        )

    def test_list_without_p(self):
        self.assert_html2rest(
            rest_string="""
                A nested bullet lists:

                * item 1 without p-tag

                    * A **`subitem 1.1 `_ link** here.

                        * subsubitem 1.1.1

                        * subsubitem 1.1.2

                    * subitem 1.2

                * item 2 without p-tag

                    * subitem 2.1

                Text under list.
            """,
            html_string="""
                

A nested bullet lists:

Text under list.

""" ) def test_table_with_headings(self): self.assert_html2rest( rest_string=""" +--------+--------+ | head 1 | head 2 | +========+========+ | item 1 | item 2 | +--------+--------+ """, html_string="""
head 1head 2
item 1item 2
""" ) def test_table_without_headings(self): self.assert_html2rest( rest_string=""" +--------+--------+ | item 1 | item 2 | +--------+--------+ | item 3 | item 4 | +--------+--------+ """, html_string="""
item 1item 2
item 3item 4
""" ) def test_duplicate_substitution1(self): self.assertRaises(Html2restException, self.assert_html2rest, rest_string=""" +-----------------------------+ | this is `same`_ first time. | +-----------------------------+ .. _same: /first/ the `same `_ link? """, html_string="""
the same first time.

the same link?

""", # debug=True ) def test_duplicate_link_substitution(self): self.assertRaises(Html2restException, self.assert_html2rest, # self.cross_compare( rest_string=""" +-----------------------------+ | this is `same`_ first time. | +-----------------------------+ .. _same: /first/ the `same `_ link? """, html_string="""
the same first time.

the same link?

""", # debug=True ) def test_duplicate_image_substitution(self): self.assertRaises(Html2restException, self.assert_html2rest, # self.cross_compare( rest_string=""" a |image|... and a other |image|! .. |image| image:: /image.png .. |image| image:: /other.png """, html_string="""

a image...
and a other image!

""", # debug=True ) # def test_preformat_unknown_nodes(self): # """ # Put unknown tags in a
 area.
#        """
#        self.assert_html2rest(
#            rest_string="""
#                111 <
><
>foo<
><
> 222 # 333<
><
>foobar<
><
>444 # # 555<
><
>666 # """, # html_string=""" #

111 foo 222
# 333foobar444

# #

555666

# """, # emitter_kwargs={"unknown_emit":preformat_unknown_nodes} # ) # # def test_transparent_unknown_nodes(self): # """ # transparent_unknown_nodes is the default unknown_emit: # # Remove all unknown html tags and show only # their child nodes' content. # """ # self.assert_html2rest( # rest_string=""" # 111 <
><
>foo<
><
> 222 # 333<
><
>foobar<
><
>444 # # 555<
><
>666 # """, # html_string=""" #

111 foo 222
# 333foobar444

# #

555666

# """, # ) if __name__ == '__main__': unittest.main()