-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·97 lines (78 loc) · 2.21 KB
/
test.py
File metadata and controls
executable file
·97 lines (78 loc) · 2.21 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
#! /usr/bin/env python3
from __future__ import annotations
import os
import platform
import shutil
import subprocess as sp
from pathlib import Path
def get_git_user_info() -> tuple[str, str]:
try:
name = sp.check_output(
["git", "config", "user.name"],
text=True
).strip()
email = sp.check_output(
["git", "config", "user.email"],
text=True
).strip()
return name, email
except sp.CalledProcessError:
author_name, author_email = get_git_user_info()
DATA = {
"author_email": author_email,
"author_name": author_name,
"package_name": "baz",
"project_name": "Foo",
"project_slug": "foo",
"system": platform.system(),
}
TEST_DIR = "test"
def run(*args: str, **kwargs) -> sp.CompletedProcess:
return sp.run(args, check=True, **kwargs)
def data() -> list[str]:
return [x for key, value in DATA.items() for x in ("--data", f"{key}={value}")]
def main() -> None:
root = Path(__file__).resolve().parent
test_dir = root / TEST_DIR
os.chdir(root)
if test_dir.is_dir():
for item in test_dir.iterdir():
if item.is_dir():
shutil.rmtree(item)
else:
item.unlink()
run(
"copier",
"copy",
*data(),
"template",
TEST_DIR,
)
os.chdir(root / TEST_DIR)
try:
run("uv", "sync")
run("uv", "run", DATA["package_name"])
run("poe", DATA["package_name"])
run("poe", "check")
run("poe", "files")
run("poe", "test", "--cov")
run("poe", "zipapp")
run("git", "init")
run("pre-commit", "install")
run("git", "add", ".")
run("git", "config", "user.name", "User")
run("git", "commit", "-a", "-m", "Initial commit")
finally:
venv_path = Path(".venv")
if venv_path.exists():
shutil.rmtree(venv_path)
try:
run("tox")
finally:
tox_path = Path(".tox")
if tox_path.exists():
shutil.rmtree(tox_path)
if __name__ == "__main__":
main()