pywin32_testall.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """A test runner for pywin32"""
  2. from __future__ import print_function
  3. import sys
  4. import os
  5. import site
  6. import subprocess
  7. # locate the dirs based on where this script is - it may be either in the
  8. # source tree, or in an installed Python 'Scripts' tree.
  9. this_dir = os.path.dirname(__file__)
  10. site_packages = [site.getusersitepackages(), ] + site.getsitepackages()
  11. # Run a test using subprocess and wait for the result.
  12. # If we get an returncode != 0, we know that there was an error.
  13. def run_test(script, cmdline_rest=""):
  14. dirname, scriptname = os.path.split(script)
  15. # some tests prefer to be run from their directory.
  16. cmd = [sys.executable, "-u", scriptname] + cmdline_rest.split()
  17. print(script)
  18. popen = subprocess.Popen(cmd, shell=True, cwd=dirname,
  19. stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  20. data = popen.communicate()[0]
  21. if sys.version_info > (3,):
  22. sys.stdout.write(data.decode('latin-1'))
  23. else:
  24. sys.stdout.write(data)
  25. sys.stdout.flush()
  26. if popen.returncode:
  27. print("****** %s failed: %s" % (script, popen.returncode))
  28. sys.exit(popen.returncode)
  29. def find_and_run(possible_locations, script, cmdline_rest=""):
  30. for maybe in possible_locations:
  31. if os.path.isfile(os.path.join(maybe, script)):
  32. run_test(os.path.abspath(os.path.join(maybe, script)), cmdline_rest)
  33. break
  34. else:
  35. raise RuntimeError("Failed to locate the test script '%s' in one of %s"
  36. % (script, possible_locations))
  37. if __name__ == '__main__':
  38. import argparse
  39. code_directories = [this_dir] + site_packages
  40. parser = argparse.ArgumentParser(description="A script to trigger tests in all subprojects of PyWin32.")
  41. parser.add_argument("-no-user-interaction",
  42. default=False,
  43. action='store_true',
  44. help="Run all tests without user interaction")
  45. args = parser.parse_args()
  46. # win32
  47. maybes = [os.path.join(directory, "win32", "test") for directory in code_directories]
  48. command = ('testall.py', )
  49. if args.no_user_interaction:
  50. command += ("-no-user-interaction", )
  51. find_and_run(maybes, *command)
  52. # win32com
  53. maybes = [os.path.join(directory, "win32com", "test") for directory in [os.path.join(this_dir, "com"), ] + site_packages]
  54. find_and_run(maybes, 'testall.py', "2")
  55. # adodbapi
  56. maybes = [os.path.join(directory, "adodbapi", "test") for directory in code_directories]
  57. find_and_run(maybes, 'adodbapitest.py')
  58. # This script has a hard-coded sql server name in it, (and markh typically
  59. # doesn't have a different server to test on) but there is now supposed to be a server out there on the Internet
  60. # just to run these tests, so try it...
  61. find_and_run(maybes, 'test_adodbapi_dbapi20.py')
  62. if sys.version_info > (3,):
  63. print("** The tests have some issues on py3k - not all failures are a problem...")