home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2738 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.0 KB  |  99 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import win32com.server.util as win32com
  6. import win32com.test.util as win32com
  7. import win32com.client as win32com
  8. import traceback
  9. import pythoncom
  10. import pywintypes
  11. import winerror
  12. L = pywintypes.Unicode
  13. import unittest
  14. error = 'dictionary test error'
  15.  
  16. def MakeTestDictionary():
  17.     return win32com.client.Dispatch('Python.Dictionary')
  18.  
  19.  
  20. def TestDictAgainst(dict, check):
  21.     for key, value in check.items():
  22.         if dict(key) != value:
  23.             raise error, "Indexing for '%s' gave the incorrect value - %s/%s" % (`key`, `dict[key]`, `check[key]`)
  24.         dict(key) != value
  25.     
  26.  
  27.  
  28. def Register(quiet):
  29.     import win32com.server.register as win32com
  30.     DictionaryPolicy = DictionaryPolicy
  31.     import win32com.servers.dictionary
  32.     win32com.server.register.RegisterClasses(DictionaryPolicy, quiet = quiet)
  33.  
  34.  
  35. def TestDict(quiet = None):
  36.     if quiet is None:
  37.         quiet = '-v' not in sys.argv
  38.     
  39.     Register(quiet)
  40.     if not quiet:
  41.         print 'Simple enum test'
  42.     
  43.     dict = MakeTestDictionary()
  44.     checkDict = { }
  45.     TestDictAgainst(dict, checkDict)
  46.     dict['NewKey'] = 'NewValue'
  47.     checkDict['NewKey'] = 'NewValue'
  48.     TestDictAgainst(dict, checkDict)
  49.     dict['NewKey'] = None
  50.     del checkDict['NewKey']
  51.     TestDictAgainst(dict, checkDict)
  52.     if not quiet:
  53.         print 'Failure tests'
  54.     
  55.     
  56.     try:
  57.         dict()
  58.         raise error, 'default method with no args worked when it shouldnt have!'
  59.     except pythoncom.com_error:
  60.         (hr, desc, exc, argErr) = None
  61.         if hr != winerror.DISP_E_BADPARAMCOUNT:
  62.             raise error, 'Expected DISP_E_BADPARAMCOUNT - got %d (%s)' % (hr, desc)
  63.         hr != winerror.DISP_E_BADPARAMCOUNT
  64.  
  65.     
  66.     try:
  67.         dict('hi', 'there')
  68.         raise error, 'multiple args worked when it shouldnt have!'
  69.     except pythoncom.com_error:
  70.         (hr, desc, exc, argErr) = None
  71.         if hr != winerror.DISP_E_BADPARAMCOUNT:
  72.             raise error, 'Expected DISP_E_BADPARAMCOUNT - got %d (%s)' % (hr, desc)
  73.         hr != winerror.DISP_E_BADPARAMCOUNT
  74.  
  75.     
  76.     try:
  77.         dict(0)
  78.         raise error, 'int key worked when it shouldnt have!'
  79.     except pythoncom.com_error:
  80.         (hr, desc, exc, argErr) = None
  81.         if hr != winerror.DISP_E_TYPEMISMATCH:
  82.             raise error, 'Expected DISP_E_TYPEMISMATCH - got %d (%s)' % (hr, desc)
  83.         hr != winerror.DISP_E_TYPEMISMATCH
  84.  
  85.     if not quiet:
  86.         print 'Python.Dictionary tests complete.'
  87.     
  88.  
  89.  
  90. class TestCase(win32com.test.util.TestCase):
  91.     
  92.     def testDict(self):
  93.         TestDict()
  94.  
  95.  
  96. if __name__ == '__main__':
  97.     unittest.main()
  98.  
  99.