diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..96e27bd --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,119 @@ +import textwrap + +import pytest + +from utils import ( + DOT_TOX, + NATIVE_EXEC_PREFIX_MSG, + NATIVE_EXECUTABLE, + NATIVE_SITE_PACKAGES, + NATIVE_TOXENV, + TOX_VERSION, + TOX4, + envs_from_tox_ini, + modify_config, + expand_tox, + prep_tox_output, + tox, + tox_footer, +) + + +def test_native_toxenv_current_env(): + result = tox("-e", NATIVE_TOXENV, "--current-env") + assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG + assert not (DOT_TOX / NATIVE_TOXENV / "lib").is_dir() + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_deps(toxenv, print_deps_stdout_arg): + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = expand_tox(textwrap.dedent( + f""" + [[TOX4:tox]] + six + py + {tox_footer(toxenv)} + """ + ).lstrip()) + assert prep_tox_output(result.stdout) == expected + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) +def test_print_deps_with_commands_pre_post(projdir, toxenv, pre_post, print_deps_stdout_arg): + with modify_config(projdir / 'tox.ini') as config: + if pre_post == "both": + config["testenv"]["commands_pre"] = "echo unexpected" + config["testenv"]["commands_post"] = "echo unexpected" + else: + config["testenv"][f"commands_{pre_post}"] = "echo unexpected" + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = expand_tox(textwrap.dedent( + f""" + [[TOX4:tox]] + six + py + {tox_footer(toxenv)} + """ + ).lstrip()) + assert sorted(prep_tox_output(result.stdout).splitlines()) == sorted( + expected.splitlines() + ) + assert result.stderr == "" + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg): + with modify_config(projdir / "tox.ini") as config: + config["tox"]["minversion"] = "3.13" + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = textwrap.dedent( + f""" + tox>=3.13 + six + py + {tox_footer(toxenv)} + """ + ).lstrip() + assert prep_tox_output(result.stdout) == expected + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): + with modify_config(projdir / "tox.ini") as config: + config["tox"]["requires"] = "\n setuptools > 30\n pluggy" + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = expand_tox(textwrap.dedent( + f""" + setuptools>30 + pluggy + [[TOX4:tox]] + six + py + {tox_footer(toxenv)} + """ + ).lstrip()) + assert prep_tox_output(result.stdout) == expected + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_deps_with_tox_minversion_and_requires( + projdir, toxenv, print_deps_stdout_arg +): + with modify_config(projdir / "tox.ini") as config: + config["tox"]["minversion"] = "3.13" + config["tox"]["requires"] = "\n setuptools > 30\n pluggy" + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = expand_tox(textwrap.dedent( + f""" + [[TOX3:tox>=3.13]] + setuptools>30 + pluggy + [[TOX4:tox>=3.13]] + six + py + {tox_footer(toxenv)} + """ + ).lstrip()) + assert prep_tox_output(result.stdout) == expected diff --git a/tests/test_integration_tox3.py b/tests/test_integration_tox3.py index 0f5eb35..45c2be1 100644 --- a/tests/test_integration_tox3.py +++ b/tests/test_integration_tox3.py @@ -27,12 +27,6 @@ pytest.skip("skipping tests for tox 3", allow_module_level=True) -def test_native_toxenv_current_env(): - result = tox("-e", NATIVE_TOXENV, "--current-env") - assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG - assert not (DOT_TOX / NATIVE_TOXENV / "lib").is_dir() - - @needs_all_pythons def test_all_toxenv_current_env(): result = tox("--current-env", check=False) @@ -60,94 +54,6 @@ def test_all_toxenv_current_env_skip_missing(): assert result.returncode == 0 -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps(toxenv, print_deps_stdout_arg): - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert result.stdout == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) -def test_print_deps_with_commands_pre_post(projdir, toxenv, pre_post, print_deps_stdout_arg): - with modify_config(projdir / 'tox.ini') as config: - if pre_post == "both": - config["testenv"]["commands_pre"] = "echo unexpected" - config["testenv"]["commands_post"] = "echo unexpected" - else: - config["testenv"][f"commands_{pre_post}"] = "echo unexpected" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert result.stdout == expected - assert result.stderr == "" - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["minversion"] = "3.13" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - tox >= 3.13 - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert result.stdout == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["requires"] = "\n setuptools > 30\n pluggy" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - setuptools > 30 - pluggy - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert result.stdout == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_minversion_and_requires( - projdir, toxenv, print_deps_stdout_arg -): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["minversion"] = "3.13" - config["tox"]["requires"] = "\n setuptools > 30\n pluggy" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - tox >= 3.13 - setuptools > 30 - pluggy - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert result.stdout == expected - - @pytest.mark.parametrize("toxenv", envs_from_tox_ini()) def test_print_extras(toxenv, print_extras_stdout_arg): result = tox("-e", toxenv, print_extras_stdout_arg) diff --git a/tests/test_integration_tox4.py b/tests/test_integration_tox4.py index 90cf7df..0de2576 100644 --- a/tests/test_integration_tox4.py +++ b/tests/test_integration_tox4.py @@ -24,105 +24,6 @@ pytest.skip("skipping tests for tox 4", allow_module_level=True) -def test_native_toxenv_current_env(): - result = tox("-e", NATIVE_TOXENV, "--current-env") - assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG - assert not (DOT_TOX / NATIVE_TOXENV / "lib").is_dir() - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps(toxenv, print_deps_stdout_arg): - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - tox - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert prep_tox_output(result.stdout) == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) -def test_print_deps_with_commands_pre_post(projdir, toxenv, pre_post, print_deps_stdout_arg): - with modify_config(projdir / 'tox.ini') as config: - if pre_post == "both": - config["testenv"]["commands_pre"] = "echo unexpected" - config["testenv"]["commands_post"] = "echo unexpected" - else: - config["testenv"][f"commands_{pre_post}"] = "echo unexpected" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - tox - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert sorted(prep_tox_output(result.stdout).splitlines()) == sorted( - expected.splitlines() - ) - assert result.stderr == "" - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["minversion"] = "3.13" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - tox>=3.13 - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert prep_tox_output(result.stdout) == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["requires"] = "\n setuptools > 30\n pluggy" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - setuptools>30 - pluggy - tox - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert prep_tox_output(result.stdout) == expected - - -@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) -def test_print_deps_with_tox_minversion_and_requires( - projdir, toxenv, print_deps_stdout_arg -): - with modify_config(projdir / "tox.ini") as config: - config["tox"]["minversion"] = "3.13" - config["tox"]["requires"] = "\n setuptools > 30\n pluggy" - result = tox("-e", toxenv, print_deps_stdout_arg) - expected = textwrap.dedent( - f""" - setuptools>30 - pluggy - tox>=3.13 - six - py - {tox_footer(toxenv)} - """ - ).lstrip() - assert prep_tox_output(result.stdout) == expected - - @pytest.mark.parametrize("toxenv", envs_from_tox_ini()) def test_print_extras(toxenv, print_extras_stdout_arg): result = tox("-e", toxenv, print_extras_stdout_arg) diff --git a/tests/utils.py b/tests/utils.py index fe7fbcf..0cad923 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -117,10 +117,36 @@ def tox_footer(envs=None, spaces=8): def prep_tox_output(output): - """Remove time info from tox output""" - result = re.sub(r" \((\d+\.\d+|\d+) seconds\)", "", output) - result = re.sub(r" ✔ in (\d+\.\d+|\d+) seconds", "", result) - return result + """Remove time info from tox 4 output. + Strip spaces around operators in tox 3 output.""" + if TOX4: + output = re.sub(r" \((\d+\.\d+|\d+) seconds\)", "", output) + output = re.sub(r" ✔ in (\d+\.\d+|\d+) seconds", "", output) + else: + output = re.sub(" ((<|>)=?) ", r"\1", output) + return output + + +def expand_tox(text): + """Replace [[TOX4:...]] and [[TOX3:...]] expressions, + empty liens are stripped if created.""" + source_lines = text.splitlines() + out_lines = [] + for line in source_lines: + if not line: + out_lines.append(line) + continue + if TOX4: + line = re.sub(r"\[\[TOX3:[^\]]*\]\]", "", line) + line = re.sub(r"\[\[TOX4:([^\]]*)\]\]", r"\1", line) + else: + line = re.sub(r"\[\[TOX4:[^\]]*\]\]", "", line) + line = re.sub(r"\[\[TOX3:([^\]]*)\]\]", r"\1", line) + if line: + out_lines.append(line) + if text[-1] == "\n": + out_lines.append("") + return "\n".join(out_lines) needs_all_pythons = pytest.mark.skipif(