Skip to content

Commit

Permalink
For converter tests, align input and expected output below each other…
Browse files Browse the repository at this point in the history
… for clarity. Use single quotes unless single quotes are part of the string literals.
  • Loading branch information
JanHoefelmeyer committed Apr 13, 2023
1 parent e516641 commit a14ef02
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 308 deletions.
68 changes: 49 additions & 19 deletions src/moin/converters/_tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ def conv():
@pytest.mark.parametrize(
'input_,output',
(
('wiki:///Test', '/Test'),
('wiki:///Test:colon', '/Test:colon'),
('wiki:///Test?mode=raw', '/Test?mode=raw'),
('wiki:///Test#anchor', '/Test#anchor'),
('wiki:///Test?mode=raw#anchor', '/Test?mode=raw#anchor'),
('wiki://MoinMoin/Test', 'http://moinmo.in/Test'),
('wiki:///Test',
'/Test'),
('wiki:///Test:colon',
'/Test:colon'),
('wiki:///Test?mode=raw',
'/Test?mode=raw'),
('wiki:///Test#anchor',
'/Test#anchor'),
('wiki:///Test?mode=raw#anchor',
'/Test?mode=raw#anchor'),
('wiki://MoinMoin/Test',
'http://moinmo.in/Test'),
),
)
def test_wiki(app, conv, input_, output):
Expand All @@ -41,18 +47,40 @@ def test_wiki(app, conv, input_, output):
'input_,page,output',
(
# note: result URLs assume test wiki running at /
('wiki.local:', 'wiki:///Root', '/Root'),
('wiki.local:Test', 'wiki:///Root', '/Test'),
('wiki.local:Test:colon', 'wiki:///Root', '/Test:colon'),
('wiki.local:users/Test:colon', 'wiki:///Root', '/users/Test:colon'),
('wiki.local:users:ns/Test:colon', 'wiki:///Root', '/users:ns/Test:colon'),
('wiki.local:Test', 'wiki:///Root/Sub', '/Test'),
('wiki.local:/Test', 'wiki:///Root', '/Root/Test'),
('wiki.local:/Test', 'wiki:///Root/Sub', '/Root/Sub/Test'),
('wiki.local:../Test', 'wiki:///Root', '/Test'),
('wiki.local:../Test', 'wiki:///Root/Sub', '/Root/Test'),
('wiki.local:',
'wiki:///Root',
'/Root'),
('wiki.local:Test',
'wiki:///Root',
'/Test'),
('wiki.local:Test:colon',
'wiki:///Root',
'/Test:colon'),
('wiki.local:users/Test:colon',
'wiki:///Root',
'/users/Test:colon'),
('wiki.local:users:ns/Test:colon',
'wiki:///Root',
'/users:ns/Test:colon'),
('wiki.local:Test',
'wiki:///Root/Sub',
'/Test'),
('wiki.local:/Test',
'wiki:///Root',
'/Root/Test'),
('wiki.local:/Test',
'wiki:///Root/Sub',
'/Root/Sub/Test'),
('wiki.local:../Test',
'wiki:///Root',
'/Test'),
('wiki.local:../Test',
'wiki:///Root/Sub',
'/Root/Test'),
# this is a local wiki item with a name happening to have a ":' inside:
('wiki.local:NoInterWiki:Item', 'wiki:///Root', '/NoInterWiki:Item'),
('wiki.local:NoInterWiki:Item',
'wiki:///Root',
'/NoInterWiki:Item'),
)
)
def test_wikilocal(conv, input_, page, output):
Expand All @@ -64,8 +92,10 @@ def test_wikilocal(conv, input_, page, output):
@pytest.mark.parametrize(
'input_,output',
(
('http://moinmo.in/', 'http://moinmo.in/'),
('mailto:[email protected]', 'mailto:[email protected]'),
('http://moinmo.in/',
'http://moinmo.in/'),
('mailto:[email protected]',
'mailto:[email protected]'),
)
)
def test_wikiexternal(conv, input_, output):
Expand Down
68 changes: 40 additions & 28 deletions src/moin/converters/_tests/test_mediawiki_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,35 @@ def setup_class(self):
self.conv = Converter()

data = [
("''italic''", '<page><body><p><emphasis>italic</emphasis></p></body></page>'),
("Text\nTest", '<page><body><p>Text\nTest</p></body></page>'),
('Text\n\nTest', '<page><body><p>Text</p><p>Test</p></body></page>'),
("'''bold'''", '<page><body><p><strong>bold</strong></p></body></page>'),
("''italic''",
'<page><body><p><emphasis>italic</emphasis></p></body></page>'),
("Text\nTest",
'<page><body><p>Text\nTest</p></body></page>'),
('Text\n\nTest',
'<page><body><p>Text</p><p>Test</p></body></page>'),
("'''bold'''",
'<page><body><p><strong>bold</strong></p></body></page>'),
("'''''bold and italic'''''",
'<page><body><p><strong><emphasis>bold and italic</emphasis></strong></p></body></page>'),
("<nowiki>no ''markup''</nowiki>\n\n<code>no ''markup''</code>\n\n<tt>no ''markup''</tt>",
"<page><body><p><code>no ''markup''</code></p><p><code>no ''markup''</code></p><p><code>no ''markup''</code></p></body></page>"),
("<pre>no ''markup'' block</pre>",
"<page><body><p><blockcode>no ''markup'' block</blockcode></p></body></page>"),
('<u>underlined</u>', '<page><body><p><u>underlined</u></p></body></page>'),
('<ins>inserted</ins>', '<page><body><p><ins>inserted</ins></p></body></page>'),
('<del>Strikethrough</del>', '<page><body><p><del>Strikethrough</del></p></body></page>'),
('<s>Strikethrough</s>', '<page><body><p><s>Strikethrough</s></p></body></page>'),
("test <sup>super</sup> or <sub>sub</sub>",
('<u>underlined</u>',
'<page><body><p><u>underlined</u></p></body></page>'),
('<ins>inserted</ins>',
'<page><body><p><ins>inserted</ins></p></body></page>'),
('<del>Strikethrough</del>',
'<page><body><p><del>Strikethrough</del></p></body></page>'),
('<s>Strikethrough</s>',
'<page><body><p><s>Strikethrough</s></p></body></page>'),
('test <sup>super</sup> or <sub>sub</sub>',
'<page><body><p>test <span baseline-shift="super">super</span> or <span baseline-shift="sub">sub</span></p></body></page>'),
("text <blockquote> quote quote quote quote quote quote </blockquote> text",
"<page><body><p>text <blockquote> quote quote quote quote quote quote </blockquote> text</p></body></page>"),
("aaa<br />bbb", "<page><body><p>aaa<line-break />bbb</p></body></page>"),
("aaa <ref> sdf </ref> test\n\n asd",
('text <blockquote> quote quote quote quote quote quote </blockquote> text',
'<page><body><p>text <blockquote> quote quote quote quote quote quote </blockquote> text</p></body></page>'),
('aaa<br />bbb',
'<page><body><p>aaa<line-break />bbb</p></body></page>'),
('aaa <ref> sdf </ref> test\n\n asd',
'<page><body><p>aaa <note note-class="footnote"><note-body> sdf </note-body></note> test</p><p> asd</p></body></page>'),
("""=level 1=
== level 2 ==
Expand All @@ -55,7 +64,8 @@ def setup_class(self):
======level 6======
""",
'<page><body><h outline-level="1">level 1</h><h outline-level="2">level 2</h><h outline-level="3">level 3</h><h outline-level="4">level 4</h><h outline-level="5">level 5</h><h outline-level="6">level 6</h></body></page>'),
("[javascript:alert('xss')]", "<page><body><p>[javascript:alert('xss')]</p></body></page>"),
("[javascript:alert('xss')]",
"<page><body><p>[javascript:alert('xss')]</p></body></page>"),
]

@pytest.mark.parametrize('input,output', data)
Expand Down Expand Up @@ -98,8 +108,8 @@ def test_base(self, input, output):
# TODO add a test for a definition list with term and definition on separate lines like:
# ; term
# : definition
(";aaa : bbb",
"<page><body><list><list-item><list-item-label>aaa </list-item-label><list-item-body><p> bbb</p></list-item-body></list-item></list></body></page>"),
(';aaa : bbb',
'<page><body><list><list-item><list-item-label>aaa </list-item-label><list-item-body><p> bbb</p></list-item-body></list-item></list></body></page>'),
(""": Single indent
:: Double indent
::::: Multiple indent
Expand Down Expand Up @@ -131,7 +141,7 @@ def test_list(self, input, output):
|Ice cream
|}
""",
"<page><body><table><table-body><table-row><table-cell>Orange</table-cell><table-cell>Apple</table-cell></table-row><table-row><table-cell>Bread</table-cell><table-cell>Pie</table-cell></table-row><table-row><table-cell>Butter</table-cell><table-cell>Ice cream</table-cell></table-row></table-body></table></body></page>"),
'<page><body><table><table-body><table-row><table-cell>Orange</table-cell><table-cell>Apple</table-cell></table-row><table-row><table-cell>Bread</table-cell><table-cell>Pie</table-cell></table-row><table-row><table-cell>Butter</table-cell><table-cell>Ice cream</table-cell></table-row></table-body></table></body></page>'),
("""{|style="border-width: 1px;"
|style="border-style: solid; border-width: 1px" colspan="2"| Orange
Apple
Expand All @@ -155,31 +165,33 @@ def test_table(self, input, output):
self.do(input, output)

data = [
("[[SomeLink]]", '<page><body><p><a xlink:href="wiki.local:SomeLink">SomeLink</a></p></body></page>'),
("[http://external.link]", '<page><body><p><a xlink:href="http://external.link"></a></p></body></page>'),
("[http://external.link alt text]",
('[[SomeLink]]',
'<page><body><p><a xlink:href="wiki.local:SomeLink">SomeLink</a></p></body></page>'),
('[http://external.link]',
'<page><body><p><a xlink:href="http://external.link"></a></p></body></page>'),
('[http://external.link alt text]',
'<page><body><p><a xlink:href="http://external.link">alt text</a></p></body></page>'),
("[[SomeLink|Some text]]",
('[[SomeLink|Some text]]',
'<page><body><p><a xlink:href="wiki.local:SomeLink">Some text</a></p></body></page>'),
("[[SomeLink|arg1=value|arg2=otherval|Some text]]",
('[[SomeLink|arg1=value|arg2=otherval|Some text]]',
'<page><body><p><a xlink:href="wiki.local:SomeLink?arg1=value&amp;arg2=otherval">Some text</a></p></body></page>'),
("[[File:Test.jpg|test]]",
('[[File:Test.jpg|test]]',
'<page><body><p><object alt="test" xlink:href="wiki.local:Test.jpg?do=get">test</object></p></body></page>'),
("[[File:MyImage.png]]",
('[[File:MyImage.png]]',
'<page><body><p><object alt="MyImage.png" xlink:href="wiki.local:MyImage.png?do=get">MyImage.png</object></p></body></page>'),
("[[File:MyImage.png|arg=http://google.com|caption]]",
('[[File:MyImage.png|arg=http://google.com|caption]]',
'<page><body><p><object alt="caption" xlink:href="wiki.local:MyImage.png?arg=http%253A%252F%252Fgoogle.com&amp;do=get">caption</object></p></body></page>'),
("[[File:Test.png|do=get|arg1=test|arg2=something else]]",
('[[File:Test.png|do=get|arg1=test|arg2=something else]]',
'<page><body><p><object alt="Test.png" xlink:href="wiki.local:Test.png?arg1=test&amp;arg2=something+else&amp;do=get">Test.png</object></p></body></page>'),
# The do=xxx part is just to test if do in args is being updated correctly, it's invalid otherwise
("[[File:Test2.png|do=xxx|caption|arg1=test]]",
('[[File:Test2.png|do=xxx|caption|arg1=test]]',
'<page><body><p><object alt="caption" xlink:href="wiki.local:Test2.png?arg1=test&amp;do=xxx">caption</object></p></body></page>'),
("[[File:myimg.png|'Graph showing width |= k for 5 < k < 10']]",
'<page><body><p><object alt="Graph showing width |= k for 5 &lt; k &lt; 10" xlink:href="wiki.local:myimg.png?do=get">Graph showing width |= k for 5 &lt; k &lt; 10</object></p></body></page>'),
("[[File:myimg.png|arg1='longish caption value with |= to test'|arg2=other|test stuff]]",
'<page><body><p><object alt="test stuff" xlink:href="wiki.local:myimg.png?arg1=longish+caption+value+with+%257C%253D+to+test&amp;arg2=other&amp;do=get">test stuff</object></p></body></page>'),
# Unicode test
("[[File:Test.jpg|\xe8]]",
('[[File:Test.jpg|\xe8]]',
'<page><body><p><object alt="\xe8" xlink:href="wiki.local:Test.jpg?do=get">\xe8</object></p></body></page>')
]

Expand Down
42 changes: 21 additions & 21 deletions src/moin/converters/_tests/test_moinwiki_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@ def test_heading(self, input, output):
self.do(input, output)

data = [
("__underline__",
('__underline__',
'<page><body><p><ins>underline</ins></p></body></page>'),
(",,sub,,script",
(',,sub,,script',
'<page><body><p><span baseline-shift="sub">sub</span>script</p></body></page>'),
("^super^script",
('^super^script',
'<page><body><p><span baseline-shift="super">super</span>script</p></body></page>'),
("~-smaller-~",
('~-smaller-~',
'<page><body><p><span font-size="85%">smaller</span></p></body></page>'),
("~+larger+~",
('~+larger+~',
'<page><body><p><span font-size="120%">larger</span></p></body></page>'),
("--(strike through)--",
('--(strike through)--',
'<page><body><p><del>strike through</del></p></body></page>'),
("normal ~+big __underline__ big+~ normal",
('normal ~+big __underline__ big+~ normal',
'<page><body><p>normal <span font-size="120%">big <ins>underline</ins> big</span> normal</p></body></page>'),
("/* normal __underline__ normal */",
('/* normal __underline__ normal */',
'<page><body><p><span class="comment">normal <ins>underline</ins> normal</span></p></body></page>'),
('&quot;',
'<page><body><p>"</p></body></page>'),
Expand Down Expand Up @@ -349,36 +349,36 @@ def test_nowiki(self, input, output):

data = [
('{{{#!wiki\nwiki\n}}}',
"<page><body><nowiki>3<nowiki-args>#!wiki</nowiki-args>wiki</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!wiki</nowiki-args>wiki</nowiki></body></page>'),
('{{{{{#!wiki\nwiki\n}}}}}',
"<page><body><nowiki>5<nowiki-args>#!wiki</nowiki-args>wiki</nowiki></body></page>"),
'<page><body><nowiki>5<nowiki-args>#!wiki</nowiki-args>wiki</nowiki></body></page>'),
('{{{#!wiki(style="background-color: red")\nwiki\n}}}',
'<page><body><nowiki>3<nowiki-args>#!wiki(style="background-color: red")</nowiki-args>wiki</nowiki></body></page>'),
('{{{#!highlight python\nimport os\n}}}',
"<page><body><nowiki>3<nowiki-args>#!highlight python</nowiki-args>import os</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!highlight python</nowiki-args>import os</nowiki></body></page>'),
('{{{#!python\nimport os\n}}}',
"<page><body><nowiki>3<nowiki-args>#!python</nowiki-args>import os</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!python</nowiki-args>import os</nowiki></body></page>'),
('{{{#!csv\na;b;c\nd;e;22\n}}}',
"<page><body><nowiki>3<nowiki-args>#!csv</nowiki-args>a;b;c\nd;e;22</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!csv</nowiki-args>a;b;c\nd;e;22</nowiki></body></page>'),
('{{{#!csv ,\na,b,c\nd,e,22\n}}}',
"<page><body><nowiki>3<nowiki-args>#!csv ,</nowiki-args>a,b,c\nd,e,22</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!csv ,</nowiki-args>a,b,c\nd,e,22</nowiki></body></page>'),
# TODO: Backward compatibility
('{{{#!wiki red/solid\nwiki\n}}}',
"<page><body><nowiki>3<nowiki-args>#!wiki red/solid</nowiki-args>wiki</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!wiki red/solid</nowiki-args>wiki</nowiki></body></page>'),
('{{{#!wiki red/solid\nwiki\n\nwiki\n}}}',
"<page><body><nowiki>3<nowiki-args>#!wiki red/solid</nowiki-args>wiki\n\nwiki</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!wiki red/solid</nowiki-args>wiki\n\nwiki</nowiki></body></page>'),
('{{{#!rst\nHeading\n-------\n}}}',
"<page><body><nowiki>3<nowiki-args>#!rst</nowiki-args>Heading\n-------</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!rst</nowiki-args>Heading\n-------</nowiki></body></page>'),
("{{{#!docbook\n<article xmlns='http://docbook.org/ns/docbook' xmlns:xlink='http://www.w3.org/1999/xlink'>\n<section>\n<title>A docbook document</title>\n</section>\n</article>\n}}}",
"<page><body><nowiki>3<nowiki-args>#!docbook</nowiki-args>&lt;article xmlns='http://docbook.org/ns/docbook' xmlns:xlink='http://www.w3.org/1999/xlink'&gt;\n&lt;section&gt;\n&lt;title&gt;A docbook document&lt;/title&gt;\n&lt;/section&gt;\n&lt;/article&gt;</nowiki></body></page>"),
('{{{#!creole\n|=A|1\n|=B|2\n}}}',
"<page><body><nowiki>3<nowiki-args>#!creole</nowiki-args>|=A|1\n|=B|2</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!creole</nowiki-args>|=A|1\n|=B|2</nowiki></body></page>'),
('{{{#!text/x.moin.creole\ntext\n}}}',
"<page><body><nowiki>3<nowiki-args>#!text/x.moin.creole</nowiki-args>text</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!text/x.moin.creole</nowiki-args>text</nowiki></body></page>'),
('{{{#!markdown\n~~~\naaa\nbbb\nccc\n~~~\n}}}',
"<page><body><nowiki>3<nowiki-args>#!markdown</nowiki-args>~~~\naaa\nbbb\nccc\n~~~</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!markdown</nowiki-args>~~~\naaa\nbbb\nccc\n~~~</nowiki></body></page>'),
('{{{#!mediawiki\n=== Level 3 ===\n}}}',
"<page><body><nowiki>3<nowiki-args>#!mediawiki</nowiki-args>=== Level 3 ===</nowiki></body></page>"),
'<page><body><nowiki>3<nowiki-args>#!mediawiki</nowiki-args>=== Level 3 ===</nowiki></body></page>'),
]

@pytest.mark.parametrize('input,output', data)
Expand Down
Loading

0 comments on commit a14ef02

Please sign in to comment.