home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / diveintopython / examples / apihelpertest.py < prev    next >
Encoding:
Python Source  |  2004-05-05  |  1.8 KB  |  63 lines

  1. """Unit test for apihelper.py
  2.  
  3. This program is part of "Dive Into Python", a free Python book for
  4. experienced programmers.  Visit http://diveintopython.org/ for the
  5. latest version.
  6. """
  7.  
  8. __author__ = "Mark Pilgrim (mark@diveintopython.org)"
  9. __version__ = "$Revision: 1.4 $"
  10. __date__ = "$Date: 2004/05/05 21:57:19 $"
  11. __copyright__ = "Copyright (c) 2001 Mark Pilgrim"
  12. __license__ = "Python"
  13.  
  14. import unittest
  15. import apihelper
  16. import sys
  17. from StringIO import StringIO
  18.  
  19. class Redirector(unittest.TestCase):
  20.     def setUp(self):
  21.         self.savestdout = sys.stdout
  22.         self.redirect = StringIO()
  23.         sys.stdout = self.redirect
  24.  
  25.     def tearDown(self):
  26.         sys.stdout = self.savestdout
  27.  
  28. class KnownValues(Redirector):
  29.     def testApiHelper(self):
  30.         """info should return known result for apihelper"""
  31.         apihelper.info(apihelper)
  32.         self.redirect.seek(0)
  33.         self.assertEqual(self.redirect.read(),
  34. """info       Print methods and doc strings. Takes module, class, list, dictionary, or string.
  35. """)
  36.  
  37. class ParamChecks(Redirector):
  38.     def testSpacing(self):
  39.         """info should honor spacing argument"""
  40.         apihelper.info(apihelper, spacing=20)
  41.         self.redirect.seek(0)
  42.         self.assertEqual(self.redirect.read(),
  43. """info                 Print methods and doc strings. Takes module, class, list, dictionary, or string.
  44. """)
  45.  
  46.     def testCollapse(self):
  47.         """info should honor collapse argument"""
  48.         apihelper.info(apihelper, collapse=0)
  49.         self.redirect.seek(0)
  50.         self.assertEqual(self.redirect.read(),
  51. """info       Print methods and doc strings.
  52.  
  53.     Takes module, class, list, dictionary, or string.
  54. """)
  55.  
  56. class BadInput(unittest.TestCase):
  57.     def testNoObject(self):
  58.         """info should fail with no object"""
  59.         self.assertRaises(TypeError, apihelper.info, spacing=20)
  60.  
  61. if __name__ == "__main__":
  62.     unittest.main()
  63.