From dd6619346306181c7d8313a86afa4ad7be6f2178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 15 May 2019 17:30:50 +0100 Subject: show config now shows all config, filter-able, contains host tox python and package versions (#1298) and package versions --- tests/unit/config/test_config.py | 49 -------------- tests/unit/session/test_show_config.py | 117 +++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 tests/unit/session/test_show_config.py (limited to 'tests') diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index c64ec1be..206fde8d 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -2722,12 +2722,6 @@ class TestCmdInvocation: assert "some-repr" in version_info assert "1.0" in version_info - def test_config_specific_ini(self, tmpdir, cmd): - ini = tmpdir.ensure("hello.ini") - result = cmd("-c", ini, "--showconfig") - assert not result.ret - assert result.outlines[1] == "config-file: {}".format(ini) - def test_no_tox_ini(self, cmd, initproj): initproj("noini-0.5") result = cmd() @@ -2736,49 +2730,6 @@ class TestCmdInvocation: assert result.err == msg assert not result.out - def test_override_workdir(self, cmd, initproj): - baddir = "badworkdir-123" - gooddir = "overridden-234" - initproj( - "overrideworkdir-0.5", - filedefs={ - "tox.ini": """ - [tox] - toxworkdir={} - """.format( - baddir - ) - }, - ) - result = cmd("--workdir", gooddir, "--showconfig") - assert not result.ret - assert gooddir in result.out - assert baddir not in result.out - assert py.path.local(gooddir).check() - assert not py.path.local(baddir).check() - - def test_showconfig_with_force_dep_version(self, cmd, initproj): - initproj( - "force_dep_version", - filedefs={ - "tox.ini": """ - [tox] - - [testenv] - deps= - dep1==2.3 - dep2 - """ - }, - ) - result = cmd("--showconfig") - result.assert_success(is_run_test_env=False) - assert any(re.match(r".*deps.*dep1==2.3, dep2.*", l) for l in result.outlines) - # override dep1 specific version, and force version for dep2 - result = cmd("--showconfig", "--force-dep=dep1", "--force-dep=dep2==5.0") - result.assert_success(is_run_test_env=False) - assert any(re.match(r".*deps.*dep1, dep2==5.0.*", l) for l in result.outlines) - @pytest.mark.parametrize( "cli_args,run_envlist", diff --git a/tests/unit/session/test_show_config.py b/tests/unit/session/test_show_config.py new file mode 100644 index 00000000..1a01d1d8 --- /dev/null +++ b/tests/unit/session/test_show_config.py @@ -0,0 +1,117 @@ +import py +import pytest +from six import StringIO +from six.moves import configparser + + +def load_config(args, cmd): + result = cmd(*args) + result.assert_success(is_run_test_env=False) + parser = configparser.ConfigParser() + output = StringIO(result.out) + parser.readfp(output) + return parser + + +def test_showconfig_with_force_dep_version(cmd, initproj): + initproj( + "force_dep_version", + filedefs={ + "tox.ini": """ + [tox] + + [testenv] + deps= + dep1==2.3 + dep2 + """ + }, + ) + parser = load_config(("--showconfig",), cmd) + assert parser.get("testenv:python", "deps") == "[dep1==2.3, dep2]" + + parser = load_config(("--showconfig", "--force-dep=dep1", "--force-dep=dep2==5.0"), cmd) + assert parser.get("testenv:python", "deps") == "[dep1, dep2==5.0]" + + +@pytest.fixture() +def setup_mixed_conf(initproj): + initproj( + "force_dep_version", + filedefs={ + "tox.ini": """ + [tox] + envlist = py37,py27,pypi,docs + + [testenv:notincluded] + changedir = whatever + + [testenv:docs] + changedir = docs + """ + }, + ) + + +@pytest.mark.parametrize( + "args, expected", + [ + ( + ["--showconfig"], + [ + "tox", + "tox:versions", + "testenv:py37", + "testenv:py27", + "testenv:pypi", + "testenv:docs", + "testenv:notincluded", + ], + ), + ( + ["--showconfig", "-l"], + [ + "tox", + "tox:versions", + "testenv:py37", + "testenv:py27", + "testenv:pypi", + "testenv:docs", + ], + ), + (["--showconfig", "-e", "py37,py36"], ["testenv:py37", "testenv:py36"]), + ], + ids=["all", "default_only", "-e"], +) +def test_showconfig(cmd, setup_mixed_conf, args, expected): + parser = load_config(args, cmd) + found_sections = parser.sections() + assert found_sections == expected + + +def test_config_specific_ini(tmpdir, cmd): + ini = tmpdir.ensure("hello.ini") + output = load_config(("-c", ini, "--showconfig"), cmd) + assert output.get("tox", "toxinipath") == ini + + +def test_override_workdir(cmd, initproj): + baddir = "badworkdir-123" + gooddir = "overridden-234" + initproj( + "overrideworkdir-0.5", + filedefs={ + "tox.ini": """ + [tox] + toxworkdir={} + """.format( + baddir + ) + }, + ) + result = cmd("--workdir", gooddir, "--showconfig") + assert not result.ret + assert gooddir in result.out + assert baddir not in result.out + assert py.path.local(gooddir).check() + assert not py.path.local(baddir).check() -- cgit v1.2.1