-
-
Notifications
You must be signed in to change notification settings - Fork 576
Expand file tree
/
Copy pathtest_toml_tox.py
More file actions
177 lines (144 loc) · 5.85 KB
/
Copy pathtest_toml_tox.py
File metadata and controls
177 lines (144 loc) · 5.85 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from __future__ import annotations
import sys
import textwrap
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import pytest
from tox.pytest import ToxProjectCreator
def test_config_in_toml_core(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
env_list = [ "A", "B"]
[env_run_base]
description = "Do magical things"
commands = [
["python", "--version"],
["python", "-c", "import sys; print(sys.executable)"]
]
"""
})
outcome = project.run("c", "--core")
outcome.assert_success()
assert "# Exception: " not in outcome.out, outcome.out
assert "# !!! unused: " not in outcome.out, outcome.out
def test_config_in_toml_non_default(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[env.C]
description = "Do magical things in C"
commands = [
["python", "--version"]
]
"""
})
outcome = project.run("c", "-e", "C", "--core")
outcome.assert_success()
assert "# Exception: " not in outcome.out, outcome.out
assert "# !!! unused: " not in outcome.out, outcome.out
def test_config_in_toml_extra(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[env_run_base]
description = "Do magical things"
commands = [
["python", "--version"]
]
"""
})
outcome = project.run("c", "-e", ".".join(str(i) for i in sys.version_info[0:2]))
outcome.assert_success()
assert "# Exception: " not in outcome.out, outcome.out
assert "# !!! unused: " not in outcome.out, outcome.out
def test_config_in_toml_replace_default(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.toml": '[env_run_base]\ndescription = "{missing:miss}"'})
outcome = project.run("c", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:py]\ndescription = miss\n", "")
def test_config_in_toml_replace_env_name_via_env(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.toml": '[env_run_base]\ndescription = "Magic in {env:MAGICAL:{env_name}}"'})
outcome = project.run("c", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:py]\ndescription = Magic in py\n", "")
def test_config_in_toml_replace_env_name_via_env_set(
tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("MAGICAL", "YEAH")
project = tox_project({"tox.toml": '[env_run_base]\ndescription = "Magic in {env:MAGICAL:{env_name}}"'})
outcome = project.run("c", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:py]\ndescription = Magic in YEAH\n", "")
def test_config_in_toml_replace_from_env_section_absolute(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[env.A]
description = "a"
[env.B]
description = "{[env.A]env_name}"
"""
})
outcome = project.run("c", "-e", "B", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:B]\ndescription = A\n", "")
def test_config_in_toml_replace_from_section_absolute(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[extra]
ok = "o"
[env.B]
description = "{[extra]ok}"
"""
})
outcome = project.run("c", "-e", "B", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:B]\ndescription = o\n", "")
def test_config_in_toml_env_list_bare_labeled_factor_description(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
env_list = [
{ ecosystem = ["oci", "python"] },
]
[env_run_base]
package = "skip"
description = "Sync {factor:ecosystem} artifacts"
commands = [["python", "-c", "print('ok')"]]
"""),
})
outcome = project.run("c", "-e", "oci", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:oci]\ndescription = Sync oci artifacts\n", "")
outcome = project.run("c", "-e", "python", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:python]\ndescription = Sync python artifacts\n", "")
def test_config_in_toml_env_list_bare_labeled_factor_default(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
env_list = [
{ ecosystem = { values = ["oci", "python"], default = "oci" } },
]
[env_run_base]
package = "skip"
[env.lint]
description = "Lint {factor:ecosystem} artifacts"
"""),
})
outcome = project.run("c", "-e", "lint", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:lint]\ndescription = Lint oci artifacts\n", "")
def test_config_in_toml_env_list_keyed_factor_description(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
env_list = [
{ product = [["sync"], {ecosystem = ["oci", "python"]}, {target = ["pw", "tt"]}] },
]
[env_run_base]
package = "skip"
description = "Sync {factor:ecosystem} to {factor:target}"
commands = [["python", "-c", "print('ok')"]]
"""),
})
outcome = project.run("c", "-e", "sync-oci-pw", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:sync-oci-pw]\ndescription = Sync oci to pw\n", "")
outcome = project.run("c", "-e", "sync-python-tt", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:sync-python-tt]\ndescription = Sync python to tt\n", "")