[Zope3-checkins] CVS: Zope3/src/zope/app/apidoc - tests.py:1.4
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Mar 29 20:59:56 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/apidoc
In directory cvs.zope.org:/tmp/cvs-serv11622/src/zope/app/apidoc
Modified Files:
tests.py
Log Message:
Removed pprintDict() helper function to make place for pprint(), which works
similar, but is more general. This function could actually move to
zope.testing.doctestunit.
=== Zope3/src/zope/app/apidoc/tests.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/apidoc/tests.py:1.3 Sun Mar 28 18:39:20 2004
+++ Zope3/src/zope/app/apidoc/tests.py Mon Mar 29 20:59:54 2004
@@ -15,7 +15,7 @@
$Id$
"""
-import pprint
+from pprint import PrettyPrinter
import unittest
from zope.app import zapi
from zope.app.traversing.interfaces import IContainmentRoot
@@ -50,21 +50,58 @@
return LocationProxy(obj, Root(), name)
-def pprintDict(info):
- print_ = pprint.PrettyPrinter(width=69).pprint
- info = info.items()
- info.sort()
- return print_(info)
+def _convertToSortedSequence(obj):
+ """Convert data structures containing dictionaries to data structures
+ using sequences only.
+
+ Examples::
+
+ >>> _convertToSortedSequence(())
+ ()
+ >>> _convertToSortedSequence({})
+ []
+ >>> _convertToSortedSequence({'foo': 1})
+ [('foo', 1)]
+ >>> _convertToSortedSequence({'foo': 1, 'bar': 2})
+ [('bar', 2), ('foo', 1)]
+ >>> _convertToSortedSequence({'foo': {1: 'a'}, 'bar': 2})
+ [('bar', 2), ('foo', [(1, 'a')])]
+ """
+
+ # Handle incoming sequences
+ if isinstance(obj, (tuple, list)):
+ objtype = type(obj)
+ result = []
+ for value in obj:
+ result.append(_convertToSortedSequence(value))
+ return objtype(result)
+
+ # Handle Dictionaries
+ if isinstance(obj, dict):
+ result = []
+ for key, value in obj.items():
+ result.append((key, _convertToSortedSequence(value)))
+ result.sort()
+ return result
+
+ return obj
+
+
+def pprint(info):
+ """Print a datastructure in a nice format."""
+ info = _convertToSortedSequence(info)
+ return PrettyPrinter(width=69).pprint(info)
def test_suite():
return unittest.TestSuite((
- DocTestSuite('zope.app.apidoc',
- setUp=setUp, tearDown=tearDown),
- DocTestSuite('zope.app.apidoc.browser.apidoc',
- setUp=setUp, tearDown=tearDown),
- DocTestSuite('zope.app.apidoc.utilities'),
+ #DocTestSuite('zope.app.apidoc',
+ # setUp=setUp, tearDown=tearDown),
+ #DocTestSuite('zope.app.apidoc.browser.apidoc',
+ # setUp=setUp, tearDown=tearDown),
+ #DocTestSuite('zope.app.apidoc.utilities'),
+ DocTestSuite('zope.app.apidoc.tests'),
))
if __name__ == '__main__':
More information about the Zope3-Checkins
mailing list