[Zope-CVS] CVS: Products/Event/tests - testEventRegistry.py:1.2

Martijn Pieters mj@zope.com
Fri, 20 Sep 2002 11:08:05 -0400


Update of /cvs-repository/Products/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv13184/tests

Modified Files:
	testEventRegistry.py 
Log Message:
New reindentDoc method to clean up docstrings pulled from Event Interfaces.


=== Products/Event/tests/testEventRegistry.py 1.1 => 1.2 ===
--- Products/Event/tests/testEventRegistry.py:1.1	Thu Sep 19 20:03:42 2002
+++ Products/Event/tests/testEventRegistry.py	Fri Sep 20 11:08:04 2002
@@ -54,3 +54,79 @@
         self.assertEqual(registry.getEventTitle('bar'), 'Dummy Event (bar)')
         self.assertEqual(registry.getEventDescription('bar'), 'Bar Description')
         self.failUnless(registry.getEventInterface('bar') is DummyEvent)
+
+class ReindentDocstringTest(unittest.TestCase):
+    def _reindent(self, doc):
+        from Products.Event.EventRegistry import reindentDocstring
+        return reindentDocstring(doc)
+
+    def testOneLine(self):
+        doc = """This is a online docstring."""
+        self.assertEqual(self._reindent(doc), doc)
+
+    def testNoIndent(self):
+        doc = "No indentation.\n\nBut multiple lines nonetheless."
+        self.assertEqual(self._reindent(doc), doc)
+
+    def testOneLevelIndent(self):
+        doc = """This is a multiline docstring.
+
+        All lines are at the same indentation
+        except for the first line.
+
+        And it contains several blank lines.
+
+        """
+
+        self.assertEqual(self._reindent(doc), "\n".join((
+            "This is a multiline docstring.",
+            "",
+            "All lines are at the same indentation",
+            "except for the first line.",
+            "",
+            "And it contains several blank lines.",
+            "", "")))
+
+    def testMultiLevelIndent(self):
+        doc = """This is a more complex multiline docstring.
+
+        In this docstring, multiple levels of indent are used:
+
+        - With bullets across a line break
+          indentation keeps the bullet together.
+
+          - Sub bullets use further indentation
+
+          - Code examples are preserved:
+
+            def foo(bar):
+                return 'Spam and eggs'
+
+        """
+
+        self.assertEqual(self._reindent(doc), "\n".join((
+            "This is a more complex multiline docstring.",
+            "",
+            "In this docstring, multiple levels of indent are used:",
+            "",
+            "- With bullets across a line break",
+            "  indentation keeps the bullet together.",
+            "",
+            "  - Sub bullets use further indentation",
+            "",
+            "  - Code examples are preserved:",
+            "",
+            "    def foo(bar):",
+            "        return 'Spam and eggs'",
+            "", "")))
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    suite = unittest.TestSuite()
+    for testcase in (EventRegistryTests, ReindentDocstringTest):
+        suite.addTest(loader.loadTestsFromTestCase(testcase))
+    return unittest.TestSuite((suite))
+
+if __name__ == '__main__':
+    unittest.main()