-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrun-eptest.py
More file actions
129 lines (107 loc) · 4.13 KB
/
run-eptest.py
File metadata and controls
129 lines (107 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# This is an integration test, rather than a unit test.
# It should be run in a Python runtime that has been installed.
# The 'pymanager.exe' under test should be first on PATH
import json
import shutil
import subprocess
import sys
from pathlib import Path
EXIT_SETUP_FAILED = 1
EXIT_ALIAS_NOT_CREATED = 2
EXIT_ALIAS_INVALID = 3
CLEANUP = []
def run(*args, **kwargs):
print("##[command]", end="")
print(*args)
with subprocess.Popen(
args,
stdout=kwargs.pop("stdout", subprocess.PIPE),
stderr=kwargs.pop("stderr", subprocess.STDOUT),
encoding=kwargs.pop("encoding", "ascii"),
errors=kwargs.pop("errors", "replace"),
**kwargs,
) as p:
out, err = p.communicate(None)
if p.returncode:
raise subprocess.CalledProcessError(p.returncode, args, out, err)
return out, err
def main():
out, _ = run("pymanager", "list", "-f=json", "-q")
for install in json.loads(out)["versions"]:
if not install.get("unmanaged"):
break
else:
print("##[error]No suitable (managed) runtime found.")
sys.exit(EXIT_SETUP_FAILED)
print("Using", install["display-name"], "from", install["prefix"], "for test")
prefix = install["prefix"]
exe = install["executable"]
site = Path(prefix) / "Lib/site-packages"
if not site.is_dir():
print("##[error]Selected runtime has no site-packages folder.")
sys.exit(EXIT_SETUP_FAILED)
eptest_src = Path(__file__).parent / "eptestpackage"
if not eptest_src.is_dir():
print("##[error]eptestpackage is missing from test script location.")
sys.exit(EXIT_SETUP_FAILED)
dist_info = site / "eptestpackage-1.0.dist-info"
dist_info.mkdir(parents=True, exist_ok=True)
CLEANUP.append(lambda: shutil.rmtree(dist_info))
for f in (eptest_src / "eptestpackage.dist-info").glob("*"):
(dist_info / f.name).write_bytes(f.read_bytes())
(site / "eptestpackage.py").write_bytes((eptest_src / "eptestpackage.py").read_bytes())
CLEANUP.append((site / "eptestpackage.py").unlink)
print("Listing 'installed' packages (should include eptestpackage)")
print(*site.glob("*"), sep="\n")
print()
out, _ = run(exe, "-c", "import eptestpackage; eptestpackage.main()")
if out.strip() != "eptestpackage:main":
print(out)
print("##[error]Failed to import eptestpackage")
sys.exit(EXIT_SETUP_FAILED)
print("Confirmed eptestpackage is importable")
out, _ = run("pymanager", "list", "-f=config", "-q")
try:
config = json.loads(out)
except json.JSONDecodeError:
print("py list -f=config output:")
print(out)
raise
bin_dir = Path(config["global_dir"])
print(bin_dir)
refresh_log, _ = run("pymanager", "install", "--refresh", "-vv")
CLEANUP.append(lambda: run("pymanager", "install", "--refresh"))
print("Listing global aliases (should include eptest, eptestw, eptest-refresh)")
print(*bin_dir.glob("eptest*"), sep="\n")
for n in ["eptest.exe", "eptestw.exe", "eptest-refresh.exe"]:
if not (bin_dir / n).is_file():
print("--refresh log follows")
print(refresh_log)
print("##[error]Did not create", n)
sys.exit(EXIT_ALIAS_NOT_CREATED)
out, _ = run(bin_dir / "eptest.exe")
print(out)
if out.strip() != "eptestpackage:main":
print("##[error]eptest.exe alias failed")
sys.exit(EXIT_ALIAS_INVALID)
out, _ = run(bin_dir / "eptestw.exe")
print(out)
if out.strip() != "eptestpackage:mainw":
print("##[error]eptestw.exe alias failed")
sys.exit(EXIT_ALIAS_INVALID)
out, _ = run(bin_dir / "eptest-refresh.exe")
print(out)
if not out.strip().endswith("eptestpackage:do_refresh"):
print("##[error]eptest-refresh.exe alias failed")
sys.exit(EXIT_ALIAS_INVALID)
try:
main()
finally:
print("Beginning cleanup")
while CLEANUP:
try:
CLEANUP.pop()()
except subprocess.CalledProcessError as ex:
print("Subprocess failed during cleanup:")
print(ex.args, ex.returncode)
print(ex.output)