Skip to content

Commit 6e6dafc

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

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
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: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ 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+
conf_type: ConfigFileFormat = "ini",
6262
extra_files: dict[str, Any] | None = ...,
6363
from_cwd: Path | None = ...,
6464
) -> SetEnv: ...
@@ -68,14 +68,11 @@ def __call__(
6868
def eval_set_env(tox_project: ToxProjectCreator) -> EvalSetEnv:
6969
def func(
7070
config: str,
71-
conf_type: _ConfType = "ini",
71+
conf_type: ConfigFileFormat = "ini",
7272
extra_files: dict[str, Any] | None = None,
7373
from_cwd: Path | None = None,
7474
) -> 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 {})})
75+
prj = tox_project({f"tox.{conf_type}": config, **(extra_files or {})})
7976
result = prj.run("c", "-k", "set_env", "-e", "py", from_cwd=None if from_cwd is None else prj.path / from_cwd)
8077
result.assert_success()
8178
set_env: SetEnv = result.env_conf("py")["set_env"]
@@ -172,7 +169,7 @@ def test_set_env_honor_override(eval_set_env: EvalSetEnv) -> None:
172169
],
173170
)
174171
def test_set_env_environment_file(
175-
conf_type: _ConfType, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
172+
conf_type: ConfigFileFormat, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
176173
) -> None:
177174
env_file = """
178175
A=1
@@ -211,7 +208,7 @@ def test_set_env_environment_file(
211208
],
212209
)
213210
def test_set_env_environment_file_combined_with_normal_setting(
214-
conf_type: _ConfType, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
211+
conf_type: ConfigFileFormat, config: str, eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch
215212
) -> None:
216213
env_file = """
217214
A=1

0 commit comments

Comments
 (0)