changeset 2652:0182bbf46479

Merge main.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Tue, 07 Aug 2007 18:40:27 +0200
parents c0a85041f623 (current diff) 7ed38f2af242 (diff)
children 459199b59cf7
files
diffstat 2 files changed, 132 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160_wiki.py	Tue Aug 07 18:34:01 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Tue Aug 07 18:40:27 2007 +0200
@@ -41,15 +41,23 @@
         self._ = None
 
     def _replace(self, key):
-        """ replace a item_name if it is in the renames dict """
-        if key[0] == 'PAGE':
-            item_name = key[1] # pagename
-        elif key[0] == 'FILE':
-            item_name = key[2] # filename, key[1] is pagename
-        try:
-            return self.renames[key] # new pagename or new filename
-        except KeyError:
-            return item_name
+        """ replace a item_name if it is in the renames dict
+            key is either a 2-tuple ('PAGE', pagename)
+            or a 3-tuple ('FILE', pagename, filename)
+        """
+        current_page = self.pagename
+        item_type, page_name, file_name = (key + (None, ))[:3]
+        abs_page_name = wikiutil.AbsPageName(self.request, current_page, page_name)
+        if item_type == 'PAGE':
+            item_name = page_name
+            key = (item_type, abs_page_name)
+        elif item_type == 'FILE':
+            item_name = file_name
+            key = (item_type, abs_page_name, file_name)
+        new_name = self.renames.get(key, item_name)
+        if new_name != item_name and abs_page_name != page_name:
+            pass # TODO we have to fix the (absolute) new_name to be a relative name (as it was before)
+        return new_name
 
     def return_word(self, word):
         return word
@@ -211,6 +219,7 @@
             target, linktext = word.split(None, 1)
             target = self._replace_target(target)
             target = self._intelli_quote(target)
+        linktext = linktext.strip()
         if linktext:
             linktext = ' ' + linktext
         return '[%s%s]' % (target, linktext)
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Tue Aug 07 18:34:01 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Tue Aug 07 18:40:27 2007 +0200
@@ -3,8 +3,7 @@
     MoinMoin - tests of wiki content conversion
 
     TODO:
-    * add some ../some_page test
-    * add some /some_page test
+    * fix failing tests
     * fix parser/converter anchor link handling
     * emit a warning if we find some page name that was renamed as a macro argument?
     * shall we support camelcase renaming?
@@ -14,6 +13,7 @@
       or ` ` will have to get handled manually.
     * converter does not touch macro arguments, they will have to get handled
       manually
+    * converter does not touch CamelCase links (but there should be no need to do)
 
     @copyright: 2007 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
@@ -21,82 +21,121 @@
 
 from MoinMoin.script.migration._conv160_wiki import convert_wiki
 
-def test_wiki_conversion(request):
-    pagename = 'TestPage'
-    rename_some_page = {
-            ('PAGE', 'some_page'): 'some page',
-            # NEEDED? ('PAGE', 'RenameThis'): 'ThisRenamed',
-    }
-    rename_some_file = {
-            ('FILE', pagename, 'with_underscore'): 'without underscore',
-            ('FILE', pagename, 'with blank'): 'without_blank',
-    }
-    tests = [
-        # NEEDED? ('CamelCase', {}, 'CamelCase'),
-        # FAILS ('RenameThis', rename_some_page, 'ThisRenamed'),
-        # NEEDED? ('!RenameThis', {}, '!RenameThis'), # not a link
-
-        # FAILING tests:
-        #('[wiki:/OtherPage]', rename_some_page, '[wiki:/OtherPage]'),
-        #('[wiki:/OtherPage other page]', rename_some_page, '[wiki:/OtherPage other page]'),
-        # ('[:Something:Something]', {}, '["Something"]'),
-        #('[attachment:My%20Attachment.jpg:it works]', {}, '[attachment:"My Attachment.jpg" it works]'),
-        #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[wiki:LinuxWiki: LinuxWiki.de]'),
-        #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
-
-        # ambiguity!!! can be resolved with some interwiki map lookup
-        # 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]'),
+class TestWikiConversion:
+    """ test the wiki markup conversion for 1.6.0 """
+    def test_absolute(self):
+        request = self.request
+        pagename = 'TestPage'
+        rename_some_page = {
+                ('PAGE', 'some_page'): 'some page',
+                # NEEDED? ('PAGE', 'RenameThis'): 'ThisRenamed',
+        }
+        rename_some_file = {
+                ('FILE', pagename, 'with_underscore'): 'without underscore',
+                ('FILE', pagename, 'with blank'): 'without_blank',
+        }
+        tests = [
+            # NEEDED? ('CamelCase', {}, 'CamelCase'),
+            # FAILS ('RenameThis', rename_some_page, 'ThisRenamed'),
+            # NEEDED? ('!RenameThis', {}, '!RenameThis'), # not a link
 
-        # "nothing changed" checks
-        ('', {}, ''),
-        ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
-        ('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
-        ('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]'),
+            # FAILING tests:
+            #('[wiki:/OtherPage]', rename_some_page, '[wiki:/OtherPage]'),
+            #('[wiki:/OtherPage other page]', rename_some_page, '[wiki:/OtherPage other page]'),
+            # ('[:Something:Something]', {}, '["Something"]'),
+            #('[attachment:My%20Attachment.jpg:it works]', {}, '[attachment:"My Attachment.jpg" it works]'),
+            #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[wiki:LinuxWiki: LinuxWiki.de]'),
+            #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
 
-        # 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]'),
+            # ambiguity!!! can be resolved with some interwiki map lookup
+            # 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]'),
 
-        # 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]'),
-
-        # "nothing changed" checks
-        ('attachment:OtherPage/with_underscore', rename_some_file, 'attachment:OtherPage/with_underscore'),
+            # "nothing changed" checks
+            ('', {}, ''),
+            ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
+            ('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
+            ('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]'),
 
-        # 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
+            # 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]'),
 
-        # 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"'),
-    ]
-    for data, renames, expected in tests:
-        assert convert_wiki(request, pagename, data, renames) == expected
+            # 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]'),
 
+            # "nothing changed" checks
+            ('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 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"'),
+        ]
+        for data, renames, expected in tests:
+            assert convert_wiki(request, pagename, data, renames) == expected
+
+    def test_sisterpage(self):
+        request = self.request
+        top_page = 'toppage'
+        pagename = '%s/subpage' % top_page
+        rename_some_page = {
+                ('PAGE', '%s/sister' % top_page): '%s/renamed_sister' % top_page,
+        }
+        tests = [
+            # "nothing changed" checks
+            ('["../sister_norename"]', rename_some_page, '["../sister_norename"]'),
+
+            # renames
+            # FAILS, see TODO in _replace:
+            #('["../sister"]', rename_some_page, '["../renamed_sister"]'),
+        ]
+        for data, renames, expected in tests:
+            assert convert_wiki(request, pagename, data, renames) == expected
+
+    def test_subpage(self):
+        request = self.request
+        pagename = 'toppage'
+        rename_some_page = {
+                ('PAGE', '%s/subpage' % pagename): '%s/renamed_subpage' % pagename,
+        }
+        tests = [
+            # "nothing changed" checks
+            ('["/subpage_norename"]', rename_some_page, '["/subpage_norename"]'),
+
+            # renames
+            # FAILS, see TODO in _replace:
+            #('["/subpage"]', rename_some_page, '["/renamed_subpage"]'),
+        ]
+        for data, renames, expected in tests:
+            assert convert_wiki(request, pagename, data, renames) == expected
+
+