From a0416f22d3ab77fcbc7c406ca68a8f53e7ab50eb Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Thu, 13 Jun 2024 15:29:03 -0700 Subject: [PATCH] Add pip upgrade (#333) --- pyproject.toml | 2 +- src/tox_ansible/plugin.py | 9 ++++++++- tests/unit/test_plugin.py | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_plugin.py diff --git a/pyproject.toml b/pyproject.toml index 45a6bce..26945d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ line-length = 100 [tool.coverage.report] exclude_also = ["if TYPE_CHECKING:", "pragma: no cover"] -fail_under = 75 +fail_under = 82 ignore_errors = true show_missing = true skip_covered = true diff --git a/src/tox_ansible/plugin.py b/src/tox_ansible/plugin.py index 3583051..ffc6122 100644 --- a/src/tox_ansible/plugin.py +++ b/src/tox_ansible/plugin.py @@ -449,7 +449,7 @@ def conf_commands_for_sanity( return commands -def conf_commands_pre( +def conf_commands_pre( # noqa: C901 env_conf: EnvConfigSet, c_name: str, c_namespace: str, @@ -473,6 +473,13 @@ def conf_commands_pre( galaxy_build_dir = f"{envtmpdir}/collection_build" end_group = "echo ::endgroup::" + if in_action(): + group = "echo ::group::Ensure pip is up to date" + commands.append(group) + commands.append("python -m ensurepip --upgrade") + if in_action(): + commands.append(end_group) + if in_action(): group = "echo ::group::Make the galaxy build dir" commands.append(group) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py new file mode 100644 index 0000000..9e365c5 --- /dev/null +++ b/tests/unit/test_plugin.py @@ -0,0 +1,42 @@ +"""Unit plugin tests.""" + +from pathlib import Path + +import pytest + +from tox.config.cli.parser import Parsed +from tox.config.main import Config +from tox.config.source import discover_source + +from tox_ansible.plugin import conf_commands_pre + + +def test_commands_pre(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: + """Test pre-command generation. + + Args: + monkeypatch: Pytest fixture. + tmp_path: Pytest fixture. + """ + monkeypatch.setenv("GITHUB_ACTIONS", "true") + + ini_file = tmp_path / "tox.ini" + ini_file.touch() + source = discover_source(ini_file, None) + + conf = Config.make( + Parsed(work_dir=tmp_path, override=[], config_file=ini_file, root_dir=tmp_path), + pos_args=[], + source=source, + ).get_env("py39") + + conf.add_config( + keys=["env_tmp_dir", "envtmpdir"], + of_type=Path, + default=tmp_path, + desc="", + ) + + result = conf_commands_pre(env_conf=conf, c_name="test", c_namespace="test") + number_commands = 15 + assert len(result) == number_commands, result