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.

GenTestScripts.py 2.5KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # Generate scripts needed for serious testing!
  3. #
  4. import os
  5. import sys
  6. import pythoncom
  7. import win32com
  8. import win32com.client.makepy
  9. import win32com.test
  10. genList = [
  11. ("msword8", "{00020905-0000-0000-C000-000000000046}", 1033, 8, 0),
  12. ]
  13. genDir = "Generated4Test"
  14. def GetGenPath():
  15. import win32api
  16. return os.path.join(win32api.GetFullPathName(win32com.test.__path__[0]), genDir)
  17. def GenerateFromRegistered(fname, *loadArgs):
  18. # tlb = apply(pythoncom.LoadRegTypeLib, loadArgs)
  19. genPath = GetGenPath()
  20. try:
  21. os.stat(genPath)
  22. except os.error:
  23. os.mkdir(genPath)
  24. # Ensure an __init__ exists.
  25. open(os.path.join(genPath, "__init__.py"), "w").close()
  26. print(fname, ": generating -", end=" ")
  27. f = open(os.path.join(genPath, fname + ".py"), "w")
  28. win32com.client.makepy.GenerateFromTypeLibSpec(
  29. loadArgs, f, bQuiet=1, bGUIProgress=1
  30. )
  31. f.close()
  32. print("compiling -", end=" ")
  33. fullModName = "win32com.test.%s.%s" % (genDir, fname)
  34. exec("import " + fullModName)
  35. # Inject the generated module as a top level module.
  36. sys.modules[fname] = sys.modules[fullModName]
  37. print("done")
  38. def GenerateAll():
  39. for args in genList:
  40. try:
  41. GenerateFromRegistered(*args)
  42. except KeyboardInterrupt:
  43. print("** Interrupted ***")
  44. break
  45. except pythoncom.com_error:
  46. print("** Could not generate test code for ", args[0])
  47. def CleanAll():
  48. print("Cleaning generated test scripts...")
  49. try: # Clear exceptions!
  50. 1 / 0
  51. except:
  52. pass
  53. genPath = GetGenPath()
  54. for args in genList:
  55. try:
  56. name = args[0] + ".py"
  57. os.unlink(os.path.join(genPath, name))
  58. except os.error as details:
  59. if type(details) == type(()) and details[0] != 2:
  60. print("Could not deleted generated", name, details)
  61. try:
  62. name = args[0] + ".pyc"
  63. os.unlink(os.path.join(genPath, name))
  64. except os.error as details:
  65. if type(details) == type(()) and details[0] != 2:
  66. print("Could not deleted generated", name, details)
  67. try:
  68. os.unlink(os.path.join(genPath, "__init__.py"))
  69. except:
  70. pass
  71. try:
  72. os.unlink(os.path.join(genPath, "__init__.pyc"))
  73. except:
  74. pass
  75. try:
  76. os.rmdir(genPath)
  77. except os.error as details:
  78. print("Could not delete test directory -", details)
  79. if __name__ == "__main__":
  80. GenerateAll()
  81. CleanAll()