pywin32_testall.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """A test runner for pywin32"""
  2. import sys
  3. import os
  4. import site
  5. import subprocess
  6. import win32api
  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. sys.stdout.buffer.write(data)
  22. if popen.returncode:
  23. print("****** %s failed: %s" % (script, popen.returncode))
  24. sys.exit(popen.returncode)
  25. def find_and_run(possible_locations, script, cmdline_rest=""):
  26. for maybe in possible_locations:
  27. if os.path.isfile(os.path.join(maybe, script)):
  28. run_test(os.path.abspath(os.path.join(maybe, script)), cmdline_rest)
  29. break
  30. else:
  31. raise RuntimeError("Failed to locate the test script '%s' in one of %s"
  32. % (script, possible_locations))
  33. if __name__ == '__main__':
  34. import argparse
  35. code_directories = [this_dir] + site_packages
  36. parser = argparse.ArgumentParser(description="A script to trigger tests in all subprojects of PyWin32.")
  37. parser.add_argument("-no-user-interaction",
  38. default=False,
  39. action='store_true',
  40. help="Run all tests without user interaction")
  41. args = parser.parse_args()
  42. # win32
  43. maybes = [os.path.join(directory, "win32", "test") for directory in code_directories]
  44. command = ('testall.py', )
  45. if args.no_user_interaction:
  46. command += ("-no-user-interaction", )
  47. find_and_run(maybes, *command)
  48. # win32com
  49. maybes = [os.path.join(directory, "win32com", "test") for directory in [os.path.join(this_dir, "com"), ] + site_packages]
  50. find_and_run(maybes, 'testall.py', "2")
  51. # adodbapi
  52. maybes = [os.path.join(directory, "adodbapi", "test") for directory in code_directories]
  53. find_and_run(maybes, 'adodbapitest.py')
  54. # This script has a hard-coded sql server name in it, (and markh typically
  55. # doesn't have a different server to test on) so don't bother trying to
  56. # run it...
  57. # find_and_run(maybes, 'test_adodbapi_dbapi20.py')
  58. if sys.version_info > (3,):
  59. print("** The tests have some issues on py3k - not all failures are a problem...")