-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·78 lines (60 loc) · 2.06 KB
/
test
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
#!/usr/bin/env python
import concurrent.futures
import os
import subprocess
import sys
failed_list = []
def test(software: str, python_version: str = "310"):
# Create test nix derivation
test_software_id = f".{software}_{python_version}.nix"
with open(test_software_id, "w") as f:
f.write(_t(software, python_version))
# Build derivation
name = f"{software} (py={python_version})"
space = 30 - len(name)
p = subprocess.run(["nix-build", f"{test_software_id}"], capture_output=True)
# What's the build state?
msg = f"Build '{name}':{' ' * space}"
if passed := (p.returncode == 0):
msg += "passed"
else:
msg += "failed"
print(msg)
if not passed:
s = "-" * 100
t = f"ERROR LOG {name}"
failed_text = f"{s}\n{s}\n\t{t}\n\n{p.stderr.decode()}\n\n{s}\n{s}\n"
failed_list.append(failed_text)
# Cleanup
os.remove(test_software_id)
return passed
def _t(software: str, python_version: str) -> str:
return rf"""{{}}:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {{}};
pythonPackages = pkgs.python{python_version}Packages;
in
import ./{software}/default.nix {{sources=sources;pkgs=pkgs;pythonPackages=pythonPackages;}}
"""
def run_tests(python_version: str = "310"):
print(f"\nTest with python {python_version}.\n")
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:
future_list = []
for d in os.listdir(r"./."):
if os.path.isdir(d) and os.path.exists(f"{d}/default.nix"):
future = pool.submit(test, d, python_version)
future_list.append(future)
try:
[f.result() for f in future_list]
except KeyboardInterrupt:
[f.cancel() for f in future_list]
raise
print("Run software compilation test...")
for python_version in "310 311 312".split(" "):
run_tests(python_version)
if failed_list:
print("\n".join(failed_list))
sys.exit(1)
print("All tests were successful.")
sys.exit(0)