changeset 4843:d8093123a1bd

Groups2009: Formatter which collects group definitions from a page was moved from datastruct.backend._formatter to formatter.groups. Refinements of the formatter. TestWikiGroupPageParser was removed because it duplicates formatter's test.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Fri, 10 Jul 2009 18:09:15 +0200
parents 654fdbbf4eb5
children 193bbbdd0ace
files MoinMoin/datastruct/backends/_formatters.py MoinMoin/datastruct/backends/_tests/test_formatters.py MoinMoin/datastruct/backends/_tests/test_wiki_groups.py MoinMoin/datastruct/backends/wiki_groups.py MoinMoin/formatter/_tests/test_formatter.py MoinMoin/formatter/_tests/test_groups.py MoinMoin/formatter/groups.py
diffstat 7 files changed, 187 insertions(+), 230 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/datastruct/backends/_formatters.py	Fri Jul 10 14:32:05 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-MoinMoin - datastruct (dicts and groups) formatters
-
-@copyright: 2009 MoinMoin:DmitrijsMilajevs
-@license: GNU GPL, see COPYING for details.
-"""
-
-from MoinMoin.formatter import FormatterBase
-from MoinMoin import wikiutil
-
-class GroupFormatter(FormatterBase):
-    """
-    Collect groups and format nothing
-    """
-
-    def __init__(self, request, **kw):
-        FormatterBase.__init__(self, request, **kw)
-        self.bullet_list_level = 0
-        self.inside_list_item = False
-        self.inside_link = False
-        self.members = []
-        self.new_member = ''
-        self.new_link_member = ''
-
-    def pagelink(self, on, pagename='', page=None, **kw):
-        self.inside_link = on
-        if self.inside_list_item:
-            if not pagename and page:
-                pagename = page.page_name
-            pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
-            self.new_link_member = pagename
-        return ''
-
-    def bullet_list(self, on, **kw):
-        if on:
-            self.bullet_list_level += 1
-        else:
-            self.bullet_list_level -= 1
-
-        assert self.bullet_list_level >= 0
-        return ''
-
-    def listitem(self, on, **kw):
-        if self.bullet_list_level == 1:
-            self.inside_list_item = on
-            if not on:
-                if self.new_member.strip() == '' and self.new_link_member != '':
-                    self.members.append(self.new_link_member.strip())
-                if self.new_member != '' and self.new_link_member == '':
-                    self.members.append(self.new_member.strip())
-            self.new_member = ''
-            self.new_link_member = ''
-        return ''
-
-    def definition_list(self, on, **kw):
-        return ''
-
-    def definition_term(self, on, compact=0, **kw):
-        return ''
-
-    def definition_desc(self, on, **kw):
-        return ''
-
-    def text(self, text, **kw):
-        if self.inside_list_item and not self.inside_link:
-            self.new_member += text
-        return ''
-
-    def null(self, *args, **kw):
-        return ''
-
-    # All these must be overriden here because they raise
-    # NotImplementedError!@#! or return html?! in the base class.
-    set_highlight_re = rawHTML = url = image = smiley = null
-    strong = emphasis = underline = highlight = sup = sub = strike = null
-    code = preformatted = small = big = code_area = code_line = null
-    code_token = linebreak = paragraph = rule = icon = null
-    number_list = null
-    heading = table = null
-    table_row = table_cell = attachment_link = attachment_image = attachment_drawing = null
-    transclusion = transclusion_param = null
-
--- a/MoinMoin/datastruct/backends/_tests/test_formatters.py	Fri Jul 10 14:32:05 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - MoinMoin.datasttructs.backends._formatters Tests
-
-    @copyright: 2009 by MoinMoin:DmitrijsMilajevs
-    @license: GNU GPL, see COPYING for details.
-"""
-
-from MoinMoin.datastruct.backends._formatters import GroupFormatter
-from MoinMoin.Page import Page
-from MoinMoin._tests import become_trusted, create_page, nuke_page
-
-class TestDatastruct(object):
-
-    def test_CamelCase(self):
-        text = """
- * CamelCase
-"""
-        assert u'CamelCase' in self.get_group(text)
-
-    def test_extended_name(self):
-        text = """
- * extended name
-"""
-        assert u'extended name' in self.get_group(text)
-
-    def test_extended_link(self):
-        text = """
- * [[extended link]]
-"""
-        assert u'extended link' in self.get_group(text)
-
-    def test_extended_link_with_label(self):
-        text = """
- * [[extended link| label]]
-"""
-        assert u'extended link' in self.get_group(text)
-
-    def test_extended_link_and_text(self):
-        text = """
- * [[extended link]] other text
- * other text [[extended link]]
- * other text [[extended link]] other text
-
-"""
-        assert len(self.get_group(text)) == 0
-
-    def test_ignore_second_level_list(self):
-        text = """
-  * second level
-   * third level
-    * forth level
-     * and then some...
-"""
-        assert len([x for x in self.get_group(text)]) == 0
-
-    def test_ignore_other(self):
-        text = """
-= ignore this =
- * take this
-
-Ignore previous line and this text.
-"""
-        assert u'take this' in self.get_group(text)
-
-    def test_strip_whitespace(self):
-        text = """
- *   take this
-"""
-        assert u'take this' in self.get_group(text)
-
-    def get_group(self, text):
-        request = self.request
-        formatter = GroupFormatter(self.request)
-
-        become_trusted(request)
-        create_page(request, u'TestPageGroup', text)
-        page = Page(request, 'TestPageGroup', formatter=formatter)
-        page.send_page(content_only=True)
-        nuke_page(request, u'TestPageGroup')
-
-        return formatter.members
-
--- a/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Fri Jul 10 14:32:05 2009 +0200
+++ b/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Fri Jul 10 18:09:15 2009 +0200
@@ -20,72 +20,11 @@
 from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string_list, nuke_page, nuke_user, wikiconfig
 
 
-class TestWikiGroupPageParser(object):
-    """
-    Test what backend extracts from a group page and what is ignored.
-    """
+class TestWikiGroupBackend(GroupsBackendTest):
 
     # Suppose that default configuration for the group_manager_init is
     # used which is WikiGroups backend.
 
-    def test_CamelCase(self):
-        text = """
- * CamelCase
-"""
-        assert u'CamelCase' in self.get_group(text)
-
-    def test_extended_name(self):
-        text = """
- * extended name
-"""
-        assert u'extended name' in self.get_group(text)
-
-    def test_extended_link(self):
-        text = """
- * [[extended link]]
-"""
-        assert u'extended link' in self.get_group(text)
-
-    def test_ignore_second_level_list(self):
-        text = """
-  * second level
-   * third level
-    * forth level
-     * and then some...
-"""
-        assert len([x for x in self.get_group(text)]) == 0
-
-    def test_ignore_other(self):
-        text = """
-= ignore this =
- * take this
-
-Ignore previous line and this text.
-"""
-        assert u'take this' in self.get_group(text)
-
-    def test_strip_whitespace(self):
-        text = """
- *   take this
-"""
-        assert u'take this' in self.get_group(text)
-
-    def get_group(self, text):
-        request = self.request
-        become_trusted(request)
-        create_page(request, u'SomeTestGroup', text)
-        group = request.groups[u'SomeTestGroup']
-        nuke_page(request, u'SomeTestGroup')
-        return group
-
-
-class TestWikiGroupBackend(GroupsBackendTest):
-
-    class Config(wikiconfig.Config):
-
-        def group_manager_init(self, request):
-            return WikiGroups(request)
-
     def setup_class(self):
         become_trusted(self.request)
 
--- a/MoinMoin/datastruct/backends/wiki_groups.py	Fri Jul 10 14:32:05 2009 +0200
+++ b/MoinMoin/datastruct/backends/wiki_groups.py	Fri Jul 10 18:09:15 2009 +0200
@@ -16,7 +16,7 @@
 from MoinMoin import caching, wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.datastruct.backends import BaseGroup, BaseGroupsBackend, GroupDoesNotExistError
-from MoinMoin.datastruct.backends._formatters import GroupFormatter
+from MoinMoin.formatter.groups import Formatter
 
 
 class WikiGroup(BaseGroup):
@@ -60,7 +60,7 @@
         return WikiGroup(request=self.request, name=group_name, backend=self)
 
     def _retrieve_members(self, group_name):
-        formatter = GroupFormatter(self.request)
+        formatter = Formatter(self.request)
         page = Page(self.request, group_name, formatter=formatter)
         page.send_page(content_only=True)
         return formatter.members
--- a/MoinMoin/formatter/_tests/test_formatter.py	Fri Jul 10 14:32:05 2009 +0200
+++ b/MoinMoin/formatter/_tests/test_formatter.py	Fri Jul 10 18:09:15 2009 +0200
@@ -132,5 +132,6 @@
                     'MoinMoin.formatter.dom_xml',
                     'MoinMoin.formatter.text_python',
                     'MoinMoin.formatter.pagelinks',
+                    'MoinMoin.formtter.groups',
                    ]
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/formatter/_tests/test_groups.py	Fri Jul 10 18:09:15 2009 +0200
@@ -0,0 +1,120 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.formatter.groups Tests
+
+    @copyright: 2009 by MoinMoin:DmitrijsMilajevs
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from  MoinMoin.formatter.groups import Formatter
+from MoinMoin.Page import Page
+from MoinMoin._tests import become_trusted, create_page, nuke_page
+
+class TestGroupFormatter(object):
+
+    def test_CamelCase(self):
+        text = """
+ * CamelCase
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'CamelCase' in groups
+
+    def test_extended_name(self):
+        text = """
+ * extended name
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'extended name' in groups
+
+    def test_extended_link(self):
+        text = """
+ * [[extended link]]
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'extended link' in groups
+
+    def test_extended_link_with_label(self):
+        text = """
+ * [[extended link| label]]
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'label' in groups
+
+    def test_extended_link_and_text(self):
+        text = """
+ * [[extended link]] other text
+ * other text [[extended link]]
+ * other text [[extended link]] other text
+
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 3
+        assert u'extended link other text' in groups
+        assert u'other text extended link' in groups
+        assert u'other text extended link other text' in groups
+
+    def test_ignore_not_first_level_list(self):
+        text = """
+ * first level
+  * second level
+   * [[SomeLink]]
+    * forth level
+     * and then some...
+ * again first level
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 2
+        assert 'first level' in groups
+        assert 'again first level' in groups
+
+    def test_intended_list(self):
+        text = """
+    * first level
+     * second level
+      * [[SomeLink]]
+       * forth level
+        * and then some...
+    * again first level
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 2
+        assert 'first level' in groups
+        assert 'again first level' in groups
+
+    def test_ignore_other(self):
+        text = """
+= ignore this =
+ * take this
+
+Ignore previous line and this text.
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'take this' in groups
+
+    def test_strip_whitespace(self):
+        text = """
+ *   take this
+"""
+        groups = list(self.get_group(text))
+        assert len(groups) == 1
+        assert u'take this' in groups
+
+    def get_group(self, text):
+        request = self.request
+        formatter = Formatter(self.request)
+
+        become_trusted(request)
+        create_page(request, u'TestPageGroup', text)
+        page = Page(request, 'TestPageGroup', formatter=formatter)
+        page.send_page(content_only=True)
+        nuke_page(request, u'TestPageGroup')
+
+        return formatter.members
+
+coverage_modules = ['MoinMoin.formtter.groups']
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/formatter/groups.py	Fri Jul 10 18:09:15 2009 +0200
@@ -0,0 +1,63 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.formatter.groups datastruct (dicts and groups) formatters
+
+    @copyright: 2009 MoinMoin:DmitrijsMilajevs
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.formatter import FormatterBase
+from MoinMoin import wikiutil
+
+class Formatter(FormatterBase):
+    """
+    Collect groups and format nothing
+    """
+
+    def __init__(self, request, **kw):
+        FormatterBase.__init__(self, request, **kw)
+        self.bullet_list_level = 0
+        self.inside_list_item = False
+        self.inside_link = False
+        self.members = []
+        self.new_member = ''
+
+    def bullet_list(self, on, **kw):
+        if on:
+            self.bullet_list_level += 1
+        else:
+            self.bullet_list_level -= 1
+
+        assert self.bullet_list_level >= 0
+
+        return self.null()
+
+    def listitem(self, on, **kw):
+        if self.bullet_list_level == 1:
+            self.inside_list_item = on
+            if not on:
+                stripped_new_member = self.new_member.strip()
+                if stripped_new_member:
+                    self.members.append(stripped_new_member)
+            self.new_member = ''
+        return self.null()
+
+    def text(self, text, **kw):
+        if self.bullet_list_level == 1 and self.inside_list_item: #and not self.inside_link:
+            self.new_member += text
+        return self.null()
+
+    def null(self, *args, **kw):
+        return ''
+
+    # All these must be overriden here because they raise
+    # NotImplementedError!@#! or return html?! in the base class.
+    set_highlight_re = rawHTML = url = image = smiley = null
+    strong = emphasis = underline = highlight = sup = sub = strike = null
+    code = preformatted = small = big = code_area = code_line = null
+    code_token = linebreak = paragraph = rule = icon = null
+    number_list = definition_list = definition_term = definition_desc = null
+    heading = table = pagelink = null
+    table_row = table_cell = attachment_link = attachment_image = attachment_drawing = null
+    transclusion = transclusion_param = null
+