-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
141 lines (109 loc) · 3.96 KB
/
tasks.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import itertools
import logging
try:
import tomllib as toml
except ImportError:
import tomli as toml
import invoke as inv
import tests.unit.tasks as ut
import tests.integration.tasks as it
import logging518.config
PROJECT_NAME = "mailpit-api-client"
DOCKER_COMPOSE_PATH = "tests/docker/docker-compose.yml"
logging518.config.fileConfig("pyproject.toml")
logger = logging.getLogger("test_runner.integration")
namespace = inv.Collection()
def read_pyproject_toml():
with open("pyproject.toml", "rb") as fp:
config = toml.load(fp)
return config["tool"]["invoke"]["test"]
def build_containers(c: inv.Context, profile: str):
config = read_pyproject_toml()
for python_version, debian_codename in itertools.product(
config["python_versions"], config["debian_codenames"]
):
project_name = (
f"{PROJECT_NAME}-{python_version.replace('.', '')}-{debian_codename}"
)
env = {"PYTHON_VERSION": python_version, "DEBIAN_CODENAME": debian_codename}
command = (
f"docker-compose -p {project_name} "
f"--profile {profile} -f {DOCKER_COMPOSE_PATH} build --pull"
)
print(command)
c.run(
command,
env=env,
pty=True,
)
def run(c, logger, profile, debian_codename, python_version, tool):
project_name = f"{PROJECT_NAME}-{python_version.replace('.', '')}"
env = {"PYTHON_VERSION": python_version, "DEBIAN_CODENAME": debian_codename}
logger.debug(f"set environment variables to: {env}")
ut.run_tool_in_container(c, env, profile, project_name, tool)
@inv.task
def checks(c: inv.Context):
logger.info("code checking started")
config = read_pyproject_toml()
profile = "checks"
for python_version, debian_codename, tool in itertools.product(
config["python_versions"], config["debian_codenames"], config["checkers"]
):
run(c, logger, profile, debian_codename, python_version, tool)
@inv.task
def unit(c: inv.Context):
logger.info("unit testing started")
config = read_pyproject_toml()
profile = "unittest"
tools = ["unittest"]
for python_version, debian_codename, tool in itertools.product(
config["python_versions"], config["debian_codenames"], tools
):
run(c, logger, profile, debian_codename, python_version, tool)
@inv.task
def integration(c: inv.Context):
logger.info("integration testing started")
config = read_pyproject_toml()
profile = "integration"
for python_version, debian_codename in itertools.product(
config["python_versions"], config["debian_codenames"]
):
logger.info(f"running with Python {python_version}")
logger.info(f"running with Debian {debian_codename}")
project_name = (
f"{PROJECT_NAME}"
f"-{python_version.replace('.', '')}"
f"-{debian_codename}"
)
env = {
"PYTHON_VERSION": python_version,
"PYTHONTRACEMALLOC": "1",
"DEBIAN_CODENAME": debian_codename,
}
logger.debug(f"set environment variables to: {env}")
it.start_mailpit_container(c, env, profile, project_name)
try:
it.run_tests(c, env, profile, project_name)
finally:
it.stop_mailpit_container(c, env, profile, project_name)
@inv.task
def build_checks(c: inv.Context):
build_containers(c, profile="checks")
@inv.task
def build_unittest(c: inv.Context):
build_containers(c, profile="unittest")
@inv.task
def build_integration(c: inv.Context):
build_containers(c, profile="integration")
tests = inv.Collection("tests")
tests.add_task(checks)
tests.add_task(unit)
tests.add_task(integration)
docker = inv.Collection("docker")
build = inv.Collection("build")
build.add_task(build_checks, "checks")
build.add_task(build_integration, name="integration")
build.add_task(build_unittest, name="unit")
docker.add_collection(build)
namespace.add_collection(tests)
namespace.add_collection(docker)