-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtest.py
executable file
·92 lines (73 loc) · 2.56 KB
/
runtest.py
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
#!.venv/bin/python
# The shebang may point towards a venv, but GitHub CI executes python -m runtest
import os
import subprocess
import sys
import textwrap
import traceback
import unittest
from test.runtime import ResultAdapter, StyledStream
if __name__ == "__main__":
stream = sys.stdout
styled = StyledStream(stream)
def println(s: str = "") -> None:
if s:
stream.write(s)
stream.write("\n")
stream.flush()
println(styled.h1("1. Setup"))
println(styled.h2("PYTHONIOENCODING"))
println(os.environ.get("PYTHONIOENCODING", "n/a"))
if os.name == "nt":
println(styled.h2("PYTHONLEGACYWINDOWSFSENCODING"))
println(os.environ.get("PYTHONLEGACYWINDOWSFSENCODING", "n/a"))
println(styled.h2("PYTHONLEGACYWINDOWSSTDIO"))
println(os.environ.get("PYTHONLEGACYWINDOWSSTDIO", "n/a"))
println(styled.h2("PYTHONUTF8"))
println(os.environ.get("PYTHONUTF8", "n/a"))
println(styled.h2("Standard Out/Err Encoding"))
println(sys.stdout.encoding)
println(sys.stderr.encoding)
println(styled.h2("Python"))
println(f"{sys.executable}")
println(styled.h2("Python Prefix"))
println(f"{sys.prefix}")
println(f"{sys.base_prefix}")
println(styled.h2("Python Path"))
for path in sys.path:
println(f"{path}")
println(styled.h2("Current Directory"))
println(f"{os.getcwd()}")
println(styled.h2("Current Module"))
println(f"{__file__}")
println(styled.h1("2. Type Checking"))
if os.name == "nt":
println(textwrap.dedent(
"""
GitHub Actions on Windows seem gratuitously brittle. The console
encoding is CP1252 instead of UTF-8. Spawning a subprocess from
Python seemingly goes nowhere. So for now, there is no type checking
on Windows...
"""
))
else:
try:
subprocess.run(["npm", "run", "pyright"], check=True)
except subprocess.CalledProcessError:
println(styled.failure("prettypretty failed to type check!"))
exit(1)
println(styled.h1("3. Unit Testing"))
try:
runner = unittest.main(
module="test",
exit=False,
testRunner=unittest.TextTestRunner(
stream=stream, resultclass=ResultAdapter # type: ignore
),
)
sys.exit(not runner.result.wasSuccessful())
except Exception as x:
trace = traceback.format_exception(x)
println("".join(trace[:-1]))
println(styled.err(trace[-1]))
sys.exit(1)