lucy-python-script-2030 0.1.0__py3-none-any.whl

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