testmakepy.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Test makepy - try and run it over every OCX in the windows system directory.
  2. import sys
  3. import win32api
  4. import traceback
  5. import glob
  6. import os
  7. import traceback
  8. import win32com.test.util
  9. from win32com.client import makepy, selecttlb, gencache
  10. import pythoncom
  11. import winerror
  12. def TestBuildAll(verbose = 1):
  13. num = 0
  14. tlbInfos = selecttlb.EnumTlbs()
  15. for info in tlbInfos:
  16. if verbose:
  17. print("%s (%s)" % (info.desc, info.dll))
  18. try:
  19. makepy.GenerateFromTypeLibSpec(info)
  20. # sys.stderr.write("Attr typeflags for coclass referenced object %s=%d (%d), typekind=%d\n" % (name, refAttr.wTypeFlags, refAttr.wTypeFlags & pythoncom.TYPEFLAG_FDUAL,refAttr.typekind))
  21. num += 1
  22. except pythoncom.com_error as details:
  23. # Ignore these 2 errors, as the are very common and can obscure
  24. # useful warnings.
  25. if details.hresult not in [winerror.TYPE_E_CANTLOADLIBRARY,
  26. winerror.TYPE_E_LIBNOTREGISTERED]:
  27. print("** COM error on", info.desc)
  28. print(details)
  29. except KeyboardInterrupt:
  30. print("Interrupted!")
  31. raise KeyboardInterrupt
  32. except:
  33. print("Failed:", info.desc)
  34. traceback.print_exc()
  35. if makepy.bForDemandDefault:
  36. # This only builds enums etc by default - build each
  37. # interface manually
  38. tinfo = (info.clsid, info.lcid, info.major, info.minor)
  39. mod = gencache.EnsureModule(info.clsid, info.lcid, info.major, info.minor)
  40. for name in mod.NamesToIIDMap.keys():
  41. makepy.GenerateChildFromTypeLibSpec(name, tinfo)
  42. return num
  43. def TestAll(verbose = 0):
  44. num = TestBuildAll(verbose)
  45. print("Generated and imported", num, "modules")
  46. win32com.test.util.CheckClean()
  47. if __name__=='__main__':
  48. TestAll("-q" not in sys.argv)