def test_source(): txt = ''' <source lang="python"> print "hello world" for i in range(42): print "go syntax highlighting" </source> <source lang="cpp"> #include <iostream> #include <ostream> int main() { std::cout << "Hallo Welt!" << std::endl; } </source> <source lang="lolCode"> HAI CAN HAS STDIO? VISIBLE "HAI WORLD!" KTHXBYE </source> ''' renderMW(txt, 'source')
def test_evilstyles(): """MW markup guide says that these styles should be avoided. """ txt = """text that is <big>big</big> and some is <small>small</small>. there is also <s>strike through</s> text and <u>underlined text</u> linebreaks can be enforced<br/>here<br/>and here we had one. <nowiki>nowikitag ''allows'' the use of [[MW-syntax]] that is not interpreted</nowiki>. we can force <tt> typewriter mode</tt> or <code>code mode</code>""" renderMW(txt, 'evilstyles')
def test_evilstyles(): """MW markup guide says that these styles should be avoided. """ txt = """text that is <big>big</big> and some is <small>small</small>. there is also <s>strike through</s> text and <u>underlined text</u> linebreaks can be enforced<br/>here<br/>and here we had one. <nowiki>nowikitag ''allows'' the use of [[MW-syntax]] that is not interpreted</nowiki>. we can force <tt> typewriter mode</tt> or <code>code mode</code>""" renderMW(txt,'evilstyles')
def test_link_in_table(): txt = ''' == Table == {| class="prettytable" |- | 1.1 || %(links)s |- | %(links)s || 2.2 |} {| class="prettytable" |- | colspan="2" | colspanned cell |- | 2.1 || 2.2 |- | colspan="2" | {| class="prettytable" |- | %(links)s || nested |- | bla || blub |} |} ''' % {'links': links} renderMW('\n\n'.join(get_styled_text(txt)), 'links_and_tables')
def test_list_and_tables_1(): txt = ''' some text outside a table {| class="prettytable" |- | * lvl 1 %(nasty)s * lvl 1 ** lvl 2 %(nasty)s ** lvl 2 *** lvl 3 *** %(nasty)s ** lvl 2 ** lvl 2 * lvl 1 | # lvl 1 %(nasty)s # lvl 1 ## lvl 2 ## lvl 2 %(nasty)s ### lvl 3 ### %(nasty)s ## lvl 2 ## lvl 2 # lvl 1 |} ''' % { 'nasty':nastyChars } renderMW('\n\n'.join(get_styled_text(txt)), 'lists_and_tables_1')
def test_preformatted(): txt = u""" <pre> bla blub blub blub blub blub blub </pre> """ renderMW(txt, 'preformatted')
def test_table(): txt='''{| class="prettytable" |- | row 1, col 1 || row 1, col 2 || row 1, col 3 |- | row 2, col 1 || row 2, col 2 || row 2, col 3 |- | row 3, col 1 || row 3, col 2 || row 3, col 3 ''' renderMW(txt, 'table')
def test_source_breaking(): txt= u''' <source lang="python"> print "asdkfj asöfkdlj asökdlfj asöklfj asöfja sölfjk aösljkdf aösljkf aöslkjf aöskfj aösjf aöskljf asöljf asöljf aösjf asöljkf aösldjf aösljkdf aösljf aösljdf öasljkf öasljdf öaslkjf aösljkf aösljf aösljf aösljf aösjkdf aöslk jfaösld jfaösljkdf aösljdf aösldjf aösldkjfaösldjfaösldjaösljdfaösldjfsal print "this does not make any sense" while True: print "assfaö ljkf asödfjk öklqejw tröqwlktj eq.r,tnm.,mnxcyvbxcvb,mnödfgjheritu epoitur eoqtur eökrlt ne,rm tnewötn _$§5 5345 23$! $%$§% 1ö43jh sadflkjahsdf asjdfhasd flkjahs fajsklfhljkh435pietruqüwirqwoeiräqäöi1o4i123i45j1245 oi51 oi1u345 o3i14u 5 " </source> ''' renderMW(txt, 'source_breaking')
def test_table(): txt = '''{| class="prettytable" |- | row 1, col 1 || row 1, col 2 || row 1, col 3 |- | row 2, col 1 || row 2, col 2 || row 2, col 3 |- | row 3, col 1 || row 3, col 2 || row 3, col 3 ''' renderMW(txt, 'table')
def test_preformatted_breaking(): txt = u''' <pre> <?xml version="1.0" standalone="yes" ?> <DBMODEL Version="4.0"> <SETTINGS> <GLOBALSETTINGS ModelName="posperDbdRev423" IDModel="0" IDVersion="0" VersionStr="1.0.0.0" Comments="" UseVersionHistroy="1" AutoIncVersion="1" DatabaseType="MySQL" ZoomFac="91.00" XPos="566" YPos="922" DefaultDataType="5" DefaultTablePrefix="0" DefSaveDBConn="" DefSyncDBConn="" DefQueryDBConn="" Printer="" HPageCount="4.0" PageAspectRatio="1.440892512336408" PageOrientation="1" PageFormat="A4 (210x297 mm, 8.26x11.7 inches)" SelectedPages="" UsePositionGrid="0" PositionGridX="20" PositionGridY="20" TableNameInRefs="1" DefaultTableType="0" ActivateRefDefForNewRelations="1" FKPrefix="" FKPostfix="" CreateFKRefDefIndex="1" DBQuoteCharacter="`" CreateSQLforLinkedObjects="0" DefModelFont="nimbus sans l" CanvasWidth="4096" CanvasHeight="2842" /> </pre>''' renderMW(txt, 'preformatted_breaking')
def test_preformatted(): txt = """ some preformatted text and some ascii 'art' # # # # # # # # sometimes the text is too long to be displayed on a single line. we have to take care about this and either truncate or wrap the text """ renderMW(txt, 'preformatted')
def test_headingss(): txt = '\n\n'.join([ '=' * lvl + ' Heading lvl %d ' % lvl + '=' * lvl for lvl in range(1, 6) ]) htmlcaptions = '\n\n'.join([ '<h%(lvl)d>Heading h%(lvl)d</h%(lvl)d>' % { 'lvl': lvl + 1 } for lvl in range(5) ]) txt += '\n\n' + htmlcaptions renderMW(txt, 'caption')
def test_gallery(): txt = [] for perrow in range(2,6): for imgcount in range(4, 10): images = '\n'.join(['Bild:dummy_img%d.jpg' %i for i in range(imgcount)]) t=""" <gallery perrow=%(perrow)d> %(images)s </gallery> """ % {'perrow':perrow, 'images':images} txt.append(t) renderMW('\n\n'.join(txt), 'gallery')
def test_gallery(): txt = [] for perrow in range(2, 6): for imgcount in range(4, 10): images = '\n'.join( ['Bild:dummy_img%d.jpg' % i for i in range(imgcount)]) t = """ <gallery perrow=%(perrow)d> %(images)s </gallery> """ % { 'perrow': perrow, 'images': images } txt.append(t) renderMW('\n\n'.join(txt), 'gallery')
def test_link_and_lists(): txt = ''' == Lists == # %(links)s # plain text ## lvl2: %(links)s ## lvl 2: plain text * %(links)s * plain text ** lvl2: %(links)s ** lvl 2: plain text ''' % {'links': links} renderMW('\n\n'.join(get_styled_text(txt)), 'links_and_lists')
def test_math_advanced(): txt = ''' inline math follows <math>-2=\sqrt[3]{-8}\ne\sqrt[6]{(-8)^2}=\sqrt[6]{64}=+2.</math> and now text. ;indented math in definition list :<math>-2=\sqrt[3]{-8}\ne\sqrt[6]{(-8)^2}=\sqrt[6]{64}=+2.</math> math in table (test down-scaling of formula): {| class="prettytable" |- |<math>-2=\sqrt[3]{-8}\ne\sqrt[6]{(-8)^2}=\sqrt[6]{64}=+2.</math> |text |- | text | text |} ''' renderMW(txt, 'math_advanced')
def test_list_and_tables_2(): # oversized table -> nested table is rendered in plain-text txt = ''' {| class="prettytable" |- | * lvl 1 %(links)s * lvl 1 ** lvl 2 %(links)s ** lvl 2 *** <math>-2=\sqrt[3]{-8}\ne\sqrt[6]{(-8)^2}=\sqrt[6]{64}=+2.</math> *** %(links)s ** lvl 2 ** lvl 2 * lvl 1 | {| class="prettytable" |- | # lvl 1 %(links)s # lvl 1 ## lvl 2 ## lvl 2 %(links)s ### <tt>teletyped text</tt> ### %(links)s ## lvl 2 ## lvl 2 # lvl 1 | text |- | text || <math>-2=\sqrt[3]{-8}\ne\sqrt[6]{(-8)^2}=\sqrt[6]{64}=+2.</math> |} |- |text after nesting || %(links)s |} ''' % { 'links':links } renderMW('\n\n'.join(get_styled_text(txt)), 'lists_and_tables_2')
def test_math(): txt = u'some inline math formulas <math>\\frac{x+y}{xy}</math> and some more <math>x^{a+b}</math>\n\nindented formula:\n:<math>x=f(y^2+2).</math>' renderMW(txt, 'math')
def test_paragraph(): txt = t * 20 txt = '\n\n'.join([txt] * 5) renderMW(txt, 'paragraph')
def test_breaking_long_sections(): """test for http://code.pediapress.com/wiki/ticket/177""" txt = u'= sect1/Bla/blub/wurst/bier&尚書•梓材&sdg/&bla/bl&b/aslkjfasdfafasFAS/fasdfasf/asdfs&asdf =' renderMW(txt, 'breaking_long_sections')
def test_externalLink(): txt = u'External link to [http://example.com] with optional link text [http://example.com bla blub]' renderMW(txt, 'externallink')
def test_intraWikiLinks(): txt = u'Intra wiki link: [[Articlename]] with different link text: [[Other Article|Some funky text]]' renderMW(txt, 'intrawikilinks')
def test_url(): txt = u"some url: http://example.com. now a url with umlauts: http://dasörtliche.de and now a italic url ''http://example.com/öpath''" renderMW(txt, 'url')
def test_styles(): txt = "''italic text'' and '''bold''' and the '''''mix''''' text<sup>sup tag</sup> and text<sub>sub tag</sub>" renderMW(txt, 'basicstyles')
def test_definitionlist(): txt = '; definitionlist starts with definition term\n: the definition of the term follows\n; definitionlist starts with definition term\n: the definition of the term follows' renderMW(txt,'definitionlist')
def test_definitionlist(): txt = '; definitionlist starts with definition term\n: the definition of the term follows\n; definitionlist starts with definition term\n: the definition of the term follows' renderMW(txt, 'definitionlist')
def test_paragraph(): txt = t*20 txt = '\n\n'.join([txt]*5) renderMW(txt, 'paragraph')
def test_references(): txt = 'random text with a reference<ref>here we have the reference text</ref>.\n\nwe need the references tag to print the references:\n\n<references/>' renderMW(txt, 'references')
def test_lists(): txt = u"* item 1 ä#üß\n* item 2 @€\n* item3\n\n# numbered item 1\n# numbered item 2\n# numbered item3" renderMW(txt, 'lists')
def test_headingss(): txt = '\n\n'.join(['='*lvl + ' Heading lvl %d '% lvl + '='*lvl for lvl in range(1,6)]) htmlcaptions = '\n\n'.join(['<h%(lvl)d>Heading h%(lvl)d</h%(lvl)d>' % {'lvl': lvl+1} for lvl in range(5)]) txt += '\n\n' + htmlcaptions renderMW(txt, 'caption')
def test_category_links(): """test for http://code.pediapress.com/wiki/ticket/177""" txt = '[[:Category:foo bar]]' renderMW(txt, 'links_entities')
def test_entity_links(): txt = '[http://toolserver.org/~magnus/geo/geohack.php?pagename=HMS_Cardiff_(D108)¶ms=-51.783600_N_-58.467786_E_]' renderMW(txt, 'links_entities')
def test_indented(): txt = 'normal paragraph\n\n: some indented text\n\nback to normal' renderMW(txt, 'indented')
def doit(ex): print "rendering", ex renderMW(ex.txt)