Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testDictionary.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # testDictionary.py
  2. #
  3. import sys
  4. import unittest
  5. import pythoncom
  6. import pywintypes
  7. import win32com.client
  8. import win32com.server.util
  9. import win32com.test.util
  10. import win32timezone
  11. import winerror
  12. def MakeTestDictionary():
  13. return win32com.client.Dispatch("Python.Dictionary")
  14. def TestDictAgainst(dict, check):
  15. for key, value in list(check.items()):
  16. if dict(key) != value:
  17. raise Exception(
  18. "Indexing for '%s' gave the incorrect value - %s/%s"
  19. % (repr(key), repr(dict[key]), repr(check[key]))
  20. )
  21. # Ensure we have the correct version registered.
  22. def Register(quiet):
  23. import win32com.servers.dictionary
  24. from win32com.test.util import RegisterPythonServer
  25. RegisterPythonServer(win32com.servers.dictionary.__file__, "Python.Dictionary")
  26. def TestDict(quiet=None):
  27. if quiet is None:
  28. quiet = not "-v" in sys.argv
  29. Register(quiet)
  30. if not quiet:
  31. print("Simple enum test")
  32. dict = MakeTestDictionary()
  33. checkDict = {}
  34. TestDictAgainst(dict, checkDict)
  35. dict["NewKey"] = "NewValue"
  36. checkDict["NewKey"] = "NewValue"
  37. TestDictAgainst(dict, checkDict)
  38. dict["NewKey"] = None
  39. del checkDict["NewKey"]
  40. TestDictAgainst(dict, checkDict)
  41. now = win32timezone.now()
  42. # We want to keep the milliseconds but discard microseconds as they
  43. # don't survive the conversion.
  44. now = now.replace(microsecond=round(now.microsecond / 1000) * 1000)
  45. dict["Now"] = now
  46. checkDict["Now"] = now
  47. TestDictAgainst(dict, checkDict)
  48. if not quiet:
  49. print("Failure tests")
  50. try:
  51. dict()
  52. raise Exception("default method with no args worked when it shouldnt have!")
  53. except pythoncom.com_error as xxx_todo_changeme:
  54. (hr, desc, exc, argErr) = xxx_todo_changeme.args
  55. if hr != winerror.DISP_E_BADPARAMCOUNT:
  56. raise Exception("Expected DISP_E_BADPARAMCOUNT - got %d (%s)" % (hr, desc))
  57. try:
  58. dict("hi", "there")
  59. raise Exception("multiple args worked when it shouldnt have!")
  60. except pythoncom.com_error as xxx_todo_changeme1:
  61. (hr, desc, exc, argErr) = xxx_todo_changeme1.args
  62. if hr != winerror.DISP_E_BADPARAMCOUNT:
  63. raise Exception("Expected DISP_E_BADPARAMCOUNT - got %d (%s)" % (hr, desc))
  64. try:
  65. dict(0)
  66. raise Exception("int key worked when it shouldnt have!")
  67. except pythoncom.com_error as xxx_todo_changeme2:
  68. (hr, desc, exc, argErr) = xxx_todo_changeme2.args
  69. if hr != winerror.DISP_E_TYPEMISMATCH:
  70. raise Exception("Expected DISP_E_TYPEMISMATCH - got %d (%s)" % (hr, desc))
  71. if not quiet:
  72. print("Python.Dictionary tests complete.")
  73. class TestCase(win32com.test.util.TestCase):
  74. def testDict(self):
  75. TestDict()
  76. if __name__ == "__main__":
  77. unittest.main()