changeset 2729:012d5ec31f92

tests: fix most wiki markup converter tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 13 Aug 2007 04:06:53 +0200
parents 59b3d8b8971f
children a907a61c33b3
files MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/_tests/test_conv160_wiki.py
diffstat 2 files changed, 66 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160_wiki.py	Mon Aug 13 03:04:22 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Mon Aug 13 04:06:53 2007 +0200
@@ -10,8 +10,8 @@
     Markup transformations needed:
     -------------------------------------------------------
     ["some_page"]           -> [[some page]] # renamed
-    [:some_page:some text]  -> [[some page|some text]] # NEW: free link with link text
-    [:page:text]            -> [[page|text]] # NEW: free link with link text
+    [:some_page:some text]  -> [[some page|some text]]
+    [:page:text]            -> [[page|text]]
                                (with a page not being renamed)
 
     attachment:with%20blank.txt -> [[attachment:with blank.txt]]
@@ -28,7 +28,7 @@
 from MoinMoin import i18n
 i18n.wikiLanguages = lambda: []
 from MoinMoin import config, wikiutil
-from MoinMoin.parser.text_moin_wiki import Parser
+from early16_text_moin_wiki import Parser
 from MoinMoin.action import AttachFile
 
 class Converter(Parser):
@@ -116,8 +116,10 @@
         return origw
 
     def _macro_repl(self, word):
+        stripped_old = word[2:-2]
+        decorated_new = "<<%s>>" % stripped_old
         # XXX later check whether some to be renamed pagename is used as macro param
-        return word
+        return decorated_new
 
     # LINKS ------------------------------------------------------------------
     def _replace_target(self, target):
@@ -155,7 +157,7 @@
         else:
             name = "%s/%s" % (pagename, fname)
         if text:
-            text = ' ' + text
+            text = '|' + text
         return "%s:%s%s" % (scheme, name, text)
 
     def _interwiki_repl(self, word):
@@ -165,10 +167,17 @@
             return word
         else:
             scheme, wikiname, pagename, text = self.interwiki("wiki:" + word)
+            iswiki = wikiutil.isStrictWikiname(pagename)
             if wikiname == 'Self':
-                return '["%s"]' % pagename # optimize special case
+                if iswiki:
+                    return '%s' % pagename # optimize special case
+                else:
+                    return '[[%s]]' % pagename # optimize special case
             else:
-                return "%s:%s" % (wikiname, pagename)
+                if ' ' not in pagename: # XXX we could get a ' '  by urlunquoting
+                    return "%s:%s" % (wikiname, pagename)
+                else:
+                    return "[[%s:%s]]" % (wikiname, pagename)
 
     def _url_repl(self, word):
         """Handle literal URLs including inline images."""
@@ -176,19 +185,21 @@
 
         if scheme == "wiki":
             scheme, wikiname, pagename, text = self.interwiki(word)
+            # XXX remap pagename
+            # XXX check pagename if it contains a blank
             if wikiname == 'Self':
-                return '["%s"]' % pagename # optimize special case
+                return '[[%s]]' % pagename # optimize special case
             else:
-                return "%s:%s:%s" % (scheme, wikiname, pagename)
+                return "[[%s:%s]]" % (wikiname, pagename)
 
         if scheme in self.attachment_schemas:
-            return self.attachment(word)
+            return "[[%s]]" % self.attachment(word)
 
         if wikiutil.isPicture(word):
             # Get image name http://here.com/dir/image.gif -> image
             name = word.split('/')[-1]
             name = ''.join(name.split('.')[:-1])
-            return word # self.formatter.image(src=word, alt=name)
+            return "{{%s}}" % word # we need transclusion syntax now!
         else:
             return word # word, scheme
 
@@ -208,8 +219,8 @@
             target = self._replace_target(target)
         linktext = linktext.strip()
         if linktext:
-            linktext = ' ' + linktext
-        return '[%s%s]' % (target, linktext)
+            linktext = '|' + linktext
+        return '[[%s%s]]' % (target, linktext)
 
 
     def _url_bracket_repl(self, word):
@@ -224,8 +235,8 @@
                 text = ''
             link = self._replace_target(link)
             if text:
-                text = ' ' + text
-            return '[%s%s]' % (link, text) # use freelink with text
+                text = '|' + text
+            return '[[%s%s]]' % (link, text)
 
         scheme_and_rest = word.split(":", 1)
         if len(scheme_and_rest) == 2: # scheme given
@@ -234,14 +245,14 @@
                 scheme, wikiname, pagename, text = self.interwiki(word, pretty_url=1)
                 if wikiname == 'Self':
                     if text:
-                        text = ' %s' % text
-                    return '["%s"%s]' % (pagename, text)
+                        text = '|' + text
+                    return '[[%s%s]]' % (pagename, text)
                 else:
                     if text:
-                        text = ' %s' % text
-                    return "[%s:%s:%s%s]" % (scheme, wikiname, pagename, text)
+                        text = '|' + text
+                    return "[[%s:%s%s]]" % (wikiname, pagename, text)
             if scheme in self.attachment_schemas:
-                return '[%s]' % self.attachment(word, pretty_url=1)
+                return '[[%s]]' % self.attachment(word, pretty_url=1)
 
         words = word.split(None, 1)
         if len(words) == 1:
@@ -249,8 +260,8 @@
         else:
             link, text = words
         if text:
-            text = ' ' + text
-        return '[%s%s]' % (link, text)
+            text = '|' + text
+        return '[[%s%s]]' % (link, text)
 
     # SCANNING ---------------------------------------------------------------
     def scan(self, scan_re, line):
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Mon Aug 13 03:04:22 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Mon Aug 13 04:06:53 2007 +0200
@@ -19,7 +19,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 import py
-py.test.skip("broken")
+#py.test.skip("broken")
 
 from MoinMoin.script.migration._conv160_wiki import convert_wiki
 
@@ -48,56 +48,56 @@
             # and transformed to wiki:SeaPig:BrianDorsey if SeaPig is in
             # interwiki map, but no page SeaPig exists.
             #('[wiki:MacroMarket/EmbedObject EO]', {}, '["MacroMarket/EmbedObject" EO]'),
-            ('[wiki:SeaPig/BrianDorsey]', {}, '[wiki:SeaPig:BrianDorsey]'),
+            ('[wiki:SeaPig/BrianDorsey]', {}, '[[SeaPig:BrianDorsey]]'),
 
-            # "nothing changed" checks
+            # "nothing changed" checks (except markup)
             ('', {}, ''),
             ('CamelCase', {}, 'CamelCase'),
             ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
             ('some_text', {}, 'some_text'),
-            ('["some_text"]', {}, '["some_text"]'),
+            ('["some_text"]', {}, '[[some_text]]'),
             ('some_page', rename_some_page, 'some_page'), # not a link
             ('{{{["some_page"]}}}', rename_some_page, '{{{["some_page"]}}}'), # not a link
             ('`["some_page"]`', rename_some_page, '`["some_page"]`'), # not a link
-            ('["OtherPage/some_page"]', rename_some_page, '["OtherPage/some_page"]'), # different link
+            ('["OtherPage/some_page"]', rename_some_page, '[[OtherPage/some_page]]'), # different link
             ('MoinMaster:some_page', rename_some_page, 'MoinMaster:some_page'), # external link
             ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
-            ('[http://some_server/some_page]', rename_some_page, '[http://some_server/some_page]'), # external link
-            ('[#some_page]', rename_some_page, '[#some_page]'), # link to anchor that has same name
-            ('[attachment:some_page.png]', rename_some_page, '[attachment:some_page.png]'), # att, not page
-            ('[attachment:some_page.png test picture]', rename_some_page, '[attachment:some_page.png test picture]'), # att, not page
-            ('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[attachment:some_page.txt attachment:some_page.png]'),
+            ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
+            ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
+            ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
+            ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
+            ('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|attachment:some_page.png]]'),
 
             # page rename changes result
-            ('["some_page"]', rename_some_page, '["some page"]'),
-            ('[:some_page]', rename_some_page, '["some page"]'),
-            ('[:some_page:]', rename_some_page, '["some page"]'),
-            ('[:some_page:some text]', rename_some_page, '["some page" some text]'),
-            ('Self:some_page', rename_some_page, '["some page"]'),
-            ('wiki:Self:some_page', rename_some_page, '["some page"]'),
-            ('[wiki:Self:some_page some text]', rename_some_page, '["some page" some text]'),
-            # XXX FAILS ('wiki:Self:some_page#some_anchor', rename_some_page, '["some page"#some_anchor]'),
+            ('["some_page"]', rename_some_page, '[[some page]]'),
+            ('[:some_page]', rename_some_page, '[[some page]]'),
+            ('[:some_page:]', rename_some_page, '[[some page]]'),
+            ('[:some_page:some text]', rename_some_page, '[[some page|some text]]'),
+            ('Self:some_page', rename_some_page, '[[some page]]'),
+            ('wiki:Self:some_page', rename_some_page, '[[some page]]'),
+            ('[wiki:Self:some_page some text]', rename_some_page, '[[some page|some text]]'),
+            # FFF ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
 
             # other markup changes we do
-            ('[:other page]', {}, '["other page"]'),
-            ('[:other page:]', {}, '["other page"]'),
-            ('[:other page:other text]', {}, '["other page" other text]'),
-            # FAILS ('Self:CamelCase', {}, 'CamelCase'),
-            ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[wiki:WikiPedia:"Lynx_(web_browser)" Lynx]'),
-            ('[:Something:Something]', {}, '["Something"]'), # optimize markup
+            ('[:other page]', {}, '[[other page]]'),
+            ('[:other page:]', {}, '[[other page]]'),
+            ('[:other page:other text]', {}, '[[other page|other text]]'),
+            ('Self:CamelCase', {}, 'CamelCase'),
+            ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[[WikiPedia:Lynx_(web_browser)|Lynx]]'),
+            ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
 
             # "nothing changed" checks
-            ('attachment:OtherPage/with_underscore', rename_some_file, 'attachment:OtherPage/with_underscore'),
+            ('attachment:OtherPage/with_underscore', rename_some_file, '[[attachment:OtherPage/with_underscore]]'),
 
             # file rename changes result
-            ('attachment:with_underscore', rename_some_file, 'attachment:"without underscore"'),
-            ('attachment:TestPage/with_underscore', rename_some_file, 'attachment:"without underscore"'), # remove superfluous pagename
+            ('attachment:with_underscore', rename_some_file, '[[attachment:without underscore]]'),
+            ('attachment:TestPage/with_underscore', rename_some_file, '[[attachment:without underscore]]'), # remove superfluous pagename
 
             # attachment syntax: kill %20
-            ('attachment:with%20blank', rename_some_file, 'attachment:without_blank'), # plus rename
-            ('attachment:keep%20blank', rename_some_file, 'attachment:"keep blank"'), # no rename
-            ('attachment:TestPage/keep%20blank', rename_some_file, 'attachment:"keep blank"'), # remove superfluous pagename
-            ('attachment:OtherPage/keep%20blank', rename_some_file, 'attachment:"OtherPage/keep blank"'),
+            ('attachment:with%20blank', rename_some_file, '[[attachment:without_blank]]'), # plus rename
+            ('attachment:keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # no rename
+            ('attachment:TestPage/keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # remove superfluous pagename
+            ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
         ]
         for data, renames, expected in tests:
             assert convert_wiki(request, pagename, data, renames) == expected
@@ -111,7 +111,7 @@
         }
         tests = [
             # "nothing changed" checks
-            ('["../sister_norename"]', rename_some_page, '["../sister_norename"]'),
+            ('["../sister_norename"]', rename_some_page, '[[../sister_norename]]'),
 
             # renames
             # FAILS, see TODO in _replace:
@@ -128,7 +128,7 @@
         }
         tests = [
             # "nothing changed" checks
-            ('["/subpage_norename"]', rename_some_page, '["/subpage_norename"]'),
+            ('["/subpage_norename"]', rename_some_page, '[[/subpage_norename]]'),
 
             # renames
             # FAILS, see TODO in _replace: