diff options
Diffstat (limited to 'creole/tests/test_creole2html.py')
-rw-r--r-- | creole/tests/test_creole2html.py | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/creole/tests/test_creole2html.py b/creole/tests/test_creole2html.py index 9a88e44..45e73dd 100644 --- a/creole/tests/test_creole2html.py +++ b/creole/tests/test_creole2html.py @@ -4,9 +4,9 @@ """ creole2html unittest ~~~~~~~~~~~~~~~~~~~~ - + Here are only some tests witch doesn't work in the cross compare tests. - + Info: There exist some situations with different whitespace handling between creol2html and html2creole. @@ -28,6 +28,7 @@ except ImportError: from creole.tests.utils.base_unittest import BaseCreoleTest from creole.tests import test_macros +from creole.py3compat import PY3 from creole import creole2html from creole.shared import example_macros @@ -57,12 +58,20 @@ class TestCreole2html(unittest.TestCase): error_msg = my_stderr.getvalue() # Check if we get a traceback information into our stderr handler - must_have = ( - "Traceback", - "AttributeError:", - "has no attribute 'notexist1'", - "has no attribute 'notexist2'", - ) + if PY3: + must_have = ( + "Traceback", + "KeyError:", + "KeyError: 'notexist1'", + "KeyError: 'notexist2'", + ) + else: + must_have = ( + "Traceback", + "KeyError:", + "KeyError: u'notexist1'", + "KeyError: u'notexist2'", + ) for part in must_have: self.assertIn(part, error_msg) @@ -194,7 +203,6 @@ class TestCreole2html(unittest.TestCase): - class TestCreole2htmlMarkup(BaseCreoleTest): def test_creole_basic(self): @@ -226,16 +234,16 @@ class TestCreole2htmlMarkup(BaseCreoleTest): self.assert_creole2html(r""" This is a normal Text block witch would escape html chars like < and > ;) - + So you can't insert <html> directly. - + <p>This escaped, too.</p> """, """ <p>This is a normal Text block witch would<br /> escape html chars like < and > ;)</p> - + <p>So you can't insert <html> directly.</p> - + <p><p>This escaped, too.</p></p> """) @@ -258,20 +266,20 @@ class TestCreole2htmlMarkup(BaseCreoleTest): self.assert_creole2html(r""" Bold and italics should //not be... - ...able// to **cross - + ...able// to **cross + paragraphs.** """, """ <p>Bold and italics should //not be...</p> - + <p>...able// to **cross</p> - + <p>paragraphs.**</p> """) def test_list_special(self): """ - optional whitespace before the list + optional whitespace before the list """ self.assert_creole2html(r""" * Item 1 @@ -279,7 +287,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): ** Item 1.2 ** Item 1.3 * Item2 - + # one ## two """, """ @@ -309,7 +317,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): A <<test_macro1 args="foo1">>bar1<</test_macro1>> in a line... ...a single <<test_macro1 foo="bar">> tag, or: <<test_macro1 a=1 b=2 />> closed... - + a macro block: <<test_macro2 char="|">> the @@ -321,7 +329,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): A [test macro1 - kwargs: args='foo1',text='bar1'] in a line...<br /> ...a single [test macro1 - kwargs: foo='bar',text=None] tag,<br /> or: [test macro1 - kwargs: a=1,b=2,text=None] closed...</p> - + <p>a macro block:</p> the|text <p>the end</p> @@ -335,12 +343,12 @@ class TestCreole2htmlMarkup(BaseCreoleTest): <<html>> <p><<this is broken 'html', but it will be pass throu>></p> <</html>> - + inline: <<html>>{...}<</html>> code """, r""" <p>html macro:</p> <p><<this is broken 'html', but it will be pass throu>></p> - + <p>inline: {...} code</p> """, macros=example_macros, @@ -350,7 +358,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): """ not existing macro with creole2html.HtmlEmitter(verbose=1): A error message should be insertet into the generated code - + Two tests: with verbose=1 and verbose=2, witch write a Traceback information to a given "stderr" """ @@ -359,14 +367,14 @@ class TestCreole2htmlMarkup(BaseCreoleTest): <<notexists>> foo bar <</notexists>> - + inline macro: <<notexisttoo foo="bar">> """ should_string = r""" <p>macro block:</p> [Error: Macro 'notexists' doesn't exist] - + <p>inline macro:<br /> [Error: Macro 'notexisttoo' doesn't exist] </p> @@ -391,7 +399,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): def test_macro_not_exist2(self): """ not existing macro with creole2html.HtmlEmitter(verbose=0): - + No error messages should be inserted. """ self.assert_creole2html(r""" @@ -399,17 +407,27 @@ class TestCreole2htmlMarkup(BaseCreoleTest): <<notexists>> foo bar <</notexists>> - + inline macro: <<notexisttoo foo="bar">> """, r""" <p>macro block:</p> - + <p>inline macro:<br /> </p> """, verbose=False ) + + def test_toc(self): + """ + Simple test to check the table of content is correctly generated. + """ + html = creole2html("""<<toc>>\n= Creole""") + self.assertEqual(html, + """<ul><li><a href="#Creole">Creole</a> </li>\n</ul>\n\n<a name="Creole"><h1>Creole</h1>\n</a>""") + + def test_image(self): """ test image tag with different picture text """ self.assert_creole2html(r""" @@ -446,7 +464,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): def test_standalone_hyperlink(self): self.assert_creole2html(r""" - a link to the http://www.pylucid.org page. + a link to the http://www.pylucid.org page. """, """ <p>a link to the <a href="http://www.pylucid.org">http://www.pylucid.org</a> page.</p> """ @@ -457,14 +475,14 @@ class TestCreole2htmlMarkup(BaseCreoleTest): markup_string=self._prepare_text(""" wiki style linebreaks - + ...and not blog styled. """), parser_kwargs={"blog_line_breaks":False}, ) self.assertEqual(html, self._prepare_text(""" <p>wiki style linebreaks</p> - + <p>...and not blog styled.</p> """)) @@ -473,7 +491,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): markup_string=self._prepare_text(""" **one** //two// - + * one * two """), @@ -481,7 +499,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): ) self.assertEqual(html, self._prepare_text(""" <p><strong>one</strong> <i>two</i></p> - + <ul> \t<li>one</li> \t<li>two</li> @@ -493,29 +511,29 @@ class TestCreole2htmlMarkup(BaseCreoleTest): markup_string=self._prepare_text(""" with blog line breaks, every line break would be convertet into<br /> with wiki style not. - + This is the first line,\\\\and this is the second. - + new line block 1 - + new line block 2 - + end """), parser_kwargs={"blog_line_breaks":False}, ) self.assertEqual(html, self._prepare_text(""" <p>with blog line breaks, every line break would be convertet into<br /> with wiki style not.</p> - + <p>This is the first line,<br /> and this is the second.</p> - + <p>new line block 1</p> - + <p>new line block 2</p> - + <p>end</p> """)) |