-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·48 lines (39 loc) · 1.89 KB
/
run_tests.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
#!/usr/bin/env python3
from typing import List
import sys, subprocess
import shell_adventure, build_image
from shell_adventure.host_side import docker_helper
PROJ_PATH = shell_adventure.PKG_PATH.parent
args = sys.argv[1:]
def header(message: str):
# Using flush fixes an issue in GitHub actions where prints and output from subprocesses get out of order in the report
print(f"\n{f' {message} '.center(45, '=')}\n", flush = True)
def run(command: List[str]):
return subprocess.run(command, stdout=sys.stdout).returncode
if __name__ == "__main__":
header("Building Images")
# Build the docker image locally (in case it has been modified locally since last release)
build_image.build_image()
# Build all the images in tests/docker_images
for dockerfile in PROJ_PATH.glob("tests/docker_images/Dockerfile.tests.*"):
tag = dockerfile.suffix[1:]
docker_helper.client.images.build(
path = str(PROJ_PATH / "tests/docker_images"),
dockerfile = str(dockerfile.name),
tag = f"shelladventure/tests:{tag}",
rm = True, # Remove intermediate containers
)
print("Done!", flush = True)
header("MyPy Analysis")
if run(["mypy"]) != 0: exit(1) # quit if mypy fails
header("Tests in Docker Container")
# Also makes a ".coverage" report in cwd
dockerTests = run(["python3", "-m", "tests.run_docker_tests", *args])
header("Main Tests")
# Merge coverage report with report from container
mainTests = run(["python3", "-m", "pytest", "--cov", "--cov-report=", "--cov-append", *args])
# Output html report
# Coverage reports are somewhat incomplete as we don't have a good way to track the code that gets run in the container
# during integration tests, since the container is launched and closed during the test.
run(["coverage", "html"])
exit(0 if dockerTests == 0 and mainTests == 0 else 1)