changeset 4488:a2a05ae3e7ec

1.6.0a mig script/converter: add tests, improve test compliance, clean up
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 15 Jan 2009 23:37:36 +0100
parents c3cae273af82
children a835ada897e0
files MoinMoin/script/migration/_conv160a_wiki.py MoinMoin/script/migration/_tests/test_conv160a_wiki.py
diffstat 2 files changed, 55 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160a_wiki.py	Mon Jan 12 09:57:57 2009 +0100
+++ b/MoinMoin/script/migration/_conv160a_wiki.py	Thu Jan 15 23:37:36 2009 +0100
@@ -3,25 +3,13 @@
     MoinMoin - convert content in 1.6.0alpha (rev 1844: 58ebb64243cc) wiki markup to 1.6.0 style
                by using a modified 1.6.0alpha parser as translator.
 
-    Assuming we have this "renames" map:
-    -------------------------------------------------------
-    'PAGE', 'some_page'        -> 'some page'
-    'FILE', 'with%20blank.txt' -> 'with blank.txt'
-
-    Markup transformations needed:
-    -------------------------------------------------------
-    ["some_page"]           -> [[some page]] # renamed
-    [: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]]
-    attachment:some_page/with%20blank.txt -> [[attachment:some page/with blank.txt]]
-    The attachment processing should also urllib.unquote the filename (or at
-    least replace %20 by space) and put it into "quotes" if it contains spaces.
+    PLEASE NOTE: most moin users will never need to execute this code,
+                 because it is just for users of 1.6.0alpha version,
+                 that used modified link markup, but was never released.
+                 The 1.5.x/1.6.x releases use a different link markup than 1.6.0a.
 
     @copyright: 2007 MoinMoin:JohannesBerg,
-                2007 MoinMoin:ThomasWaldmann
+                2007-2009 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -276,29 +264,6 @@
         else:
             return text
 
-    ''' old:
-    def _interwiki_repl(self, word):
-        """Handle InterWiki links."""
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
-        if wikitag_bad:
-            return word
-        else:
-            wikiname, pagename = word.split(':', 1)
-            pagename = wikiutil.url_unquote(pagename) # maybe someone has used %20 for blanks in pagename
-            camelcase = wikiutil.isStrictWikiname(pagename)
-            if wikiname in ('Self', self.request.cfg.interwikiname):
-                pagename = self._replace(('PAGE', pagename))
-                if camelcase:
-                    return '%s' % pagename # optimize special case
-                else:
-                    return '[[%s]]' % pagename # optimize special case
-            else:
-                if ' ' in pagename: # we could get a ' '  by urlunquoting
-                    return '[[%s:%s]]' % (wikiname, pagename)
-                else:
-                    return '%s:%s' % (wikiname, pagename)
-    '''
-
     def _interwiki_repl(self, word):
         """Handle InterWiki links."""
         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
@@ -345,56 +310,23 @@
             else:
                 return '[[%s:%s%s]]' % (wikitag, wikitail, text)
 
-    ''' old:
-    def interwiki(self, url_and_text):
-        # keep track of whether this is a self-reference, so links
-        # are always shown even the page doesn't exist.
-        wikiname, pagename = wikiutil.split_wiki(url)
-    '''
-    '''
-    def attachment(self, url_and_text):
-        """ This gets called on attachment URLs. """
-        if len(url_and_text) == 1:
-            url = url_and_text[0]
-            text = ''
-        else:
-            url, text = url_and_text
-            text = '|' + text
-
-        scheme, fname = url.split(":", 1)
-        #scheme, fname, text = wikiutil.split_wiki(target_and_text)
+    def attachment(self, target_and_text, **kw):
+        """ This gets called on attachment URLs """
+        _ = self._
+        scheme, fname, text = wikiutil160a.split_wiki(target_and_text)
 
         pagename, fname = AttachFile.absoluteName(fname, self.pagename)
         from_this_page = pagename == self.pagename
         fname = self._replace(('FILE', pagename, fname))
-        fname = wikiutil.url_unquote(fname, want_unicode=True)
-        fname = self._replace(('FILE', pagename, fname))
+        #fname = wikiutil.url_unquote(fname, want_unicode=True)
+        #fname = self._replace(('FILE', pagename, fname))
         pagename = self._replace(('PAGE', pagename))
         if from_this_page:
             name = fname
         else:
             name = "%s/%s" % (pagename, fname)
 
-        if scheme == 'drawing':
-            return "{{drawing:%s%s}}" % (name, text)
-
-        # check for image URL, and possibly return IMG tag
-        # (images are always inlined, just like for other URLs)
-        if wikiutil.isPicture(name):
-            return "{{attachment:%s%s}}" % (name, text)
-
-        # inline the attachment
-        if scheme == 'inline':
-            return '{{attachment:%s%s}}' % (name, text)
-        else: # 'attachment'
-            return '[[attachment:%s%s]]' % (name, text)
-    '''
-
-    def attachment(self, target_and_text, **kw):
-        """ This gets called on attachment URLs """
-        _ = self._
-        scheme, fname, text = wikiutil160a.split_wiki(target_and_text)
-        fn_txt = fname
+        fn_txt = name
         if text:
             fn_txt += '|' + text
 
@@ -433,30 +365,33 @@
         # Local extended link? [:page name:link text] XXX DEPRECATED
         if word[0] == ':':
             words = word[1:].split(':', 1)
-            pagename = self._replace(('PAGE', words[0]))
-            if len(words) == 1 or len(words) == 2 and not words[1]:
-                return '[[%s]]' % (pagename, )
-            else:
-                return '[[%s|%s]]' % (pagename, words[1])
+            link, text = (words + ['', ''])[:2]
+            if link.strip() == text.strip():
+                text = ''
+            link = self._replace_target(link)
+            if text:
+                text = '|' + text
+            return '[[%s%s]]' % (link, text)
 
         scheme_and_rest = word.split(":", 1)
         if len(scheme_and_rest) == 1: # no scheme
             # Traditional split on space
             words = word.split(None, 1)
-            if len(words) == 1:
-                words = words * 2
-
             if words[0].startswith('#'): # anchor link
-                if words[0] == words[1]:
-                    return '[[%s]]' % words[0]
-                else:
-                    return '[[%s|%s]]' % tuple(words)
+                link, text = (words + ['', ''])[:2]
+                if link.strip() == text.strip():
+                    text = ''
+                if text:
+                    text = '|' + text
+                return '[[%s%s]]' % (link, text)
         else:
-            scheme, rest = scheme_and_rest
+            scheme = scheme_and_rest[0]
             if scheme == "wiki":
                 return self.interwiki(word, pretty_url=1)
             if scheme in self.attachment_schemas:
-                return self.attachment(word)
+                m = self.attachment(word)
+                # with url_bracket markup, 1.6.0a parser does not embed pictures, but link!
+                return '[[%s]]' % m[2:-2]
 
             words = word.split(None, 1)
             if len(words) == 1:
@@ -471,65 +406,6 @@
             else:
                 return '[[%s|%s]]' % (target, text)
 
-
-    '''
-    def _url_bracket_repl(self, word):
-        """Handle bracketed URLs."""
-        word = word[1:-1] # strip brackets
-
-        # Local extended link?
-        if word[0] == ':':
-            words = word[1:].split(':', 1)
-            link, text = (words + ['', ''])[:2]
-            if link.strip() == text.strip():
-                text = ''
-            link = self._replace_target(link)
-            if text:
-                text = '|' + text
-            return '[[%s%s]]' % (link, text)
-
-        # Traditional split on space
-        words = word.split(None, 1)
-        if words[0][0] == '#':
-            # anchor link
-            link, text = (words + ['', ''])[:2]
-            if link.strip() == text.strip():
-                text = ''
-            #link = self._replace_target(link)
-            if text:
-                text = '|' + text
-            return '[[%s%s]]' % (link, text)
-
-        scheme = words[0].split(":", 1)[0]
-        if scheme == "wiki":
-            return self.interwiki(words)
-            #scheme, wikiname, pagename, text = self.interwiki(word)
-            #print "%r %r %r %r" % (scheme, wikiname, pagename, text)
-            #if wikiname in ('Self', self.request.cfg.interwikiname, ''):
-            #    if text:
-            #        text = '|' + text
-            #    return '[[%s%s]]' % (pagename, text)
-            #else:
-            #    if text:
-            #        text = '|' + text
-            #    return "[[%s:%s%s]]" % (wikiname, pagename, text)
-        if scheme in self.attachment_schemas:
-            m = self.attachment(words)
-            if m.startswith('{{') and m.endswith('}}'):
-                # with url_bracket markup, 1.5.8 parser does not embed, but link!
-                m = '[[%s]]' % m[2:-2]
-            return m
-
-        target, desc = (words + ['', ''])[:2]
-        if wikiutil.isPicture(desc) and re.match(self.url_rule, desc):
-            #return '[[%s|{{%s|%s}}]]' % (words[0], words[1], words[0])
-            return '[[%s|{{%s}}]]' % (target, desc)
-        else:
-            if desc:
-                desc = '|' + desc
-            return '[[%s%s]]' % (target, desc)
-    '''
-
     def _pre_repl(self, word):
         w = word.strip()
         if w == '{{{' and not self.in_pre:
--- a/MoinMoin/script/migration/_tests/test_conv160a_wiki.py	Mon Jan 12 09:57:57 2009 +0100
+++ b/MoinMoin/script/migration/_tests/test_conv160a_wiki.py	Thu Jan 15 23:37:36 2009 +0100
@@ -37,6 +37,23 @@
         }
 
         tests = [
+            # 1.6.0a specific tests (jk)
+            # attachment links
+            ("attachment:filename.ext", {}, "[[attachment:filename.ext]]"),
+            ("[attachment:'Filename.ext' Aliasname]", {}, "[[attachment:Filename.ext|Aliasname]]"),
+            ("[attachment:'Pagename/Filename.ext' Aliasname]", {}, "[[attachment:Pagename/Filename.ext|Aliasname]]"),
+            ("[attachment:'Pagename/Subpage/Filename.ext' Aliasname]", {}, "[[attachment:Pagename/Subpage/Filename.ext|Aliasname]]"),
+            ('[attachment:"Pagename/Subpage/File Name.ext" Aliasname]', {}, "[[attachment:Pagename/Subpage/File Name.ext|Aliasname]]"),
+            # page links
+            ('["Pagename"]', {}, "[[Pagename]]"),
+            ('["/Subpage"]', {}, "[[/Subpage]]"),
+            ('["Pagename/Subpage"]', {}, "[[Pagename/Subpage]]"),
+            ("['Pagename/Subpage' Aliasname]", {}, "[[Pagename/Subpage|Aliasname]]"),
+            # other links
+            ("[http://google.de google]", {}, "[[http://google.de|google]]"),
+            # other stuff
+            ("[[GetText(To)]]", {}, "<<GetText(To)>>"),
+
             # 1.6.0a specific tests
             ('["some page" somepage]', {}, '[[some page|somepage]]'),
             ("['some page' somepage]", {}, '[[some page|somepage]]'),
@@ -64,18 +81,17 @@
             ('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
-            #XXX ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
-            #XXX ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
-            # url unquote stuff (%20 was popular for space)
-            #XXX ('attachment:My%20Attachment.jpg', {}, '{{attachment:My Attachment.jpg}}'), # embed!
-            #XXX ('[attachment:My%20Attachment.jpg]', {}, '[[attachment:My Attachment.jpg]]'), # link!
-            #XXX ('[attachment:My%20Attachment.jpg it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
+            ('[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
 
             # page rename changes result
             ('["some_page"]', rename_some_page, '[[some page]]'),
             ('[:some_page]', rename_some_page, '[[some page]]'),
+            ('[:some_page#anchor]', rename_some_page, '[[some page#anchor]]'),
             ('[:some_page:]', rename_some_page, '[[some page]]'),
+            ('[:some_page#anchor:]', rename_some_page, '[[some page#anchor]]'),
             ('[:some_page:some text]', rename_some_page, '[[some page|some text]]'),
+            ('[:some_page#anchor:some text]', rename_some_page, '[[some page#anchor|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]]'),
@@ -87,22 +103,16 @@
             ('[:other page:other text]', {}, '[[other page|other text]]'),
             # XXX TODO ('Self:CamelCase', {}, 'CamelCase'),
             # XXX TODO ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[[WikiPedia:Lynx_(web_browser)|Lynx]]'),
-            # XXX TODO ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
+            ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
 
             # "nothing changed" checks
             ('attachment:OtherPage/with_underscore', rename_some_file, '[[attachment:OtherPage/with_underscore]]'),
 
             # file rename changes result
-            # XXX TODO ('attachment:with_underscore', rename_some_file, '[[attachment:without underscore]]'),
-            # XXX TODO ('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
-            # XXX TODO ('attachment:with%20blank', rename_some_file, '[[attachment:without_blank]]'), # plus rename
-            # XXX TODO ('attachment:keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # no rename
-            # XXX TODO ('attachment:TestPage/keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # remove superfluous pagename
-            # XXX TODO ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
-
-            # embed images
+            # embed images, all verified on 160a
             ('http://server/image.png', {}, '{{http://server/image.png}}'),
             ('attachment:image.gif', {}, '{{attachment:image.gif}}'),
             ('inline:image.jpg', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}