Skip to content

Commit a322833

Browse files
committed
PR feedback
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 63e5726 commit a322833

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/tox/config/set_env.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@ def __init__( # noqa: C901, PLR0912
2424
from .loader.replacer import MatchExpression, find_replace_expr # noqa: PLC0415
2525

2626
if isinstance(raw, dict):
27-
# TOML 'file' attribute is to be handled separately later
28-
self._raw = dict(raw)
29-
if "file" in raw:
27+
self._raw = raw
28+
if "file" in raw: # environment files to be handled later
3029
self._env_files.append(raw["file"])
3130
self._raw.pop("file")
32-
3331
return
34-
3532
if isinstance(raw, list):
3633
self._raw = reduce(lambda a, b: {**a, **b}, raw)
3734
return
38-
3935
for line in raw.splitlines(): # noqa: PLR1702
4036
if line.strip():
41-
# INI 'file|' attribute is to be handled separately later
42-
if line.startswith("file|"):
37+
if line.startswith("file|"): # environment files to be handled later
4338
self._env_files.append(line[len("file|") :])
4439
else:
4540
try:

tests/config/test_set_env.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ def test_set_env_bad_line() -> None:
5151
SetEnv("A", "py", "py", Path())
5252

5353

54-
_ConfType = Literal["ini", "toml"]
54+
ConfigFileFormat = Literal["ini", "toml"]
5555

5656

5757
class EvalSetEnv(Protocol):
5858
def __call__(
5959
self,
6060
config: str,
61-
conf_type: _ConfType = "ini",
61+
*,
62+
of_type: ConfigFileFormat = "ini",
6263
extra_files: dict[str, Any] | None = ...,
6364
from_cwd: Path | None = ...,
6465
) -> SetEnv: ...
@@ -68,14 +69,12 @@ def __call__(
6869
def eval_set_env(tox_project: ToxProjectCreator) -> EvalSetEnv:
6970
def func(
7071
config: str,
71-
conf_type: _ConfType = "ini",
72+
*,
73+
of_type: ConfigFileFormat = "ini",
7274
extra_files: dict[str, Any] | None = None,
7375
from_cwd: Path | None = None,
7476
) -> SetEnv:
75-
if conf_type == "ini":
76-
prj = tox_project({"tox.ini": config, **(extra_files or {})})
77-
else:
78-
prj = tox_project({"tox.toml": config, **(extra_files or {})})
77+
prj = tox_project({f"tox.{of_type}": config, **(extra_files or {})})
7978
result = prj.run("c", "-k", "set_env", "-e", "py", from_cwd=None if from_cwd is None else prj.path / from_cwd)
8079
result.assert_success()
8180
set_env: SetEnv = result.env_conf("py")["set_env"]
@@ -162,17 +161,17 @@ def test_set_env_honor_override(eval_set_env: EvalSetEnv) -> None:
162161

163162

164163
@pytest.mark.parametrize(
165-
("conf_type", "config"),
164+
("of_type", "config"),
166165
[
167166
("ini", "[testenv]\npackage=skip\nset_env=file|A{/}a.txt\nchange_dir=C"),
168167
("toml", '[env_run_base]\npackage="skip"\nset_env={file="A{/}a.txt"}\nchange_dir="C"'),
169-
# Using monkeypatched env setting as a reference
168+
# Using monkeypatch env setting as a reference
170169
("ini", "[testenv]\npackage=skip\nset_env=file|{env:myenvfile}\nchange_dir=C"),
171170
("toml", '[env_run_base]\npackage="skip"\nset_env={file="{env:myenvfile}"}\nchange_dir="C"'),
172171
],
173172
)
174173
def test_set_env_environment_file(
175-
conf_type: _ConfType, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
174+
of_type: ConfigFileFormat, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
176175
) -> None:
177176
env_file = """
178177
A=1
@@ -186,7 +185,7 @@ def test_set_env_environment_file(
186185
monkeypatch.setenv("myenvfile", "A{/}a.txt")
187186

188187
extra = {"A": {"a.txt": env_file}, "B": None, "C": None}
189-
set_env = eval_set_env(config, conf_type=conf_type, extra_files=extra, from_cwd=Path("B"))
188+
set_env = eval_set_env(config, of_type=of_type, extra_files=extra, from_cwd=Path("B"))
190189
content = {k: set_env.load(k) for k in set_env}
191190
assert content == {
192191
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
@@ -201,7 +200,7 @@ def test_set_env_environment_file(
201200

202201

203202
@pytest.mark.parametrize(
204-
("conf_type", "config"),
203+
("of_type", "config"),
205204
[
206205
("ini", "[testenv]\npackage=skip\nset_env=file|A{/}a.txt\n X=y\nchange_dir=C"),
207206
("toml", '[env_run_base]\npackage="skip"\nset_env={file="A{/}a.txt", X="y"}\nchange_dir="C"'),
@@ -211,7 +210,7 @@ def test_set_env_environment_file(
211210
],
212211
)
213212
def test_set_env_environment_file_combined_with_normal_setting(
214-
conf_type: _ConfType, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
213+
of_type: ConfigFileFormat, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
215214
) -> None:
216215
env_file = """
217216
A=1
@@ -220,7 +219,7 @@ def test_set_env_environment_file_combined_with_normal_setting(
220219
monkeypatch.setenv("myenvfile", "A{/}a.txt")
221220

222221
extra = {"A": {"a.txt": env_file}, "B": None, "C": None}
223-
set_env = eval_set_env(config, conf_type=conf_type, extra_files=extra, from_cwd=Path("B"))
222+
set_env = eval_set_env(config, of_type=of_type, extra_files=extra, from_cwd=Path("B"))
224223
content = {k: set_env.load(k) for k in set_env}
225224
assert content == {
226225
"PIP_DISABLE_PIP_VERSION_CHECK": "1",

0 commit comments

Comments
 (0)