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

  1. """Unit test for odbchelper.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.2 $"
  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 odbchelper
  16.  
  17. class GoodInput(unittest.TestCase):
  18.     def testBlank(self):
  19.         """buildConnectionString handles empty dictionary"""
  20.         self.assertEqual("", odbchelper.buildConnectionString({}))
  21.     def testKnownValue(self):
  22.         """buildConnectionString returns known result with known input"""
  23.         params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
  24.         knownItems = params.items()
  25.         knownItems.sort()
  26.         knownString = repr(knownItems)
  27.         result = odbchelper.buildConnectionString(params)
  28.         resultItems = [tuple(e.split("=")) for e in result.split(";")]
  29.         resultItems.sort()
  30.         resultString = repr(resultItems)
  31.         self.assertEqual(knownString, resultString)
  32.  
  33. class BadInput(unittest.TestCase):
  34.     def testString(self):
  35.         """buildConnectionString should fail with string input"""
  36.         self.assertRaises(AttributeError, odbchelper.buildConnectionString, "")
  37.  
  38.     def testList(self):
  39.         """buildConnectionString should fail with list input"""
  40.         self.assertRaises(AttributeError, odbchelper.buildConnectionString, [])
  41.  
  42.     def testTuple(self):
  43.         """buildConnectionString should fail with tuple input"""
  44.         self.assertRaises(AttributeError, odbchelper.buildConnectionString, ())
  45.  
  46. if __name__ == "__main__":
  47.     unittest.main()
  48.