|
25 | 25 | from tox.session.state import State
|
26 | 26 |
|
27 | 27 |
|
28 |
| -@pytest.fixture() |
29 |
| -def exhaustive_ini(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path: |
30 |
| - to = tmp_path / "tox.ini" |
31 |
| - to.write_text( |
32 |
| - textwrap.dedent( |
33 |
| - """ |
34 |
| - [tox] |
35 |
| - colored = yes |
36 |
| - verbose = 5 |
37 |
| - quiet = 1 |
38 |
| - command = run-parallel |
39 |
| - env = py37, py36 |
40 |
| - default_runner = virtualenv |
41 |
| - recreate = true |
42 |
| - no_test = true |
43 |
| - parallel = 3 |
44 |
| - parallel_live = True |
45 |
| - override = |
46 |
| - a=b |
47 |
| - c=d |
48 |
| - """, |
49 |
| - ), |
50 |
| - ) |
51 |
| - monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to)) |
52 |
| - return to |
53 |
| - |
54 |
| - |
55 |
| -@pytest.mark.parametrize("content", ["[tox]", ""]) |
56 |
| -def test_ini_empty( # noqa: PLR0913 |
57 |
| - tmp_path: Path, |
58 |
| - core_handlers: dict[str, Callable[[State], int]], |
59 |
| - default_options: dict[str, Any], |
60 |
| - mocker: MockerFixture, |
61 |
| - monkeypatch: MonkeyPatch, |
62 |
| - content: str, |
63 |
| -) -> None: |
64 |
| - to = tmp_path / "tox.ini" |
65 |
| - monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to)) |
66 |
| - to.write_text(content) |
67 |
| - mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path())) |
68 |
| - options = get_options("r") |
69 |
| - assert vars(options.parsed) == default_options |
70 |
| - assert options.parsed.verbosity == 2 |
71 |
| - assert options.cmd_handlers == core_handlers |
72 |
| - |
73 |
| - to.unlink() |
74 |
| - missing_options = get_options("r") |
75 |
| - missing_options.parsed.hash_seed = ANY |
76 |
| - assert vars(missing_options.parsed) == vars(options.parsed) |
77 |
| - |
78 |
| - |
79 | 28 | @pytest.fixture()
|
80 | 29 | def default_options() -> dict[str, Any]:
|
81 | 30 | return {
|
@@ -110,56 +59,29 @@ def default_options() -> dict[str, Any]:
|
110 | 59 | }
|
111 | 60 |
|
112 | 61 |
|
113 |
| -def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None: |
114 |
| - with pytest.raises(SystemExit) as context: |
115 |
| - get_options("-h") |
116 |
| - assert context.value.code == 0 |
117 |
| - out, err = capfd.readouterr() |
118 |
| - assert not err |
119 |
| - res = out.splitlines()[-1] |
120 |
| - msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)" |
121 |
| - assert res == msg |
122 |
| - |
123 |
| - |
124 |
| -@pytest.mark.usefixtures("exhaustive_ini") |
125 |
| -def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State], int]]) -> None: |
126 |
| - options = get_options("p") |
127 |
| - assert vars(options.parsed) == { |
128 |
| - "colored": "yes", |
129 |
| - "command": "p", |
130 |
| - "default_runner": "virtualenv", |
131 |
| - "develop": False, |
132 |
| - "discover": [], |
133 |
| - "env": CliEnv(["py37", "py36"]), |
134 |
| - "hash_seed": ANY, |
135 |
| - "install_pkg": None, |
136 |
| - "no_test": True, |
137 |
| - "override": [Override("a=b"), Override("c=d")], |
138 |
| - "package_only": False, |
139 |
| - "no_recreate_pkg": False, |
140 |
| - "parallel": 3, |
141 |
| - "parallel_live": True, |
142 |
| - "parallel_no_spinner": False, |
143 |
| - "quiet": 1, |
144 |
| - "no_provision": False, |
145 |
| - "recreate": True, |
146 |
| - "no_recreate_provision": False, |
147 |
| - "result_json": None, |
148 |
| - "skip_missing_interpreters": "config", |
149 |
| - "skip_pkg_install": False, |
150 |
| - "verbose": 5, |
151 |
| - "work_dir": None, |
152 |
| - "root_dir": None, |
153 |
| - "config_file": None, |
154 |
| - "factors": [], |
155 |
| - "labels": [], |
156 |
| - "exit_and_dump_after": 0, |
157 |
| - "skip_env": "", |
158 |
| - "list_dependencies": is_ci(), |
159 |
| - } |
160 |
| - assert options.parsed.verbosity == 4 |
| 62 | +@pytest.mark.parametrize("content", ["[tox]", ""]) |
| 63 | +def test_ini_empty( # noqa: PLR0913 |
| 64 | + tmp_path: Path, |
| 65 | + core_handlers: dict[str, Callable[[State], int]], |
| 66 | + default_options: dict[str, Any], |
| 67 | + mocker: MockerFixture, |
| 68 | + monkeypatch: MonkeyPatch, |
| 69 | + content: str, |
| 70 | +) -> None: |
| 71 | + to = tmp_path / "tox.ini" |
| 72 | + monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to)) |
| 73 | + to.write_text(content) |
| 74 | + mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path())) |
| 75 | + options = get_options("r") |
| 76 | + assert vars(options.parsed) == default_options |
| 77 | + assert options.parsed.verbosity == 2 |
161 | 78 | assert options.cmd_handlers == core_handlers
|
162 | 79 |
|
| 80 | + to.unlink() |
| 81 | + missing_options = get_options("r") |
| 82 | + missing_options.parsed.hash_seed = ANY |
| 83 | + assert vars(missing_options.parsed) == vars(options.parsed) |
| 84 | + |
163 | 85 |
|
164 | 86 | def test_bad_cli_ini(
|
165 | 87 | tmp_path: Path,
|
@@ -244,3 +166,81 @@ def test_conf_arg(tmp_path: Path, conf_arg: str, filename: str, content: str) ->
|
244 | 166 | pos_args=[],
|
245 | 167 | source=source,
|
246 | 168 | )
|
| 169 | + |
| 170 | + |
| 171 | +@pytest.fixture() |
| 172 | +def exhaustive_ini(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path: |
| 173 | + to = tmp_path / "tox.ini" |
| 174 | + to.write_text( |
| 175 | + textwrap.dedent( |
| 176 | + """ |
| 177 | + [tox] |
| 178 | + colored = yes |
| 179 | + verbose = 5 |
| 180 | + quiet = 1 |
| 181 | + command = run-parallel |
| 182 | + env = py37, py36 |
| 183 | + default_runner = virtualenv |
| 184 | + recreate = true |
| 185 | + no_test = true |
| 186 | + parallel = 3 |
| 187 | + parallel_live = True |
| 188 | + override = |
| 189 | + a=b |
| 190 | + c=d |
| 191 | + """, |
| 192 | + ), |
| 193 | + ) |
| 194 | + monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to)) |
| 195 | + return to |
| 196 | + |
| 197 | + |
| 198 | +@pytest.mark.usefixtures("exhaustive_ini") |
| 199 | +def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State], int]]) -> None: |
| 200 | + options = get_options("p") |
| 201 | + assert vars(options.parsed) == { |
| 202 | + "colored": "yes", |
| 203 | + "command": "p", |
| 204 | + "default_runner": "virtualenv", |
| 205 | + "develop": False, |
| 206 | + "discover": [], |
| 207 | + "env": CliEnv(["py37", "py36"]), |
| 208 | + "hash_seed": ANY, |
| 209 | + "install_pkg": None, |
| 210 | + "no_test": True, |
| 211 | + "override": [Override("a=b"), Override("c=d")], |
| 212 | + "package_only": False, |
| 213 | + "no_recreate_pkg": False, |
| 214 | + "parallel": 3, |
| 215 | + "parallel_live": True, |
| 216 | + "parallel_no_spinner": False, |
| 217 | + "quiet": 1, |
| 218 | + "no_provision": False, |
| 219 | + "recreate": True, |
| 220 | + "no_recreate_provision": False, |
| 221 | + "result_json": None, |
| 222 | + "skip_missing_interpreters": "config", |
| 223 | + "skip_pkg_install": False, |
| 224 | + "verbose": 5, |
| 225 | + "work_dir": None, |
| 226 | + "root_dir": None, |
| 227 | + "config_file": None, |
| 228 | + "factors": [], |
| 229 | + "labels": [], |
| 230 | + "exit_and_dump_after": 0, |
| 231 | + "skip_env": "", |
| 232 | + "list_dependencies": is_ci(), |
| 233 | + } |
| 234 | + assert options.parsed.verbosity == 4 |
| 235 | + assert options.cmd_handlers == core_handlers |
| 236 | + |
| 237 | + |
| 238 | +def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None: |
| 239 | + with pytest.raises(SystemExit) as context: |
| 240 | + get_options("-h") |
| 241 | + assert context.value.code == 0 |
| 242 | + out, err = capfd.readouterr() |
| 243 | + assert not err |
| 244 | + res = out.splitlines()[-1] |
| 245 | + msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)" |
| 246 | + assert res == msg |
0 commit comments