Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.cli.test_cli_ini: Re-order for clarity (textual moves only) #3209

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
198 changes: 99 additions & 99 deletions tests/config/cli/test_cli_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,6 @@
from tox.session.state import State


@pytest.fixture()
def exhaustive_ini(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path:
to = tmp_path / "tox.ini"
to.write_text(
textwrap.dedent(
"""
[tox]
colored = yes
verbose = 5
quiet = 1
command = run-parallel
env = py37, py36
default_runner = virtualenv
recreate = true
no_test = true
parallel = 3
parallel_live = True
override =
a=b
c=d
""",
),
)
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
return to


@pytest.mark.parametrize("content", ["[tox]", ""])
def test_ini_empty( # noqa: PLR0913
tmp_path: Path,
core_handlers: dict[str, Callable[[State], int]],
default_options: dict[str, Any],
mocker: MockerFixture,
monkeypatch: MonkeyPatch,
content: str,
) -> None:
to = tmp_path / "tox.ini"
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
to.write_text(content)
mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path()))
options = get_options("r")
assert vars(options.parsed) == default_options
assert options.parsed.verbosity == 2
assert options.cmd_handlers == core_handlers

to.unlink()
missing_options = get_options("r")
missing_options.parsed.hash_seed = ANY
assert vars(missing_options.parsed) == vars(options.parsed)


@pytest.fixture()
def default_options() -> dict[str, Any]:
return {
Expand Down Expand Up @@ -110,56 +59,29 @@ def default_options() -> dict[str, Any]:
}


def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None:
with pytest.raises(SystemExit) as context:
get_options("-h")
assert context.value.code == 0
out, err = capfd.readouterr()
assert not err
res = out.splitlines()[-1]
msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)"
assert res == msg


@pytest.mark.usefixtures("exhaustive_ini")
def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State], int]]) -> None:
options = get_options("p")
assert vars(options.parsed) == {
"colored": "yes",
"command": "p",
"default_runner": "virtualenv",
"develop": False,
"discover": [],
"env": CliEnv(["py37", "py36"]),
"hash_seed": ANY,
"install_pkg": None,
"no_test": True,
"override": [Override("a=b"), Override("c=d")],
"package_only": False,
"no_recreate_pkg": False,
"parallel": 3,
"parallel_live": True,
"parallel_no_spinner": False,
"quiet": 1,
"no_provision": False,
"recreate": True,
"no_recreate_provision": False,
"result_json": None,
"skip_missing_interpreters": "config",
"skip_pkg_install": False,
"verbose": 5,
"work_dir": None,
"root_dir": None,
"config_file": None,
"factors": [],
"labels": [],
"exit_and_dump_after": 0,
"skip_env": "",
"list_dependencies": is_ci(),
}
assert options.parsed.verbosity == 4
@pytest.mark.parametrize("content", ["[tox]", ""])
def test_ini_empty( # noqa: PLR0913
tmp_path: Path,
core_handlers: dict[str, Callable[[State], int]],
default_options: dict[str, Any],
mocker: MockerFixture,
monkeypatch: MonkeyPatch,
content: str,
) -> None:
to = tmp_path / "tox.ini"
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
to.write_text(content)
mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path()))
options = get_options("r")
assert vars(options.parsed) == default_options
assert options.parsed.verbosity == 2
assert options.cmd_handlers == core_handlers

to.unlink()
missing_options = get_options("r")
missing_options.parsed.hash_seed = ANY
assert vars(missing_options.parsed) == vars(options.parsed)


def test_bad_cli_ini(
tmp_path: Path,
Expand Down Expand Up @@ -244,3 +166,81 @@ def test_conf_arg(tmp_path: Path, conf_arg: str, filename: str, content: str) ->
pos_args=[],
source=source,
)


@pytest.fixture()
def exhaustive_ini(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path:
to = tmp_path / "tox.ini"
to.write_text(
textwrap.dedent(
"""
[tox]
colored = yes
verbose = 5
quiet = 1
command = run-parallel
env = py37, py36
default_runner = virtualenv
recreate = true
no_test = true
parallel = 3
parallel_live = True
override =
a=b
c=d
""",
),
)
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
return to


@pytest.mark.usefixtures("exhaustive_ini")
def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State], int]]) -> None:
options = get_options("p")
assert vars(options.parsed) == {
"colored": "yes",
"command": "p",
"default_runner": "virtualenv",
"develop": False,
"discover": [],
"env": CliEnv(["py37", "py36"]),
"hash_seed": ANY,
"install_pkg": None,
"no_test": True,
"override": [Override("a=b"), Override("c=d")],
"package_only": False,
"no_recreate_pkg": False,
"parallel": 3,
"parallel_live": True,
"parallel_no_spinner": False,
"quiet": 1,
"no_provision": False,
"recreate": True,
"no_recreate_provision": False,
"result_json": None,
"skip_missing_interpreters": "config",
"skip_pkg_install": False,
"verbose": 5,
"work_dir": None,
"root_dir": None,
"config_file": None,
"factors": [],
"labels": [],
"exit_and_dump_after": 0,
"skip_env": "",
"list_dependencies": is_ci(),
}
assert options.parsed.verbosity == 4
assert options.cmd_handlers == core_handlers


def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None:
with pytest.raises(SystemExit) as context:
get_options("-h")
assert context.value.code == 0
out, err = capfd.readouterr()
assert not err
res = out.splitlines()[-1]
msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)"
assert res == msg