This repository was archived by the owner on Mar 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtox.ini
More file actions
163 lines (148 loc) · 5.47 KB
/
tox.ini
File metadata and controls
163 lines (148 loc) · 5.47 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = lint, static, unit
[vars]
src_dir = {toxinidir}/src/
tst_dir = {toxinidir}/tests/
itst_dir = {toxinidir}/tests/integration
lib_dir = {toxinidir}/lib/charms/operator_libs_linux/
all_dir = {[vars]src_dir} {[vars]tst_dir} {[vars]lib_dir}
lxd_ubuntu = ops-libs-test-ubuntu
lxd_centos = ops-libs-test-centos
wait = 5
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_dir}
PYTHONBREAKPOINT=pdb.set_trace
PY_COLORS=1
passenv =
PYTHONPATH
CHARM_BUILD_DIR
MODEL_SETTINGS
[testenv:fmt]
description = Apply coding style standards to code
deps =
ruff==0.7.0
commands =
ruff check --preview --fix
ruff format --preview
[testenv:lint]
description = Check code against coding style standards
deps =
codespell==2.3.0
ruff==0.7.0
commands =
codespell {toxinidir}/ --toml={toxinidir}/pyproject.toml
ruff check --preview # --preview means include 'unstable' rules/fixes
ruff format --preview --diff
[testenv:static]
description = Run static type checker
allowlist_externals = echo
deps =
pyright==1.1.385
-r requirements.txt
commands =
#pyright {[vars]lib_dir} {posargs} # FIXME: enable static analysis of all libs
#pyright {[vars]test_dir} {posargs} # FIXME: enable static analysis of tests
echo 'NOTE: Only manually specified libs are being static type checked currently'
pyright lib/charms/operator_libs_linux/v0/apt.py {posargs}
pyright lib/charms/operator_libs_linux/v2/snap.py {posargs}
[testenv:unit]
description = Run unit tests
deps =
pytest
coverage[toml]
-r{toxinidir}/requirements.txt
pyfakefs==5.5.0
dbus-fast==1.90.2
allowlist_externals =
mkdir
commands_pre =
mkdir --parents .report # --parents allows the folder to already exist
commands =
coverage run --source={[vars]lib_dir} \
-m pytest \
--ignore={[vars]tst_dir}integration \
--tb native \
-v \
{posargs}
coverage xml -o .report/coverage.xml
coverage html --show-contexts
coverage report
[testenv:integration]
description = Build a LXD container for integration tests then run the tests
allowlist_externals =
lxc
bash
commands =
# Create a LXD containers for Ubuntu and CentOS with necessary packages installed.
# Note (rgildein): running integration tests on a VM because the grub library could not be used on containers
bash -c 'lxc launch --vm -qe ubuntu:focal {[vars]lxd_ubuntu} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
bash -c 'lxc launch --vm -qe images:centos/9-Stream/cloud {[vars]lxd_centos} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
bash -c 'while !(lxc exec {[vars]lxd_ubuntu} -- bash -c "echo ready"); do sleep {[vars]wait}; done'
bash -c 'while !(lxc exec {[vars]lxd_centos} -- bash -c "echo ready"); do sleep {[vars]wait}; done'
# Wait for the cloud-init process to finish in both Ubuntu and CentOS image
lxc exec {[vars]lxd_ubuntu} -- bash -c "cloud-init status -w >/dev/null 2>&1"
lxc exec {[vars]lxd_centos} -- bash -c "cloud-init status -w >/dev/null 2>&1"
# Make sure the latest snapd is available
lxc exec {[vars]lxd_ubuntu} -- bash -c "snap refresh snapd"
lxc exec {[vars]lxd_ubuntu} -- bash -c "systemctl restart snapd"
# Copy all the files needed for integration testing into instances.
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_ubuntu}/{[vars]lxd_ubuntu}/
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_centos}/{[vars]lxd_centos}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_centos}/{[vars]lxd_centos}/
# Run the tests.
lxc exec {[vars]lxd_ubuntu} -- tox -c /{[vars]lxd_ubuntu}/tox.ini -e integration-ubuntu {posargs}
lxc exec {[vars]lxd_centos} -- tox -c /{[vars]lxd_centos}/tox.ini -e integration-centos {posargs}
commands_post =
-lxc stop {[vars]lxd_ubuntu} {[vars]lxd_centos}
[testenv:integration-ubuntu]
description = Run integration tests for Ubuntu instance.
deps =
pytest
-r requirements.txt
commands =
pytest --ignore={[vars]tst_dir}unit \
--ignore={[vars]tst_dir}integration/test_dnf.py \
--ignore={[vars]tst_dir}integration/juju_systemd_notices \
--log-cli-level=INFO \
--tb native \
-v \
-s \
{posargs}
[testenv:integration-centos]
description = Run integration tests for CentOS instance.
deps =
pytest
-r requirements.txt
commands =
pytest --log-cli-level=INFO \
--tb native \
-v \
-s \
{[vars]tst_dir}integration/test_dnf.py \
{posargs}
[testenv:integration-juju-systemd-notices]
description = Run juju systemd notices integration tests.
deps =
pytest
pytest-order
jubilant
-r {toxinidir}/requirements.txt
passenv =
CHARM_PATH
commands =
pytest -v \
-s \
--tb native \
--log-cli-level=INFO \
{[vars]tst_dir}integration/juju_systemd_notices \
{posargs}