forked from zsol/dotslash-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
55 lines (49 loc) · 1.45 KB
/
test.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
import json
from pathlib import Path
import shutil
import sys
import subprocess
import traceback
def check_path(dotslash: str, path: Path) -> None:
contents = path.read_text()
_header, _, descriptor_text = contents.partition("\n")
descriptor = json.loads(descriptor_text)
assert isinstance(descriptor, dict)
name = descriptor["name"]
assert isinstance(name, str)
version = name.removeprefix("cpython-")
proc = subprocess.run(
[dotslash, path, "-c", "import sys; print(sys.version)"],
text=True,
capture_output=True,
check=True,
)
if not proc.stdout.startswith(version):
raise AssertionError(f"{version=} not found in {proc.stdout=}")
print(f"👌{path}")
def main() -> None:
dotslash = shutil.which("dotslash")
if dotslash is None:
print("Dotslash binary cannot be found, failing test.", file=sys.stderr)
sys.exit(-1)
args = sys.argv[1:]
descriptor_paths: list[Path] = []
for arg in args:
path = Path(arg)
if path.is_dir():
descriptor_paths.extend(path.glob("*"))
else:
descriptor_paths.append(path)
failure = False
for path in descriptor_paths:
try:
check_path(dotslash, Path(path))
except Exception:
failure = True
traceback.print_exc()
if failure:
print("🤔")
sys.exit(1)
print("🫡")
if __name__ == "__main__":
main()