[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_docutils.py Full coverage for z.c.docutils.makeDocStructures.

Tres Seaver cvs-admin at zope.org
Wed May 9 20:23:46 UTC 2012


Log message for revision 125782:
  Full coverage for z.c.docutils.makeDocStructures.

Changed:
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_docutils.py

-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_docutils.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_docutils.py	2012-05-09 20:23:39 UTC (rev 125781)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_docutils.py	2012-05-09 20:23:43 UTC (rev 125782)
@@ -45,9 +45,84 @@
         from zope.configuration.docutils import makeDocStructures
         return makeDocStructures(*args, **kw)
 
-    # TODO:  coverage
+    def _makeContext(self):
+        class _Context(object):
+            def __init__(self):
+                self._docRegistry = []
+        return _Context()
 
+    def test_empty(self):
+        context = self._makeContext()
+        namespaces, subdirs = self._callFUT(context)
+        self.assertEqual(len(namespaces), 0)
+        self.assertEqual(len(subdirs), 0)
 
+    def test_wo_parents(self):
+        from zope.interface import Interface
+        class ISchema(Interface):
+            pass
+        class IUsedIn(Interface):
+            pass
+        NS = 'http://namespace.example.com/main'
+        NS2 = 'http://namespace.example.com/other'
+        def _one():
+            pass
+        def _two():
+            pass
+        def _three():
+            pass
+        context = self._makeContext()
+        context._docRegistry.append(
+                    ((NS, 'one'), ISchema, IUsedIn, _one, 'ONE', None))
+        context._docRegistry.append(
+                    ((NS2, 'two'), ISchema, IUsedIn, _two, 'TWO', None))
+        context._docRegistry.append(
+                    ((NS, 'three'), ISchema, IUsedIn, _three, 'THREE', None))
+        namespaces, subdirs = self._callFUT(context)
+        self.assertEqual(len(namespaces), 2)
+        self.assertEqual(namespaces[NS], {'one': (ISchema, _one, 'ONE'),
+                                          'three': (ISchema, _three, 'THREE')})
+        self.assertEqual(namespaces[NS2], {'two': (ISchema, _two, 'TWO')})
+        self.assertEqual(len(subdirs), 0)
+
+    def test_w_parents(self):
+        from zope.interface import Interface
+        class ISchema(Interface):
+            pass
+        class IUsedIn(Interface):
+            pass
+        PNS = 'http://namespace.example.com/parent'
+        NS = 'http://namespace.example.com/main'
+        NS2 = 'http://namespace.example.com/other'
+        def _one():
+            pass
+        def _two():
+            pass
+        def _three():
+            pass
+        class Parent(object):
+            namespace = PNS
+            name = 'parent'
+        parent1 = Parent()
+        parent2 = Parent()
+        parent2.name = 'parent2'
+        context = self._makeContext()
+        context._docRegistry.append(
+                    ((NS, 'one'), ISchema, IUsedIn, _one, 'ONE', parent1))
+        context._docRegistry.append(
+                    ((NS2, 'two'), ISchema, IUsedIn, _two, 'TWO', parent2))
+        context._docRegistry.append(
+                    ((NS, 'three'), ISchema, IUsedIn, _three, 'THREE', parent1))
+        namespaces, subdirs = self._callFUT(context)
+        self.assertEqual(len(namespaces), 0)
+        self.assertEqual(len(subdirs), 2)
+        self.assertEqual(subdirs[(PNS, 'parent')],
+                         [(NS, 'one', ISchema, _one, 'ONE'),
+                          (NS, 'three', ISchema, _three, 'THREE')])
+        self.assertEqual(subdirs[(PNS, 'parent2')],
+                         [(NS2, 'two', ISchema, _two, 'TWO')])
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(Test_wrap),



More information about the checkins mailing list