#!/usr/bin/env python # coding: utf-8 """ cross compare unittest ~~~~~~~~~~~~~~~~~~~~~~ Compare all similarities between: * creole2html * html2creole * textile2html (used the python textile module) * html2textile Note: This only works fine if there is no problematic whitespace handling. In this case, we must test in test_creole2html.py or test_html2creole.py :copyleft: 2008-2014 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ import unittest from creole.tests.utils.base_unittest import BaseCreoleTest class CrossCompareTests(BaseCreoleTest): """ Cross compare tests for creol2html _and_ html2creole with the same test strings. Used BaseCreoleTest.assertCreole() """ def test_bold_italics(self): self.cross_compare( creole_string=r""" **bold** //italics// //italics and **bold**.// **bold and //italics//.** """, html_string="""

bold italics
italics and bold.
bold and italics.

""", ) self.cross_compare( textile_string=""" *bold* __italics__ __italics and *bold*.__ *bold and __italics__.* """, html_string="""

bold italics
italics and bold.
bold and italics.

""", ) # Note: In ReSt inline markup may not be nested. self.cross_compare( html_string="""

bold italics

""", rest_string=""" **bold** *italics* """, ) def test_bold_italics2(self): self.cross_compare( creole_string=r""" **//bold italics//** //**bold italics**// //This is **also** good.// """, html_string="""

bold italics
bold italics
This is also good.

""", ) self.cross_compare( textile_string=""" *__bold italics__* __*bold italics*__ __This is *also* good.__ """, html_string="""

bold italics
bold italics
This is also good.

""", ) def test_headlines1(self): self.cross_compare( creole_string=r""" = Section Title 1 == Section Title 2 === Section Title 3 ==== Section Title 4 ===== Section Title 5 ====== Section Title 6 """, textile_string=""" h1. Section Title 1 h2. Section Title 2 h3. Section Title 3 h4. Section Title 4 h5. Section Title 5 h6. Section Title 6 """, html_string="""

Section Title 1

Section Title 2

Section Title 3

Section Title 4

Section Title 5
Section Title 6
""" ) self.cross_compare( rest_string=""" =============== Section Title 1 =============== --------------- Section Title 2 --------------- Section Title 3 =============== Section Title 4 --------------- Section Title 5 ``````````````` Section Title 6 ''''''''''''''' """, html_string="""

Section Title 1

Section Title 2

Section Title 3

Section Title 4

Section Title 5
Section Title 6
""" ) def test_horizontal_rule(self): all_markups = """ Text before horizontal rule. ---- Text after the line. """ self.cross_compare( creole_string=all_markups, # textile_string=all_markups, # FIXME: textile and
? html_string="""

Text before horizontal rule.


Text after the line.

""" ) self.cross_compare( rest_string=all_markups, html_string="""

Text before horizontal rule.


Text after the line.

""" ) def test_link(self): self.cross_compare( creole_string=r""" X [[http://domain.tld|link B]] test. """, textile_string=""" X "link B":http://domain.tld test. """, rest_string=""" X `link B `_ test. """, html_string="""

X link B test.

""" ) def test_link_without_title(self): self.cross_compare( creole_string=r""" [[http://www.pylucid.org]] """, textile_string=""" "http://www.pylucid.org":http://www.pylucid.org """, rest_string=""" `http://www.pylucid.org `_ """, html_string="""

http://www.pylucid.org

""" ) def test_link_with_unknown_protocol(self): self.cross_compare( creole_string=r""" X [[foo://bar|unknown protocol]] Y """, # textile will return '#' if url scheme is unknown! # textile_string=""" # X "unknown protocol":foo://bar Y # """, rest_string=""" X `unknown protocol `_ Y """, html_string="""

X unknown protocol Y

""" ) def test_link_with_at_sign(self): self.cross_compare( creole_string=r""" X [[http://de.wikipedia.org/wiki/Creole_(Markup)|Creole@wikipedia]] """, html_string="""

X Creole@wikipedia

""" ) self.cross_compare( rest_string=""" X `Creole@wikipedia `_ """, html_string="""

X Creole@wikipedia

""" ) self.cross_compare_textile( textile_string=""" X "foo@domain":http://domain.tld """, html_string="""

X foo@domain

""" ) def test_image(self): self.cross_compare( creole_string=r""" a {{/image.jpg|JPG pictures}} and a {{/image.jpeg|JPEG pictures}} and a {{/image.gif|GIF pictures}} and a {{/image.png|PNG pictures}} ! {{/path1/path2/image|Image without files ext?}} """, html_string="""

a JPG pictures and
a JPEG pictures and
a GIF pictures and
a PNG pictures !
Image without files ext?

""" ) self.cross_compare( textile_string=""" a !/image.jpg(JPG pictures)! and a !/image.jpeg(JPEG pictures)! and a !/image.gif(GIF pictures)! and a !/image.png(PNG pictures)! ! !/path1/path2/image(Image without files ext?)! """, html_string="""

a JPG pictures and
a JPEG pictures and
a GIF pictures and
a PNG pictures !
Image without files ext?

""" ) self.cross_compare( rest_string=""" 1 |JPG pictures| one .. |JPG pictures| image:: /image.jpg 2 |JPEG pictures| two .. |JPEG pictures| image:: /image.jpeg 3 |GIF pictures| tree .. |GIF pictures| image:: /image.gif 4 |PNG pictures| four .. |PNG pictures| image:: /image.png 5 |Image without files ext?| five .. |Image without files ext?| image:: /path1/path2/image """, html_string="""

1 JPG pictures one

2 JPEG pictures two

3 GIF pictures tree

4 PNG pictures four

5 Image without files ext? five

""" ) def test_link_image(self): """ FIXME: ReSt. and linked images """ self.cross_compare( creole_string=r""" Linked [[http://example.com/|{{myimage.jpg|example site}} image]] """, html_string="""

Linked example site image

""" ) self.cross_compare( textile_string=""" Linked "!myimage.jpg(example site)! image":http://example.com/ """, html_string="""

Linked example site image

""" ) # self.cross_compare(# FIXME: ReSt # rest_string=""" # I recommend you try |PyLucid CMS|_. # # .. |PyLucid CMS| image:: /images/pylucid.png # .. _PyLucid CMS: http://www.pylucid.org/ # """, # html_string=""" #

I recommend you try PyLucid CMS.

# """ # ) def test_pre1(self): self.cross_compare( creole_string=r""" {{{ * no list }}} """, textile_string="""
                * no list
                
""", html_string="""
                * no list
                
""") self.cross_compare( # FIXME: Not the best html2rest output rest_string=""" Preformatting text: :: Here some performatting with no `link `_ here. text... end. Under pre block """, html_string="""

Preformatting text:

                Here some performatting with
                no `link <http://domain.tld>`_ here.
                text... end.
                

Under pre block

""" ) # def test_pre2(self): # """ TODO: html2creole: wrong lineendings """ # self.cross_compare( # creole_string=r""" # start # # {{{ # * no list # }}} # # end # """, # textile_string=""" # start # #
#                * no list
#                
# # end # """, # html_string=""" #

start

# #
#                * no list
#                
# #

end

# """) def test_pre_contains_braces(self): self.cross_compare( creole_string=""" {{{ # Closing braces in nowiki: if (x != NULL) { for (i = 0) { if (x = 1) { x[i]--; }}} }}} """, textile_string="""
                # Closing braces in nowiki:
                if (x != NULL) {
                  for (i = 0) {
                    if (x = 1) {
                      x[i]--;
                  }}}
                
""", rest_string=""" :: # Closing braces in nowiki: if (x != NULL) { for (i = 0) { if (x = 1) { x[i]--; }}} """, html_string="""
                # Closing braces in nowiki:
                if (x != NULL) {
                  for (i = 0) {
                    if (x = 1) {
                      x[i]--;
                  }}}
                
""") def test_list(self): """ Bold, Italics, Links, Pre in Lists """ self.cross_compare( creole_string=r""" * **bold** item * //italic// item # item about a [[/foo/bar|certain_page]] """, textile_string=""" * *bold* item * __italic__ item # item about a "certain_page":/foo/bar """, html_string="""
  • bold item
  • italic item
  1. item about a certain_page
""", strip_lines=True ) def test_simple_table(self): self.cross_compare( creole_string=""" |= Headline 1 |= Headline 2 | | cell one | cell two | """, textile_string=""" |_. Headline 1|_. Headline 2| |cell one|cell two| """, html_string="""
Headline 1 Headline 2
cell one cell two
""", # debug=True strip_lines=True, ) self.cross_compare( rest_string=""" +------------+------------+ | Headline 1 | Headline 2 | +============+============+ | cell one | cell two | +------------+------------+ """, html_string="""
Headline 1 Headline 2
cell one cell two
""", # debug=True ) if __name__ == '__main__': unittest.main()