forked from davesteele/comitup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtest.py
More file actions
executable file
·82 lines (53 loc) · 1.48 KB
/
devtest.py
File metadata and controls
executable file
·82 lines (53 loc) · 1.48 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
#!/usr/bin/python3
"""
devtest.py
This creates a virtual environment, and runs a number of test environments
against the comitup code.
The venv is persistent, so the tests run quicker than in tox or nox.
"""
import subprocess
import sys
import venv
from pathlib import Path
from typing import List
envpath: Path = Path(__file__).resolve().parent / ".devenv"
pythonpath: str = str(envpath / "bin" / "python")
pkgs: List[str] = [
"pytest",
"mypy",
"flake8",
"black",
"types-mock",
"types-tabulate",
"types-pkg_resources",
"types-Flask",
"types-cachetools",
]
targets: str = "comitup web cli test devtest.py setup.py"
def mkcmd(cmd: str) -> List[str]:
return [str(pythonpath), "-m"] + cmd.split()
def run(cmd: str) -> int:
cp = subprocess.run(mkcmd(cmd))
return cp.returncode
def runtest(test: str) -> int:
print("# Running {}".format(test.split()[0]))
return run(test)
print("# Tests starting")
if not envpath.exists():
print("# Creating virtual environment")
virtenv = venv.EnvBuilder(
system_site_packages=True, symlinks=True, with_pip=True
)
virtenv.create(str(envpath))
print("# Installing packages")
run("pip install " + " ".join(pkgs))
tests: List[str] = [
"pytest",
"mypy {}".format(targets),
"flake8 {}".format(targets),
"black --check {}".format(targets),
]
if any([runtest(test) for test in tests]):
print("# ERROR(S) ENCOUNTERED")
sys.exit(1)
print("# Tests complete")