[Zope3-checkins] SVN: Zope3/trunk/src/zope/importtool/ add a helper
function to produce a simple two-column report
Fred L. Drake, Jr.
fred at zope.com
Wed Jun 2 16:02:43 EDT 2004
Log message for revision 25202:
add a helper function to produce a simple two-column report
-=-
Added: Zope3/trunk/src/zope/importtool/format.py
===================================================================
--- Zope3/trunk/src/zope/importtool/format.py 2004-06-02 19:51:07 UTC (rev 25201)
+++ Zope3/trunk/src/zope/importtool/format.py 2004-06-02 20:02:42 UTC (rev 25202)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Helper functions for formatting.
+
+$Id$
+"""
+
+def two_column_report(items):
+ left_width = right_width = 0
+ for left, right in items:
+ left_width = max(left_width, len(left))
+ right_width = max(right_width, len(right))
+ width = left_width + 1 + right_width
+ print width * "-"
+ for left, right in items:
+ print left.ljust(left_width), right
Property changes on: Zope3/trunk/src/zope/importtool/format.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/importtool/tests/test_format.py
===================================================================
--- Zope3/trunk/src/zope/importtool/tests/test_format.py 2004-06-02 19:51:07 UTC (rev 25201)
+++ Zope3/trunk/src/zope/importtool/tests/test_format.py 2004-06-02 20:02:42 UTC (rev 25202)
@@ -0,0 +1,44 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for zope.importtool.format.
+
+$Id$
+"""
+import sys
+import unittest
+
+from StringIO import StringIO
+
+from zope.importtool import format
+
+
+class FormatTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.old_stdout = sys.stdout
+ sys.stdout = self.stdout = StringIO()
+
+ def tearDown(self):
+ sys.stdout = self.old_stdout
+
+ def test_two_column_report(self):
+ format.two_column_report([("abc", "def"), ("abcdef", "ghijklm")])
+ self.assertEqual(self.stdout.getvalue(),
+ "--------------\n"
+ "abc def\n"
+ "abcdef ghijklm\n")
+
+
+def test_suite():
+ return unittest.makeSuite(FormatTestCase)
Property changes on: Zope3/trunk/src/zope/importtool/tests/test_format.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list