2019-07-23 14:49:13 +02:00
|
|
|
import functools
|
2019-07-17 18:28:54 +02:00
|
|
|
import os
|
|
|
|
import pathlib
|
2020-09-11 14:42:56 +02:00
|
|
|
import re
|
2019-07-17 18:28:54 +02:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2019-07-18 11:33:42 +02:00
|
|
|
import textwrap
|
2020-09-15 14:16:40 +02:00
|
|
|
import warnings
|
2019-07-17 18:28:54 +02:00
|
|
|
|
2019-08-01 14:46:01 +02:00
|
|
|
from packaging import version
|
|
|
|
|
2019-07-17 18:28:54 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
NATIVE_TOXENV = f"py{sys.version_info[0]}{sys.version_info[1]}"
|
|
|
|
NATIVE_EXECUTABLE = str(pathlib.Path(sys.executable).resolve())
|
2020-08-11 17:07:58 +02:00
|
|
|
NATIVE_EXEC_PREFIX = str(pathlib.Path(sys.exec_prefix).resolve())
|
|
|
|
NATIVE_EXEC_PREFIX_MSG = f"{NATIVE_EXEC_PREFIX} is the exec_prefix"
|
2019-10-21 12:37:19 +02:00
|
|
|
FIXTURES_DIR = pathlib.Path(__file__).parent / "fixtures"
|
|
|
|
DOT_TOX = pathlib.Path("./.tox")
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2019-10-21 12:37:19 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def projdir(tmp_path, monkeypatch):
|
|
|
|
pwd = tmp_path / "projdir"
|
|
|
|
pwd.mkdir()
|
|
|
|
for fname in "tox.ini", "setup.py":
|
|
|
|
shutil.copy(FIXTURES_DIR / fname, pwd)
|
|
|
|
monkeypatch.chdir(pwd)
|
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
@pytest.fixture(params=('--print-deps-only', '--print-deps-to-file=-', '--print-deps-to=-'))
|
|
|
|
def print_deps_stdout_arg(request):
|
|
|
|
"""Argument for printing deps to stdout"""
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2020-09-11 14:42:56 +02:00
|
|
|
def tox(*args, quiet=True, **kwargs):
|
2019-07-17 18:28:54 +02:00
|
|
|
kwargs.setdefault("encoding", "utf-8")
|
|
|
|
kwargs.setdefault("stdout", subprocess.PIPE)
|
|
|
|
kwargs.setdefault("stderr", subprocess.PIPE)
|
|
|
|
kwargs.setdefault("check", True)
|
2020-09-11 14:42:56 +02:00
|
|
|
q = ("-q",) if quiet else ()
|
2020-09-11 15:23:29 +02:00
|
|
|
try:
|
|
|
|
cp = subprocess.run((sys.executable, "-m", "tox") + q + args, **kwargs)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e.stdout, file=sys.stdout)
|
|
|
|
print(e.stderr, file=sys.stderr)
|
|
|
|
raise
|
2019-07-17 18:28:54 +02:00
|
|
|
print(cp.stdout, file=sys.stdout)
|
|
|
|
print(cp.stderr, file=sys.stderr)
|
|
|
|
return cp
|
|
|
|
|
|
|
|
|
2019-07-23 14:49:13 +02:00
|
|
|
@functools.lru_cache(maxsize=8)
|
2019-07-23 14:37:06 +02:00
|
|
|
def is_available(python):
|
|
|
|
try:
|
|
|
|
subprocess.run((python, "--version"))
|
|
|
|
except FileNotFoundError:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2019-08-01 14:46:01 +02:00
|
|
|
TOX_VERSION = version.parse(tox("--version").stdout.split(" ")[0])
|
2020-08-12 17:04:58 +02:00
|
|
|
TOX313 = TOX_VERSION < version.parse("3.14")
|
|
|
|
|
2019-08-01 14:46:01 +02:00
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
needs_py36789 = pytest.mark.skipif(
|
|
|
|
not all((is_available(f"python3.{x}") for x in range(6, 10))),
|
|
|
|
reason="This test needs python3.6, 3.7, 3.8 and 3.9 available in $PATH",
|
2019-07-23 14:49:13 +02:00
|
|
|
)
|
|
|
|
|
2019-08-01 14:46:01 +02:00
|
|
|
|
2019-07-23 14:49:13 +02:00
|
|
|
|
2019-07-17 18:28:54 +02:00
|
|
|
def test_native_toxenv_current_env():
|
|
|
|
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG
|
2019-07-18 11:06:48 +02:00
|
|
|
assert not (DOT_TOX / NATIVE_TOXENV / "lib").is_dir()
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
@needs_py36789
|
2019-07-17 18:28:54 +02:00
|
|
|
def test_all_toxenv_current_env():
|
|
|
|
result = tox("--current-env", check=False)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert NATIVE_EXEC_PREFIX_MSG in result.stdout.splitlines()
|
2019-07-17 18:28:54 +02:00
|
|
|
assert result.stdout.count("InterpreterMismatch:") >= 2
|
|
|
|
assert result.returncode > 0
|
|
|
|
|
|
|
|
|
2019-07-23 14:37:06 +02:00
|
|
|
@pytest.mark.parametrize("python", ["python3.4", "python3.5"])
|
|
|
|
def test_missing_toxenv_current_env(python):
|
|
|
|
if is_available(python):
|
|
|
|
pytest.skip(f"Only works if {python} is not available in $PATH")
|
|
|
|
env = python.replace("python", "py").replace(".", "")
|
|
|
|
result = tox("-e", env, "--current-env", check=False)
|
|
|
|
assert f"InterpreterNotFound: {python}" in result.stdout
|
|
|
|
assert "Traceback" not in (result.stderr + result.stdout)
|
|
|
|
assert result.returncode > 0
|
|
|
|
|
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
@needs_py36789
|
2019-07-17 18:28:54 +02:00
|
|
|
def test_all_toxenv_current_env_skip_missing():
|
|
|
|
result = tox("--current-env", "--skip-missing-interpreters", check=False)
|
|
|
|
assert "InterpreterMismatch:" in result.stdout
|
|
|
|
assert "congratulations" in result.stdout
|
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
@pytest.mark.parametrize("toxenv", ["py36", "py37", "py38", "py39"])
|
2020-09-15 14:16:40 +02:00
|
|
|
def test_print_deps(toxenv, print_deps_stdout_arg):
|
|
|
|
result = tox("-e", toxenv, print_deps_stdout_arg)
|
2019-07-18 11:33:42 +02:00
|
|
|
expected = textwrap.dedent(
|
|
|
|
f"""
|
|
|
|
six
|
|
|
|
py
|
|
|
|
___________________________________ summary ____________________________________
|
|
|
|
{toxenv}: commands succeeded
|
|
|
|
congratulations :)
|
|
|
|
"""
|
|
|
|
).lstrip()
|
|
|
|
assert result.stdout == expected
|
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
@pytest.mark.parametrize("toxenv", ["py36", "py37", "py38", "py39"])
|
|
|
|
def test_print_deps_only_deprecated(toxenv):
|
|
|
|
result = tox(
|
|
|
|
"-e", toxenv, '--print-deps-only',
|
|
|
|
env={**os.environ, 'PYTHONWARNINGS': 'always'},
|
|
|
|
)
|
|
|
|
waring_text = (
|
|
|
|
"DeprecationWarning: --print-deps-only is deprecated; "
|
|
|
|
+ "use `--print-deps-to -`"
|
|
|
|
)
|
|
|
|
assert waring_text in result.stderr
|
|
|
|
|
|
|
|
|
|
|
|
def test_allenvs_print_deps(print_deps_stdout_arg):
|
|
|
|
result = tox(print_deps_stdout_arg)
|
2019-07-18 11:33:42 +02:00
|
|
|
expected = textwrap.dedent(
|
|
|
|
"""
|
|
|
|
six
|
|
|
|
py
|
|
|
|
six
|
|
|
|
py
|
|
|
|
six
|
|
|
|
py
|
2020-08-12 15:23:55 +02:00
|
|
|
six
|
|
|
|
py
|
2019-07-18 11:33:42 +02:00
|
|
|
___________________________________ summary ____________________________________
|
|
|
|
py36: commands succeeded
|
|
|
|
py37: commands succeeded
|
|
|
|
py38: commands succeeded
|
2020-08-12 15:23:55 +02:00
|
|
|
py39: commands succeeded
|
2019-07-18 11:33:42 +02:00
|
|
|
congratulations :)
|
|
|
|
"""
|
|
|
|
).lstrip()
|
|
|
|
assert result.stdout == expected
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
@pytest.mark.parametrize("toxenv", ["py36", "py37", "py38", "py39"])
|
2019-08-01 12:39:12 +02:00
|
|
|
def test_print_deps_to_file(toxenv, tmp_path):
|
|
|
|
depspath = tmp_path / "deps"
|
2020-09-15 16:19:17 +02:00
|
|
|
result = tox("-e", toxenv, "--print-deps-to", str(depspath))
|
2019-08-01 12:39:12 +02:00
|
|
|
assert depspath.read_text().splitlines() == ["six", "py"]
|
|
|
|
expected = textwrap.dedent(
|
|
|
|
f"""
|
|
|
|
___________________________________ summary ____________________________________
|
|
|
|
{toxenv}: commands succeeded
|
|
|
|
congratulations :)
|
|
|
|
"""
|
|
|
|
).lstrip()
|
|
|
|
assert result.stdout == expected
|
|
|
|
|
|
|
|
|
2020-09-15 16:21:23 +02:00
|
|
|
@pytest.mark.parametrize('option', ('--print-deps-to', '--print-deps-to-file'))
|
|
|
|
def test_allenvs_print_deps_to_file(tmp_path, option):
|
2019-08-01 12:39:12 +02:00
|
|
|
depspath = tmp_path / "deps"
|
2020-09-15 16:21:23 +02:00
|
|
|
result = tox(option, str(depspath))
|
2020-08-12 15:23:55 +02:00
|
|
|
assert depspath.read_text().splitlines() == ["six", "py"] * 4
|
2019-08-01 12:39:12 +02:00
|
|
|
expected = textwrap.dedent(
|
|
|
|
"""
|
|
|
|
___________________________________ summary ____________________________________
|
|
|
|
py36: commands succeeded
|
|
|
|
py37: commands succeeded
|
|
|
|
py38: commands succeeded
|
2020-08-12 15:23:55 +02:00
|
|
|
py39: commands succeeded
|
2019-08-01 12:39:12 +02:00
|
|
|
congratulations :)
|
|
|
|
"""
|
|
|
|
).lstrip()
|
|
|
|
assert result.stdout == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_allenvs_print_deps_to_existing_file(tmp_path):
|
|
|
|
depspath = tmp_path / "deps"
|
|
|
|
depspath.write_text("nada")
|
2020-09-15 16:19:17 +02:00
|
|
|
result = tox("--print-deps-to", str(depspath))
|
2019-08-01 12:39:12 +02:00
|
|
|
lines = depspath.read_text().splitlines()
|
|
|
|
assert "nada" not in lines
|
|
|
|
assert "six" in lines
|
|
|
|
assert "py" in lines
|
|
|
|
|
|
|
|
|
2019-08-12 16:17:41 +02:00
|
|
|
def test_print_deps_only_print_deps_to_file_are_mutually_exclusive():
|
|
|
|
result = tox(
|
|
|
|
"-e",
|
|
|
|
NATIVE_TOXENV,
|
|
|
|
"--print-deps-only",
|
2020-09-15 16:19:17 +02:00
|
|
|
"--print-deps-to",
|
2019-08-12 16:17:41 +02:00
|
|
|
"foobar",
|
|
|
|
check=False,
|
|
|
|
)
|
|
|
|
assert result.returncode > 0
|
|
|
|
assert "cannot be used together" in result.stderr
|
|
|
|
|
|
|
|
|
2020-08-12 15:23:55 +02:00
|
|
|
@needs_py36789
|
2019-07-17 18:28:54 +02:00
|
|
|
def test_regular_run():
|
|
|
|
result = tox()
|
2020-08-12 15:23:55 +02:00
|
|
|
lines = sorted(result.stdout.splitlines()[:4])
|
2020-08-11 17:07:58 +02:00
|
|
|
assert "/.tox/py36 is the exec_prefix" in lines[0]
|
|
|
|
assert "/.tox/py37 is the exec_prefix" in lines[1]
|
|
|
|
assert "/.tox/py38 is the exec_prefix" in lines[2]
|
2020-08-12 15:23:55 +02:00
|
|
|
assert "/.tox/py39 is the exec_prefix" in lines[3]
|
2019-07-17 18:28:54 +02:00
|
|
|
assert "congratulations" in result.stdout
|
2020-08-12 15:23:55 +02:00
|
|
|
for y in 6, 7, 8, 9:
|
2020-08-12 17:04:58 +02:00
|
|
|
if TOX313 and y > 8:
|
|
|
|
# there is a bug in tox < 3.14,
|
|
|
|
# it creates venv with /usr/bin/python3 if the version is unknown
|
|
|
|
# See https://src.fedoraproject.org/rpms/python-tox/pull-request/15
|
2020-08-12 15:23:55 +02:00
|
|
|
continue
|
2019-07-18 11:06:48 +02:00
|
|
|
for pkg in "py", "six", "test":
|
|
|
|
sitelib = DOT_TOX / f"py3{y}/lib/python3.{y}/site-packages"
|
|
|
|
assert sitelib.is_dir()
|
|
|
|
assert len(list(sitelib.glob(f"{pkg}-*.dist-info"))) == 1
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2019-07-23 14:49:13 +02:00
|
|
|
def test_regular_run_native_toxenv():
|
|
|
|
result = tox("-e", NATIVE_TOXENV)
|
|
|
|
lines = sorted(result.stdout.splitlines()[:1])
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in lines[0]
|
2019-07-23 14:49:13 +02:00
|
|
|
assert "congratulations" in result.stdout
|
|
|
|
for pkg in "py", "six", "test":
|
|
|
|
sitelib = (
|
|
|
|
DOT_TOX / f"{NATIVE_TOXENV}/lib/python3.{NATIVE_TOXENV[-1]}/site-packages"
|
|
|
|
)
|
|
|
|
assert sitelib.is_dir()
|
|
|
|
assert len(list(sitelib.glob(f"{pkg}-*.dist-info"))) == 1
|
|
|
|
|
|
|
|
|
2019-08-01 13:24:41 +02:00
|
|
|
def test_regular_after_current_is_supported():
|
2019-07-17 18:59:50 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in result.stdout
|
2019-08-01 13:24:41 +02:00
|
|
|
assert "--recreate" not in result.stderr
|
|
|
|
|
|
|
|
|
2020-09-15 16:19:55 +02:00
|
|
|
def test_regular_after_killed_current_is_not_supported():
|
2019-08-01 13:24:41 +02:00
|
|
|
# fake broken tox run
|
|
|
|
shutil.rmtree(DOT_TOX, ignore_errors=True)
|
|
|
|
(DOT_TOX / NATIVE_TOXENV / "bin").mkdir(parents=True)
|
|
|
|
(DOT_TOX / NATIVE_TOXENV / "bin" / "python").symlink_to(NATIVE_EXECUTABLE)
|
|
|
|
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, check=False)
|
2019-07-17 18:59:50 +02:00
|
|
|
assert result.returncode > 0
|
2019-08-01 13:24:41 +02:00
|
|
|
assert "--recreate" in result.stderr
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
def test_regular_after_first_print_deps_is_supported(print_deps_stdout_arg):
|
|
|
|
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg)
|
2019-07-29 14:20:44 +02:00
|
|
|
assert result.stdout.splitlines()[0] == "six"
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV)
|
2019-08-01 13:24:41 +02:00
|
|
|
lines = sorted(result.stdout.splitlines()[:1])
|
|
|
|
assert "--recreate" not in result.stderr
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in lines[0]
|
2019-07-29 14:20:44 +02:00
|
|
|
|
2019-07-29 14:30:15 +02:00
|
|
|
# check that "test" was not installed to current environment
|
2019-10-21 12:48:57 +02:00
|
|
|
shutil.rmtree("./test.egg-info")
|
2019-07-29 14:30:15 +02:00
|
|
|
pip_freeze = subprocess.run(
|
|
|
|
(sys.executable, "-m", "pip", "freeze"),
|
|
|
|
encoding="utf-8",
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
).stdout.splitlines()
|
2019-10-21 12:48:57 +02:00
|
|
|
# XXX when this fails, recreate your current environment
|
2019-07-29 14:30:15 +02:00
|
|
|
assert "test==0.0.0" not in pip_freeze
|
|
|
|
|
2019-07-29 14:20:44 +02:00
|
|
|
|
2019-07-17 18:28:54 +02:00
|
|
|
def test_regular_recreate_after_current():
|
2019-07-17 18:59:50 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-re", NATIVE_TOXENV)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in result.stdout
|
2019-07-17 18:59:50 +02:00
|
|
|
assert "not supported" not in result.stderr
|
2019-08-01 13:24:41 +02:00
|
|
|
assert "--recreate" not in result.stderr
|
2019-07-17 18:28:54 +02:00
|
|
|
|
|
|
|
|
2019-07-18 11:33:42 +02:00
|
|
|
def test_current_after_regular_is_not_supported():
|
2019-07-17 18:59:50 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in result.stdout
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, "--current-env", check=False)
|
2019-07-17 18:59:50 +02:00
|
|
|
assert result.returncode > 0
|
|
|
|
assert "not supported" in result.stderr
|
|
|
|
|
|
|
|
|
|
|
|
def test_current_recreate_after_regular():
|
|
|
|
result = tox("-e", NATIVE_TOXENV)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert f"/.tox/{NATIVE_TOXENV} is the exec_prefix" in result.stdout
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-re", NATIVE_TOXENV, "--current-env")
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG
|
2019-07-18 11:33:42 +02:00
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
def test_current_after_print_deps(print_deps_stdout_arg):
|
2019-07-18 11:33:42 +02:00
|
|
|
# this is quite fast, so we can do it several times
|
|
|
|
for _ in range(3):
|
2020-09-15 14:16:40 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg)
|
2019-07-18 11:33:42 +02:00
|
|
|
assert "bin/python" not in result.stdout
|
|
|
|
assert "six" in result.stdout
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-re", NATIVE_TOXENV, "--current-env")
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG
|
2019-07-18 11:33:42 +02:00
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
def test_regular_recreate_after_print_deps(print_deps_stdout_arg):
|
|
|
|
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg)
|
2019-07-18 11:33:42 +02:00
|
|
|
assert "bin/python" not in result.stdout
|
|
|
|
assert "six" in result.stdout
|
|
|
|
|
2019-10-21 12:37:19 +02:00
|
|
|
result = tox("-re", NATIVE_TOXENV)
|
2020-08-11 17:07:58 +02:00
|
|
|
assert result.stdout.splitlines()[0] != NATIVE_EXEC_PREFIX_MSG
|
2019-07-29 14:20:44 +02:00
|
|
|
sitelib = DOT_TOX / f"{NATIVE_TOXENV}/lib/python3.{NATIVE_TOXENV[-1]}/site-packages"
|
|
|
|
assert sitelib.is_dir()
|
|
|
|
assert len(list(sitelib.glob("test-*.dist-info"))) == 1
|
2019-07-18 11:33:42 +02:00
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg)
|
2019-07-18 11:33:42 +02:00
|
|
|
assert "bin/python" not in result.stdout
|
|
|
|
assert "six" in result.stdout
|
2019-07-26 13:49:54 +02:00
|
|
|
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
def test_print_deps_without_python_command(tmp_path, print_deps_stdout_arg):
|
2019-07-26 13:49:54 +02:00
|
|
|
bin = tmp_path / "bin"
|
|
|
|
bin.mkdir()
|
|
|
|
tox_link = bin / "tox"
|
|
|
|
tox_path = shutil.which("tox")
|
|
|
|
tox_link.symlink_to(tox_path)
|
|
|
|
env = {**os.environ, "PATH": str(bin)}
|
|
|
|
|
2020-09-15 14:16:40 +02:00
|
|
|
result = tox("-e", NATIVE_TOXENV, print_deps_stdout_arg, env=env)
|
2019-07-26 13:49:54 +02:00
|
|
|
expected = textwrap.dedent(
|
|
|
|
f"""
|
|
|
|
six
|
|
|
|
py
|
|
|
|
___________________________________ summary ____________________________________
|
|
|
|
{NATIVE_TOXENV}: commands succeeded
|
|
|
|
congratulations :)
|
|
|
|
"""
|
|
|
|
).lstrip()
|
|
|
|
assert result.stdout == expected
|
2020-09-11 14:42:56 +02:00
|
|
|
|
|
|
|
|
2020-09-15 16:28:59 +02:00
|
|
|
@pytest.mark.parametrize("flag", [None, "--print-deps-to=-", "--current-env"])
|
2020-09-11 14:42:56 +02:00
|
|
|
def test_noquiet_installed_packages(flag):
|
|
|
|
flags = (flag,) if flag else ()
|
|
|
|
result = tox("-e", NATIVE_TOXENV, *flags, quiet=False, check=False)
|
|
|
|
assert f"\n{NATIVE_TOXENV} installed: " in result.stdout
|
|
|
|
for line in result.stdout.splitlines():
|
|
|
|
if line.startswith(f"{NATIVE_TOXENV} installed: "):
|
|
|
|
packages = line.rpartition(" installed: ")[-1].split(",")
|
|
|
|
break
|
|
|
|
|
|
|
|
# default tox produces output sorted by package names
|
|
|
|
assert packages == sorted(
|
|
|
|
packages, key=lambda p: p.partition("==")[0].partition(" @ ")[0]
|
|
|
|
)
|
|
|
|
|
|
|
|
# without a flag, the output must match tox defaults
|
|
|
|
if not flag:
|
|
|
|
assert len(packages) == 3
|
|
|
|
assert packages[0].startswith("py==")
|
|
|
|
assert packages[1].startswith("six==")
|
|
|
|
assert packages[2].startswith(("test==", "test @ ")) # old and new pip
|
|
|
|
|
|
|
|
# with our flags, uses the current environment by default, hence has tox, pytest
|
|
|
|
else:
|
|
|
|
assert f"tox=={TOX_VERSION}" in packages
|
|
|
|
assert len([p for p in packages if p.startswith("pytest==")]) == 1
|
|
|
|
assert all(re.match(r"\S+==\S+", p) for p in packages)
|