changeset 4898:c299e8ece712

Groups2009: Docstring for get() for BaseDictsBackend, BaseDict and BaseGroupsBackend. Tests for get check if another default value returned for not existing keys. Typo and other refinements.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Fri, 24 Jul 2009 14:17:44 +0200
parents 4cc429db5bd1
children d11540d1c5a0
files MoinMoin/datastruct/backends/__init__.py MoinMoin/datastruct/backends/_tests/__init__.py MoinMoin/datastruct/backends/_tests/test_wiki_groups.py MoinMoin/formatter/_tests/test_groups.py
diffstat 4 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/datastruct/backends/__init__.py	Fri Jul 24 10:02:31 2009 +0200
+++ b/MoinMoin/datastruct/backends/__init__.py	Fri Jul 24 14:17:44 2009 +0200
@@ -98,6 +98,11 @@
                 pass
 
     def get(self, key, default=None):
+        """
+        Return the group named <key> if key is in the backend, else
+        default. If default is not given, it defaults to None, so that
+        this method never raises a GroupDoesNotExistError.
+        """
         try:
             return self[key]
         except GroupDoesNotExistError:
@@ -275,6 +280,11 @@
         return self._dict[key]
 
     def get(self, key, default=None):
+        """
+        Return the value if key is in the dictionary, else default. If
+        default is not given, it defaults to None, so that this method
+        never raises a KeyError.
+        """
         return self._dict.get(key, default)
 
     def _load_dict(self):
@@ -312,6 +322,11 @@
         raise NotImplementedError()
 
     def get(self, key, default=None):
+        """
+        Return the dictionary named <key> if key is in the backend,
+        else default. If default is not given, it defaults to None, so
+        that this method never raises a DictDoesNotExistError.
+        """
         try:
             return self[key]
         except DictDoesNotExistError:
--- a/MoinMoin/datastruct/backends/_tests/__init__.py	Fri Jul 24 10:02:31 2009 +0200
+++ b/MoinMoin/datastruct/backends/_tests/__init__.py	Fri Jul 24 14:17:44 2009 +0200
@@ -72,6 +72,7 @@
         assert groups.get(u'AdminGroup')
         assert u'NotExistingGroup' not in groups
         assert groups.get(u'NotExistingGroup') is None
+        assert groups.get(u'NotExistingGroup', []) == []
 
     def test_groups_with_member(self):
         groups = self.request.groups
@@ -172,10 +173,13 @@
 
         assert u'SomeNotExistingDict' not in dicts
         assert dicts.get(u'SomeNotExistingDict') is None
+        assert dicts.get(u'SomeNotExistingDict', {}) == {}
+
 
         for dict_name, expected_dict in self.dicts.items():
             test_dict = dicts[dict_name]
             for key, value in expected_dict.items():
                 assert u'SomeNotExistingKey' not in test_dict
                 assert test_dict.get(u'SomeNotExistingKey') is None
+                assert test_dict.get(u'SomeNotExistingKey', {}) == {}
 
--- a/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Fri Jul 24 10:02:31 2009 +0200
+++ b/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Fri Jul 24 14:17:44 2009 +0200
@@ -28,7 +28,7 @@
     def setup_class(self):
         become_trusted(self.request)
 
-        for (group, members) in self.test_groups.iteritems():
+        for group, members in self.test_groups.iteritems():
             page_text = ' * %s' % '\n * '.join(members)
             create_page(self.request, group, page_text)
 
--- a/MoinMoin/formatter/_tests/test_groups.py	Fri Jul 24 10:02:31 2009 +0200
+++ b/MoinMoin/formatter/_tests/test_groups.py	Fri Jul 24 14:17:44 2009 +0200
@@ -83,7 +83,7 @@
         assert 'first level' in members
         assert 'again first level' in members
 
-    def test_intended_list(self):
+    def test_indented_list(self):
         text = """
     * first level
      * second level
@@ -190,7 +190,7 @@
         assert 'first level' in members
         assert 'again first level' in members
 
-    def test_intended_list(self):
+    def test_indented_list(self):
         text = """
     * first level
     ** second level