mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2024-12-24 00:56:16 +01:00
WIP common tests
Fixes https://github.com/fedora-python/tox-current-env/issues/60
This commit is contained in:
parent
843dee6288
commit
b12be8cbe9
119
tests/test_integration.py
Normal file
119
tests/test_integration.py
Normal file
@ -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
|
@ -27,12 +27,6 @@ if TOX_VERSION.major != 3:
|
||||
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)
|
||||
|
@ -24,105 +24,6 @@ if TOX_VERSION.major != 4:
|
||||
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)
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user