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.

pywin32_testall.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. """A test runner for pywin32"""
  2. import os
  3. import site
  4. import subprocess
  5. import sys
  6. # locate the dirs based on where this script is - it may be either in the
  7. # source tree, or in an installed Python 'Scripts' tree.
  8. this_dir = os.path.dirname(__file__)
  9. site_packages = [
  10. site.getusersitepackages(),
  11. ] + site.getsitepackages()
  12. failures = []
  13. # Run a test using subprocess and wait for the result.
  14. # If we get an returncode != 0, we know that there was an error, but we don't
  15. # abort immediately - we run as many tests as we can.
  16. def run_test(script, cmdline_extras):
  17. dirname, scriptname = os.path.split(script)
  18. # some tests prefer to be run from their directory.
  19. cmd = [sys.executable, "-u", scriptname] + cmdline_extras
  20. print("--- Running '%s' ---" % script)
  21. sys.stdout.flush()
  22. result = subprocess.run(cmd, check=False, cwd=dirname)
  23. print("*** Test script '%s' exited with %s" % (script, result.returncode))
  24. sys.stdout.flush()
  25. if result.returncode:
  26. failures.append(script)
  27. def find_and_run(possible_locations, extras):
  28. for maybe in possible_locations:
  29. if os.path.isfile(maybe):
  30. run_test(maybe, extras)
  31. break
  32. else:
  33. raise RuntimeError(
  34. "Failed to locate a test script in one of %s" % possible_locations
  35. )
  36. def main():
  37. import argparse
  38. code_directories = [this_dir] + site_packages
  39. parser = argparse.ArgumentParser(
  40. description="A script to trigger tests in all subprojects of PyWin32."
  41. )
  42. parser.add_argument(
  43. "-no-user-interaction",
  44. default=False,
  45. action="store_true",
  46. help="(This is now the default - use `-user-interaction` to include them)",
  47. )
  48. parser.add_argument(
  49. "-user-interaction",
  50. action="store_true",
  51. help="Include tests which require user interaction",
  52. )
  53. parser.add_argument(
  54. "-skip-adodbapi",
  55. default=False,
  56. action="store_true",
  57. help="Skip the adodbapi tests; useful for CI where there's no provider",
  58. )
  59. args, remains = parser.parse_known_args()
  60. # win32, win32ui / Pythonwin
  61. extras = []
  62. if args.user_interaction:
  63. extras += ["-user-interaction"]
  64. extras.extend(remains)
  65. scripts = [
  66. "win32/test/testall.py",
  67. "Pythonwin/pywin/test/all.py",
  68. ]
  69. for script in scripts:
  70. maybes = [os.path.join(directory, script) for directory in code_directories]
  71. find_and_run(maybes, extras)
  72. # win32com
  73. maybes = [
  74. os.path.join(directory, "win32com", "test", "testall.py")
  75. for directory in [
  76. os.path.join(this_dir, "com"),
  77. ]
  78. + site_packages
  79. ]
  80. extras = remains + ["1"] # only run "level 1" tests in CI
  81. find_and_run(maybes, extras)
  82. # adodbapi
  83. if not args.skip_adodbapi:
  84. maybes = [
  85. os.path.join(directory, "adodbapi", "test", "adodbapitest.py")
  86. for directory in code_directories
  87. ]
  88. find_and_run(maybes, remains)
  89. # This script has a hard-coded sql server name in it, (and markh typically
  90. # doesn't have a different server to test on) but there is now supposed to be a server out there on the Internet
  91. # just to run these tests, so try it...
  92. maybes = [
  93. os.path.join(directory, "adodbapi", "test", "test_adodbapi_dbapi20.py")
  94. for directory in code_directories
  95. ]
  96. find_and_run(maybes, remains)
  97. if failures:
  98. print("The following scripts failed")
  99. for failure in failures:
  100. print(">", failure)
  101. sys.exit(1)
  102. print("All tests passed \\o/")
  103. if __name__ == "__main__":
  104. main()