diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9308ca5b7..4068a590b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,8 +8,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v1.2.3 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - id: check-yaml - id: debug-statements - id: flake8 diff --git a/tests/conftest.py b/tests/conftest.py index c30387771..ec59f4a1c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ # FIXME this seems unnecessary # TODO move fixtures here and only keep helper functions/classes in the plugin # TODO _pytest_helpers might be a better name than _pytestplugin then? +# noinspection PyUnresolvedReferences from tox._pytestplugin import * # noqa diff --git a/tests/test_config.py b/tests/test_config.py index 13a369e05..a81a7ca1f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -8,9 +8,16 @@ from pluggy import PluginManager import tox -from tox.config import CommandParser, DepOption, SectionReader, get_homedir -from tox.config import get_version_info, getcontextname, is_section_substitution, parseconfig - +from tox.config import ( + CommandParser, + DepOption, + SectionReader, + get_homedir, + get_version_info, + getcontextname, + is_section_substitution, + parseconfig, +) from tox.venv import VirtualEnv @@ -106,10 +113,8 @@ def test_force_dep_version(self, initproj): ["--force-dep=dep1==1.5", "--force-dep=dep2==2.1", "--force-dep=dep3==3.0"] ) assert config.option.force_dep == ["dep1==1.5", "dep2==2.1", "dep3==3.0"] - assert ( - [str(x) for x in config.envconfigs["python"].deps] - == ["dep1==1.5", "dep2==2.1", "dep3==3.0", "dep4==4.0"] - ) + expected_deps = ["dep1==1.5", "dep2==2.1", "dep3==3.0", "dep4==4.0"] + assert expected_deps == [str(x) for x in config.envconfigs["python"].deps] def test_force_dep_with_url(self, initproj): initproj( @@ -127,10 +132,8 @@ def test_force_dep_with_url(self, initproj): ) config = parseconfig(["--force-dep=dep1==1.5"]) assert config.option.force_dep == ["dep1==1.5"] - assert ( - [str(x) for x in config.envconfigs["python"].deps] - == ["dep1==1.5", "https://pypi.org/xyz/pkg1.tar.gz"] - ) + expected_deps = ["dep1==1.5", "https://pypi.org/xyz/pkg1.tar.gz"] + assert [str(x) for x in config.envconfigs["python"].deps] == expected_deps def test_process_deps(self, newconfig): config = newconfig( @@ -146,17 +149,15 @@ def test_process_deps(self, newconfig): --help dep2 """, ) # note that those last two are invalid - assert ( - [str(x) for x in config.envconfigs["python"].deps] - == [ - "-rrequirements.txt", - "--index-url=https://pypi.org/simple", - "-fhttps://pypi.org/packages", - "--global-option=foo", - "-v dep1", - "--help dep2", - ] - ) + expected_deps = [ + "-rrequirements.txt", + "--index-url=https://pypi.org/simple", + "-fhttps://pypi.org/packages", + "--global-option=foo", + "-v dep1", + "--help dep2", + ] + assert [str(x) for x in config.envconfigs["python"].deps] == expected_deps def test_is_same_dep(self): """ @@ -348,16 +349,14 @@ def test_command_substitution_from_other_section_multiline(self, newconfig): ) reader = SectionReader("testenv", config._cfg) x = reader.getargvlist("commands") - assert ( - x - == [ - "cmd1 param11 param12".split(), - "cmd2 param21 param22".split(), - "cmd1 param11 param12".split(), - "cmd2 param21 param22".split(), - ["echo", "cmd", "1", "2", "3", "4", "cmd", "2"], - ] - ) + expected_deps = [ + "cmd1 param11 param12".split(), + "cmd2 param21 param22".split(), + "cmd1 param11 param12".split(), + "cmd2 param21 param22".split(), + ["echo", "cmd", "1", "2", "3", "4", "cmd", "2"], + ] + assert x == expected_deps def test_command_substitution_from_other_section_posargs(self, newconfig): """Ensure subsitition from other section with posargs succeeds""" @@ -705,14 +704,10 @@ def test_argvlist_quoted_posargs(self, newconfig): reader.addsubstitutions(["foo", "bar"]) assert reader.getargvlist("key1") == [] x = reader.getargvlist("key2") - assert ( - x - == [ - ["cmd1", "--foo-args=foo bar"], - ["cmd2", "-f", "foo bar"], - ["cmd3", "-f", "foo", "bar"], - ] - ) + expected_deps = [ + ["cmd1", "--foo-args=foo bar"], ["cmd2", "-f", "foo bar"], ["cmd3", "-f", "foo", "bar"] + ] + assert x == expected_deps def test_argvlist_posargs_with_quotes(self, newconfig): config = newconfig( @@ -1189,16 +1184,14 @@ def test_install_command_substitutions(self, newconfig): """ ) envconfig = config.envconfigs["python"] - assert ( - envconfig.install_command - == [ - "some_install", - "--arg={}/foo".format(config.toxinidir), - "python", - "{opts}", - "{packages}", - ] - ) + expected_deps = [ + "some_install", + "--arg={}/foo".format(config.toxinidir), + "python", + "{opts}", + "{packages}", + ] + assert envconfig.install_command == expected_deps def test_pip_pre(self, newconfig): config = newconfig( @@ -1603,15 +1596,11 @@ def get_deps(env): return [dep.name for dep in configs[env].deps] assert get_deps("a-x") == ["dep-a-or-b", "dep-a-and-x", "dep-a-or-!x"] - assert ( - get_deps("a-y") - == ["dep-a-or-b", "dep-ab-and-y", "dep-a-and-!x", "dep-a-or-!x", "dep-!a-or-!x"] - ) + expected = ["dep-a-or-b", "dep-ab-and-y", "dep-a-and-!x", "dep-a-or-!x", "dep-!a-or-!x"] + assert get_deps("a-y") == expected assert get_deps("b-x") == ["dep-a-or-b", "dep-!a-or-!x"] - assert ( - get_deps("b-y") - == ["dep-a-or-b", "dep-ab-and-y", "dep-a-or-!x", "dep-!a-and-!x", "dep-!a-or-!x"] - ) + expected = ["dep-a-or-b", "dep-ab-and-y", "dep-a-or-!x", "dep-!a-and-!x", "dep-!a-or-!x"] + assert get_deps("b-y") == expected def test_envconfigs_based_on_factors(self, newconfig): inisource = """ @@ -2413,17 +2402,15 @@ def test_listenvs_verbose_description(self, cmd, initproj): }, ) result = cmd("-lv") - assert ( - result.outlines[2:] - == [ - "default environments:", - "py36 -> run pytest on Python 3.6", - "py27 -> run pytest on Python 2.7", - "py34 -> run pytest on Python 3.4", - "pypy -> publish to pypy", - "docs -> let me overwrite that", - ] - ) + expected = [ + "default environments:", + "py36 -> run pytest on Python 3.6", + "py27 -> run pytest on Python 2.7", + "py34 -> run pytest on Python 3.4", + "pypy -> publish to pypy", + "docs -> let me overwrite that", + ] + assert result.outlines[2:] == expected def test_listenvs_all(self, cmd, initproj): initproj( @@ -2442,7 +2429,8 @@ def test_listenvs_all(self, cmd, initproj): }, ) result = cmd("-a") - assert result.outlines == ["py36", "py27", "py34", "pypy", "docs", "notincluded"] + expected = ["py36", "py27", "py34", "pypy", "docs", "notincluded"] + assert result.outlines == expected def test_listenvs_all_verbose_description(self, cmd, initproj): initproj( @@ -2659,28 +2647,17 @@ def test_command_with_split_line_in_subst_arguments(self): ) p = CommandParser(cmd) parsed = list(p.words()) - assert parsed == ["cmd2", " ", "{posargs:{item2}\n other}"] + expected = ["cmd2", " ", "{posargs:{item2}\n other}"] + assert parsed == expected def test_command_parsing_for_issue_10(self): cmd = "nosetests -v -a !deferred --with-doctest []" p = CommandParser(cmd) parsed = list(p.words()) - assert ( - parsed - == [ - "nosetests", - " ", - "-v", - " ", - "-a", - " ", - "!deferred", - " ", - "--with-doctest", - " ", - "[]", - ] - ) + expected = [ + "nosetests", " ", "-v", " ", "-a", " ", "!deferred", " ", "--with-doctest", " ", "[]" + ] + assert parsed == expected # @mark_dont_run_on_windows def test_commands_with_backslash(self, newconfig): diff --git a/tests/test_result.py b/tests/test_result.py index b7670214f..38f02bc15 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -39,14 +39,12 @@ def test_set_header(pkg): assert replog.dict["toxversion"] == tox.__version__ assert replog.dict["platform"] == sys.platform assert replog.dict["host"] == socket.getfqdn() - assert ( - replog.dict["installpkg"] - == { - "basename": "hello-1.0.tar.gz", - "md5": pkg.computehash("md5"), - "sha256": pkg.computehash("sha256"), - } - ) + expected = { + "basename": "hello-1.0.tar.gz", + "md5": pkg.computehash("md5"), + "sha256": pkg.computehash("sha256"), + } + assert replog.dict["installpkg"] == expected data = replog.dumps_json() replog2 = ResultLog(data) assert replog2.dict == replog.dict @@ -69,10 +67,8 @@ def test_get_commandlog(pkg): assert "setup" not in envlog.dict setuplog = envlog.get_commandlog("setup") setuplog.add_command(["virtualenv", "..."], "venv created", 0) - assert ( - setuplog.list - == [{"command": ["virtualenv", "..."], "output": "venv created", "retcode": "0"}] - ) + expected = [{"command": ["virtualenv", "..."], "output": "venv created", "retcode": "0"}] + assert setuplog.list == expected assert envlog.dict["setup"] setuplog2 = replog.get_envlog("py36").get_commandlog("setup") assert setuplog2.list == setuplog.list @@ -87,10 +83,8 @@ def test_invocation_error(exit_code, os_name, mocker, monkeypatch): # check that mocker works, because it will be our only test in # test_z_cmdline.py::test_exit_code needs the mocker.spy above assert tox.exception.exit_code_str.call_count == 1 - assert ( - tox.exception.exit_code_str.call_args - == mocker.call("InvocationError", "", exit_code) - ) + call_args = tox.exception.exit_code_str.call_args + assert call_args == mocker.call("InvocationError", "", exit_code) if exit_code is None: assert "(exited with code" not in result else: diff --git a/tests/test_venv.py b/tests/test_venv.py index cd6296832..0d7ec60a9 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -6,8 +6,14 @@ import tox from tox.interpreters import NoInterpreterInfo -from tox.venv import CreationConfig, VirtualEnv, getdigest, prepend_shebang_interpreter -from tox.venv import tox_testenv_create, tox_testenv_install_deps +from tox.venv import ( + CreationConfig, + VirtualEnv, + getdigest, + prepend_shebang_interpreter, + tox_testenv_create, + tox_testenv_install_deps, +) def test_getdigest(tmpdir): @@ -65,7 +71,8 @@ def test_create(mocksession, newconfig): assert "virtualenv" == str(args[2]) if not tox.INFO.IS_WIN: # realpath is needed for stuff like the debian symlinks - assert py.path.local(sys.executable).realpath() == py.path.local(args[0]).realpath() + our_sys_path = py.path.local(sys.executable).realpath() + assert our_sys_path == py.path.local(args[0]).realpath() # assert Envconfig.toxworkdir in args assert venv.getcommandpath("easy_install", cwd=py.path.local()) interp = venv._getliveconfig().python @@ -963,12 +970,10 @@ def test_tox_testenv_interpret_shebang_long_example(tmpdir): "name-in-the-argument-list" ) args = prepend_shebang_interpreter(base_args) - assert ( - args - == [ - b"this-is-an-example-of-a-very-long-interpret-directive-what-should-be-" - b"directly-invoked-when-tox-needs-to-invoked-the-provided-script-name-" - b"in-the-argument-list" - ] - + base_args - ) + expected = [ + b"this-is-an-example-of-a-very-long-interpret-directive-what-should-be-" + b"directly-invoked-when-tox-needs-to-invoked-the-provided-script-name-" + b"in-the-argument-list" + ] + + assert args == expected + base_args diff --git a/tox/__init__.py b/tox/__init__.py index a891d6708..81d7f6885 100644 --- a/tox/__init__.py +++ b/tox/__init__.py @@ -6,9 +6,8 @@ To override/modify tox behaviour via plugins see `tox.hookspec` and its use with pluggy. """ -from pkg_resources import DistributionNotFound, get_distribution - import pluggy +from pkg_resources import DistributionNotFound, get_distribution from . import exception from .constants import INFO, PIP, PYTHON @@ -35,6 +34,5 @@ except DistributionNotFound: __version__ = "0.0.0.dev0" - # NOTE: must come last due to circular import from .session import cmdline # noqa diff --git a/tox/_pytestplugin.py b/tox/_pytestplugin.py index 1ced61f0a..5f5133bcd 100644 --- a/tox/_pytestplugin.py +++ b/tox/_pytestplugin.py @@ -1,13 +1,13 @@ from __future__ import print_function, unicode_literals +import os +import textwrap import time +from fnmatch import fnmatch -import os import py import pytest import six -import textwrap -from fnmatch import fnmatch import tox from tox.config import parseconfig diff --git a/tox/_quickstart.py b/tox/_quickstart.py index db16714b6..bb6c229c6 100644 --- a/tox/_quickstart.py +++ b/tox/_quickstart.py @@ -43,9 +43,9 @@ import codecs import os import sys +import textwrap import six -import textwrap import tox diff --git a/tox/config.py b/tox/config.py index 57331c03c..b3b8a843a 100755 --- a/tox/config.py +++ b/tox/config.py @@ -16,9 +16,8 @@ import py import tox -from tox.interpreters import Interpreters from tox._verlib import NormalizedVersion - +from tox.interpreters import Interpreters hookimpl = tox.hookimpl """DEPRECATED - REMOVE - this is left for compatibility with plugins importing this from here. @@ -1001,23 +1000,26 @@ def make_envconfig(self, name, section, subs, config, replace=True): return tc def _getenvdata(self, reader): - envstr = self.config.option.env or os.environ.get("TOXENV") or reader.getstring( - "envlist", replace=False - ) or [] - envlist = _split_env(envstr) + candidates = ( + self.config.option.env, + os.environ.get("TOXENV"), + reader.getstring("envlist", replace=False), + ) + env_str = next((i for i in candidates if i), []) + env_list = _split_env(env_str) # collect section envs - all_envs = set(envlist) - {"ALL"} + all_envs = set(env_list) - {"ALL"} for section in self._cfg: if section.name.startswith(testenvprefix): all_envs.add(section.name[len(testenvprefix):]) if not all_envs: all_envs.add("python") - if not envlist or "ALL" in envlist: - envlist = sorted(all_envs) + if not env_list or "ALL" in env_list: + env_list = sorted(all_envs) - return envlist, all_envs + return env_list, all_envs def _split_env(env): diff --git a/tox/constants.py b/tox/constants.py index 23a810e37..049a08dc7 100644 --- a/tox/constants.py +++ b/tox/constants.py @@ -5,7 +5,7 @@ import sys as _sys -def _contruct_default_factors(version_tuples, other_interpreters): +def _construct_default_factors(version_tuples, other_interpreters): default_factors = {"py": _sys.executable, "py2": "python2", "py3": "python3"} default_factors.update( { @@ -20,7 +20,7 @@ def _contruct_default_factors(version_tuples, other_interpreters): class PYTHON: CPYTHON_VERSION_TUPLES = [(2, 7), (3, 4), (3, 5), (3, 6), (3, 7)] OTHER_PYTHON_INTERPRETERS = ["jython", "pypy", "pypy3"] - DEFAULT_FACTORS = _contruct_default_factors(CPYTHON_VERSION_TUPLES, OTHER_PYTHON_INTERPRETERS) + DEFAULT_FACTORS = _construct_default_factors(CPYTHON_VERSION_TUPLES, OTHER_PYTHON_INTERPRETERS) CURRENT_RELEASE_ENV = "py36" """Should hold currently released py -> for easy updating""" QUICKSTART_PY_ENVS = ["py27", "py34", "py35", CURRENT_RELEASE_ENV, "pypy", "jython"] diff --git a/tox/session.py b/tox/session.py index 9b0aa1e9e..e74b81f92 100644 --- a/tox/session.py +++ b/tox/session.py @@ -59,7 +59,7 @@ def show_help(config): tw.write(config._parser._format_help()) tw.line() tw.line("Environment variables", bold=True) - tw.line("TOXENV: comma separated list of environments " "(overridable by '-e')") + tw.line("TOXENV: comma separated list of environments (overridable by '-e')") tw.line( "TOX_TESTENV_PASSENV: space-separated list of extra environment variables to be " "passed into test command environments" diff --git a/tox/venv.py b/tox/venv.py index 22695d9f7..35b5d4a1d 100755 --- a/tox/venv.py +++ b/tox/venv.py @@ -387,11 +387,8 @@ def test(self, redirect=False): ) except tox.exception.InvocationError as err: if self.envconfig.ignore_outcome: - self.session.report.warning( - "command failed but result from testenv is ignored\ncmd: {}".format( - str(err) - ) - ) + msg = "command failed but result from testenv is ignored\ncmd:" + self.session.report.warning("{} {}".format(msg, err)) self.status = "ignored failed command" continue # keep processing commands