diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a1d348739..98b7564897 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/ambv/black - rev: 18.4a4 + rev: 18.5b1 hooks: - id: black args: [--line-length=99, --safe] diff --git a/doc/conf.py b/doc/conf.py index da291f6310..f6a962746d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -6,7 +6,10 @@ sys.path.insert(0, os.path.dirname(__file__)) extensions = [ - "sphinx.ext.autodoc", "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.viewcode" + "sphinx.ext.autodoc", + "sphinx.ext.extlinks", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] project = u"tox" diff --git a/setup.py b/setup.py index 5839d3788f..ea47156b5c 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,11 @@ def main(): install_requires=["py>=1.4.17", "pluggy>=0.3.0,<1.0", "six", "virtualenv>=1.11.2"], extras_require={ "testing": [ - "pytest >= 3.0.0", "pytest-cov", "pytest-mock", "pytest-timeout", "pytest-xdist" + "pytest >= 3.0.0", + "pytest-cov", + "pytest-mock", + "pytest-timeout", + "pytest-xdist", ], "docs": ["sphinx >= 1.6.3, < 2", "towncrier >= 17.8.0"], "lint": ["pre-commit == 1.8.2"], diff --git a/tests/test_config.py b/tests/test_config.py index a81a7ca1f2..a9bfe3e13e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -22,7 +22,6 @@ class TestVenvConfig: - def test_config_parsing_minimal(self, tmpdir, newconfig): config = newconfig( [], @@ -172,7 +171,6 @@ def test_is_same_dep(self): class TestConfigPlatform: - def test_config_parse_platform(self, newconfig): config = newconfig( [], @@ -223,7 +221,6 @@ def test_config_parse_platform_with_factors(self, newconfig, plat): class TestConfigPackage: - def test_defaults(self, tmpdir, newconfig): config = newconfig([], "") assert config.setupdir.realpath() == tmpdir.realpath() @@ -256,7 +253,6 @@ def test_project_paths(self, tmpdir, newconfig): class TestParseconfig: - def test_search_parents(self, tmpdir): b = tmpdir.mkdir("a").mkdir("b") toxinipath = tmpdir.ensure("tox.ini") @@ -293,7 +289,6 @@ def test_get_homedir(monkeypatch): class TestGetcontextname: - def test_blank(self, monkeypatch): monkeypatch.setattr(os, "environ", {}) assert getcontextname() is None @@ -436,7 +431,6 @@ def test_regression_issue595(self, newconfig): class TestIniParser: - def test_getstring_single(self, newconfig): config = newconfig( """ @@ -705,7 +699,9 @@ def test_argvlist_quoted_posargs(self, newconfig): assert reader.getargvlist("key1") == [] x = reader.getargvlist("key2") expected_deps = [ - ["cmd1", "--foo-args=foo bar"], ["cmd2", "-f", "foo bar"], ["cmd3", "-f", "foo", "bar"] + ["cmd1", "--foo-args=foo bar"], + ["cmd2", "-f", "foo bar"], + ["cmd3", "-f", "foo", "bar"], ] assert x == expected_deps @@ -816,7 +812,6 @@ def test_getbool(self, newconfig): class TestIniParserPrefix: - def test_basic_section_access(self, newconfig): config = newconfig( """ @@ -873,7 +868,6 @@ def test_other_section_substitution(self, newconfig): class TestConfigTestEnv: - def test_commentchars_issue33(self, newconfig): config = newconfig( """ @@ -1723,7 +1717,6 @@ def test_ignore_outcome(self, newconfig): class TestGlobalOptions: - def test_notest(self, newconfig): config = newconfig([], "") assert not config.option.notest @@ -1905,7 +1898,6 @@ def test_defaultenv_partial_override(self, newconfig): class TestHashseedOption: - def _get_envconfigs(self, newconfig, args=None, tox_ini=None, make_hashseed=None): if args is None: args = [] @@ -2023,7 +2015,6 @@ def test_setenv_in_one_testenv(self, newconfig): class TestSetenv: - def test_getdict_lazy(self, newconfig, monkeypatch): monkeypatch.setenv("X", "2") config = newconfig( @@ -2196,7 +2187,6 @@ def test_setenv_cross_section_mixed(self, monkeypatch, newconfig): class TestIndexServer: - def test_indexserver(self, newconfig): config = newconfig( """ @@ -2248,7 +2238,6 @@ def test_multiple_homedir_relative_local_indexservers(self, newconfig): class TestConfigConstSubstitutions: - @pytest.mark.parametrize("pathsep", [":", ";"]) def test_replace_pathsep_unix(self, monkeypatch, newconfig, pathsep): monkeypatch.setattr("os.pathsep", pathsep) @@ -2273,7 +2262,6 @@ def test_pathsep_regex(self): class TestParseEnv: - def test_parse_recreate(self, newconfig): inisource = "" config = newconfig([], inisource) @@ -2291,7 +2279,6 @@ def test_parse_recreate(self, newconfig): class TestCmdInvocation: - def test_help(self, cmd): result = cmd("-h") assert not result.ret @@ -2310,9 +2297,7 @@ def test_version_no_plugins(self): assert "registered plugins:" not in version_info def test_version_with_normal_plugin(self, monkeypatch): - def fake_normal_plugin_distinfo(): - class MockModule: __file__ = "some-file" @@ -2331,11 +2316,8 @@ class MockEggInfo: assert "1.0" in version_info def test_version_with_fileless_module(self, monkeypatch): - def fake_no_file_plugin_distinfo(): - class MockModule: - def __repr__(self): return "some-repr" @@ -2463,7 +2445,7 @@ def test_listenvs_all_verbose_description(self, cmd, initproj): "additional environments:", "docs -> generate documentation", ] - assert result.outlines[-len(expected):] == expected + assert result.outlines[-len(expected) :] == expected def test_listenvs_all_verbose_description_no_additional_environments(self, cmd, initproj): initproj( @@ -2477,7 +2459,9 @@ def test_listenvs_all_verbose_description_no_additional_environments(self, cmd, ) result = cmd("-av") expected = [ - "default environments:", "py27 -> [no description]", "py36 -> [no description]" + "default environments:", + "py27 -> [no description]", + "py36 -> [no description]", ] assert result.out.splitlines()[-3:] == expected assert "additional environments" not in result.out @@ -2572,7 +2556,6 @@ def test_env_spec(cmdline, envlist): class TestCommandParser: - def test_command_parser_for_word(self): p = CommandParser("word") assert list(p.words()) == ["word"] @@ -2655,7 +2638,17 @@ def test_command_parsing_for_issue_10(self): p = CommandParser(cmd) parsed = list(p.words()) expected = [ - "nosetests", " ", "-v", " ", "-a", " ", "!deferred", " ", "--with-doctest", " ", "[]" + "nosetests", + " ", + "-v", + " ", + "-a", + " ", + "!deferred", + " ", + "--with-doctest", + " ", + "[]", ] assert parsed == expected diff --git a/tests/test_interpreters.py b/tests/test_interpreters.py index c091dbfc3c..1dd6474bb0 100644 --- a/tests/test_interpreters.py +++ b/tests/test_interpreters.py @@ -60,7 +60,6 @@ def communicate(): def test_tox_get_python_executable(): - class envconfig: basepython = sys.executable envname = "pyxx" @@ -89,7 +88,6 @@ class envconfig: def test_find_executable_extra(monkeypatch): - @staticmethod def sysfind(_): return "hello" @@ -113,9 +111,7 @@ def test_run_and_get_interpreter_info(): class TestInterpreters: - def test_get_executable(self, interpreters): - class envconfig: basepython = sys.executable envname = "pyxx" @@ -128,7 +124,6 @@ class envconfig: assert info.runnable def test_get_executable_no_exist(self, interpreters): - class envconfig: basepython = "1lkj23" envname = "pyxx" @@ -141,7 +136,6 @@ class envconfig: assert not info.runnable def test_get_sitepackagesdir_error(self, interpreters): - class envconfig: basepython = sys.executable envname = "123" @@ -184,7 +178,6 @@ def test_exec_failed(): class TestInterpreterInfo: - @staticmethod def info( name="my-name", @@ -215,7 +208,6 @@ def test_str(self): class TestNoInterpreterInfo: - def test_runnable(self): assert not NoInterpreterInfo("foo").runnable assert not NoInterpreterInfo("foo", executable=sys.executable).runnable diff --git a/tests/test_pytest_plugins.py b/tests/test_pytest_plugins.py index 326ba48b62..612800008d 100644 --- a/tests/test_pytest_plugins.py +++ b/tests/test_pytest_plugins.py @@ -10,7 +10,6 @@ class TestInitProj: - @pytest.mark.parametrize( "kwargs", ({}, {"src_root": None}, {"src_root": ""}, {"src_root": "."}) ) @@ -61,7 +60,6 @@ def test_broken_py_path_local_join_workaround_on_Windows(self, tmpdir, initproj, class TestPathParts: - @pytest.mark.parametrize( "input, expected", ( @@ -81,7 +79,7 @@ def test_path_parts(self, input, expected): def test_on_py_path(self): cwd_parts = _path_parts(py.path.local()) folder_parts = _path_parts(py.path.local("a/b/c")) - assert folder_parts[len(cwd_parts):] == ["a", "b", "c"] + assert folder_parts[len(cwd_parts) :] == ["a", "b", "c"] @pytest.mark.parametrize( diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index d65b8c9482..6b81f48c80 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -15,7 +15,12 @@ ALL_PY_ENVS_AS_STRING = ", ".join(tox.PYTHON.QUICKSTART_PY_ENVS) ALL_PY_ENVS_WO_LAST_AS_STRING = ", ".join(tox.PYTHON.QUICKSTART_PY_ENVS[:-1]) SIGNS_OF_SANITY = ( - "tox.readthedocs.io", "[tox]", "[testenv]", "envlist = ", "deps =", "commands =" + "tox.readthedocs.io", + "[tox]", + "[testenv]", + "envlist = ", + "deps =", + "commands =", ) """A bunch of elements to be expected in the generated config as marker for basic sanity""" @@ -44,6 +49,7 @@ def __call__(self, prompt): class _cnf: """Handle files and args for different test scenarios.""" + SOME_CONTENT = "dontcare" def __init__(self, exists=False, names=None, pass_path=False): @@ -111,6 +117,7 @@ def _alternative_content(self): class _exp: """Holds test expectations and a user scenario description.""" + STANDARD_EPECTATIONS = [ALL_PY_ENVS_AS_STRING, "pytest", "pytest"] def __init__(self, name, exp=None): diff --git a/tests/test_venv.py b/tests/test_venv.py index 0d7ec60a9b..9ab5ea875b 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -455,7 +455,6 @@ def test_install_python3(newmocksession): class TestCreationConfig: - def test_basic(self, newconfig, mocksession, tmpdir): config = newconfig([], "") envconfig = config.envconfigs["python"] @@ -588,7 +587,6 @@ def test_develop_recreation(self, newconfig, mocksession): class TestVenvTest: - def test_envbindir_path(self, newmocksession, monkeypatch): monkeypatch.setenv("PIP_RESPECT_VIRTUALENV", "1") mocksession = newmocksession( @@ -813,7 +811,6 @@ def test_tox_testenv_create(newmocksession): log = [] class Plugin: - @tox.hookimpl def tox_testenv_create(self, action, venv): assert isinstance(action, tox.session.Action) @@ -845,7 +842,6 @@ def test_tox_testenv_pre_post(newmocksession): log = [] class Plugin: - @tox.hookimpl def tox_runtest_pre(self): log.append("started") diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py index 3419339aee..8a96edfe89 100644 --- a/tests/test_z_cmdline.py +++ b/tests/test_z_cmdline.py @@ -27,7 +27,6 @@ def test_report_protocol(newconfig): ) class Popen: - def __init__(self, *args, **kwargs): pass @@ -82,7 +81,6 @@ def test__resolve_pkg_doubledash(tmpdir, mocksession): class TestSession: - def test_make_sdist(self, initproj): initproj( "example123-0.5", diff --git a/tox/_pytestplugin.py b/tox/_pytestplugin.py index 5f5133bcda..7602a481dc 100644 --- a/tox/_pytestplugin.py +++ b/tox/_pytestplugin.py @@ -47,7 +47,6 @@ def work_in_clean_dir(tmpdir): @pytest.fixture(name="newconfig") def create_new_config_file(tmpdir): - def create_new_config_file_(args, source=None, plugins=()): if source is None: source = args @@ -85,7 +84,6 @@ def run(*argv): class RunResult: - def __init__(self, capfd, args): self._capfd = capfd self.args = args @@ -115,7 +113,6 @@ def __repr__(self): class ReportExpectMock: - def __init__(self, session): self._calls = [] self._index = -1 @@ -182,7 +179,6 @@ def not_expect(self, cat, messagepattern="*"): class pcallMock: - def __init__(self, args, cwd, env, stdout, stderr, shell): self.arg0 = args[0] self.args = args[1:] @@ -202,9 +198,7 @@ def wait(self): @pytest.fixture(name="mocksession") def create_mocksession(request): - class MockSession(Session): - def __init__(self): self._clearmocks() self.config = request.getfixturevalue("newconfig")([], "") @@ -232,7 +226,6 @@ def popen(self, args, cwd, shell=None, stdout=None, stderr=None, env=None, **_): @pytest.fixture def newmocksession(mocksession, newconfig): - def newmocksession_(args, source, plugins=()): mocksession.config = newconfig(args, source, plugins=plugins) return mocksession @@ -287,8 +280,8 @@ def initproj_(nameversion, filedefs=None, src_root="."): name, version = nameversion base = tmpdir.join(name) src_root_path = _path_join(base, src_root) - assert ( - base == src_root_path or src_root_path.relto(base) + assert base == src_root_path or src_root_path.relto( + base ), "`src_root` must be the constructed project folder or its direct or indirect subfolder" base.ensure(dir=1) diff --git a/tox/_quickstart.py b/tox/_quickstart.py index bb6c229c60..5304f61b18 100644 --- a/tox/_quickstart.py +++ b/tox/_quickstart.py @@ -78,7 +78,6 @@ def nonempty(x): def choice(*l): - def val(x): if x not in l: raise ValidationError("Please enter one of {}.".format(", ".join(l))) diff --git a/tox/_verlib.py b/tox/_verlib.py index 1c9c7f3155..da1a0a923c 100644 --- a/tox/_verlib.py +++ b/tox/_verlib.py @@ -12,6 +12,7 @@ class IrrationalVersionError(Exception): """This is an irrational version.""" + pass @@ -22,6 +23,7 @@ class HugeMajorVersionNumError(IrrationalVersionError): See `error_on_huge_major_num` option in `NormalizedVersion` for details. This guard can be disabled by setting that option False. """ + pass diff --git a/tox/config.py b/tox/config.py index b3b8a843af..45b3558bec 100755 --- a/tox/config.py +++ b/tox/config.py @@ -99,7 +99,6 @@ def _format_help(self): class VenvAttribute: - def __init__(self, name, type, default, help, postprocess): self.name = name self.type = type @@ -130,11 +129,11 @@ def postprocess(self, testenv_config, value): # in case of a short option, we remove the space for option in tox.PIP.INSTALL_SHORT_OPTIONS_ARGUMENT: if name.startswith(option): - name = "{}{}".format(option, name[len(option):].strip()) + name = "{}{}".format(option, name[len(option) :].strip()) # in case of a long option, we add an equal sign for option in tox.PIP.INSTALL_LONG_OPTIONS_ARGUMENT: if name.startswith(option + " "): - name = "{}={}".format(option, name[len(option):].strip()) + name = "{}={}".format(option, name[len(option) :].strip()) name = self._replace_forced_dep(name, config) deps.append(DepConfig(name, ixserver)) return deps @@ -841,7 +840,6 @@ def make_hashseed(): class parseini: - def __init__(self, config, inipath): config.toxinipath = inipath config.toxinidir = config.toxinipath.dirpath() @@ -1012,7 +1010,7 @@ def _getenvdata(self, reader): all_envs = set(env_list) - {"ALL"} for section in self._cfg: if section.name.startswith(testenvprefix): - all_envs.add(section.name[len(testenvprefix):]) + all_envs.add(section.name[len(testenvprefix) :]) if not all_envs: all_envs.add("python") @@ -1040,7 +1038,6 @@ def _base_factor_name(factor): def _split_factor_expr(expr): - def split_single(e): raw = e.split("-") included = {_base_factor_name(factor) for factor in raw if not _is_negated_factor(factor)} @@ -1074,7 +1071,6 @@ def mapcat(f, seq): class DepConfig: - def __init__(self, name, indexserver=None): self.name = name self.indexserver = indexserver @@ -1090,7 +1086,6 @@ def __str__(self): class IndexServerConfig: - def __init__(self, name, url=None): self.name = name self.url = url @@ -1104,7 +1099,6 @@ def __init__(self, name, url=None): class SectionReader: - def __init__(self, section_name, cfgparser, fallbacksections=None, factors=(), prefix=None): if prefix is None: self.section_name = section_name @@ -1204,7 +1198,6 @@ def getstring(self, name, default=None, replace=True, crossonly=False): return x def _apply_factors(self, s): - def factor_line(line): m = re.search(r"^([\w{}\.!,-]+)\:\s+(.+)", line) if not m: @@ -1326,7 +1319,7 @@ def _replace_env(self, match): def _substitute_from_other_section(self, key): if key.startswith("[") and "]" in key: i = key.find("]") - section, item = key[1:i], key[i + 1:] + section, item = key[1:i], key[i + 1 :] cfg = self.reader._cfg if section in cfg and item in cfg[section]: if (section, item) in self.reader._subststack: @@ -1351,7 +1344,6 @@ def _replace_substitution(self, match): class _ArgvlistReader: - @classmethod def getargvlist(cls, reader, value, replace=True): """Parse ``commands`` argvlist multiline string. @@ -1428,9 +1420,7 @@ def processcommand(cls, reader, command, replace=True): class CommandParser(object): - class State(object): - def __init__(self): self.word = "" self.depth = 0 diff --git a/tox/exception.py b/tox/exception.py index 01d0968fe3..246fca7fb0 100644 --- a/tox/exception.py +++ b/tox/exception.py @@ -32,7 +32,6 @@ def exit_code_str(exception_name, command, exit_code): class Error(Exception): - def __str__(self): return "{}: {}".format(self.__class__.__name__, self.args[0]) diff --git a/tox/interpreters.py b/tox/interpreters.py index c13a503389..1bff7ab54e 100644 --- a/tox/interpreters.py +++ b/tox/interpreters.py @@ -10,7 +10,6 @@ class Interpreters: - def __init__(self, hook): self.name2executable = {} self.executable2info = {} @@ -89,7 +88,6 @@ def exec_on_interpreter(executable, source): class ExecFailed(Exception): - def __init__(self, executable, source, out, err): self.executable = executable self.source = source diff --git a/tox/result.py b/tox/result.py index 5d23f48156..e6dc4c73eb 100644 --- a/tox/result.py +++ b/tox/result.py @@ -8,7 +8,6 @@ class ResultLog: - def __init__(self, data=None): if not data: self.dict = {} @@ -40,7 +39,6 @@ def dumps_json(self): class EnvLog: - def __init__(self, reportlog, name, dict): self.reportlog = reportlog self.name = name @@ -60,7 +58,9 @@ def set_python_info(self, pythonexecutable): version_info = eval(lines.pop(0)) version = "\n".join(lines) self.dict["python"] = { - "executable": executable, "version_info": version_info, "version": version + "executable": executable, + "version_info": version_info, + "version": version, } def get_commandlog(self, name): @@ -71,7 +71,6 @@ def set_installed(self, packages): class CommandLog: - def __init__(self, envlog, list): self.envlog = envlog self.list = list diff --git a/tox/session.py b/tox/session.py index c39b085ec8..ea4b953041 100644 --- a/tox/session.py +++ b/tox/session.py @@ -81,7 +81,6 @@ def show_help_ini(config): class Action(object): - def __init__(self, session, venv, msg, args): self.venv = venv self.msg = msg @@ -412,7 +411,7 @@ def newaction(self, venv, msg, *args): def runcommand(self): self.report.using("tox-{} from {}".format(tox.__version__, tox.__file__)) - verbosity = (self.report.verbosity > Verbosity.DEFAULT) + verbosity = self.report.verbosity > Verbosity.DEFAULT if self.config.option.showconfig: self.showconfig() elif self.config.option.listenvs: @@ -570,9 +569,8 @@ def get_installpkg_path(self): :return: Path to the distribution :rtype: py.path.local """ - if ( - not self.config.option.sdistonly - and (self.config.sdistsrc or self.config.option.installpkg) + if not self.config.option.sdistonly and ( + self.config.sdistsrc or self.config.option.installpkg ): path = self.config.option.installpkg if not path: diff --git a/tox/venv.py b/tox/venv.py index 0ccbb140b5..26804f5904 100755 --- a/tox/venv.py +++ b/tox/venv.py @@ -12,7 +12,6 @@ class CreationConfig: - def __init__(self, md5, python, version, sitepackages, usedevelop, deps, alwayscopy): self.md5 = md5 self.python = python @@ -66,7 +65,6 @@ def matches(self, other): class VirtualEnv(object): - def __init__(self, envconfig=None, session=None): self.envconfig = envconfig self.session = session @@ -279,10 +277,10 @@ def _installopts(self, indexserver): def run_install_command(self, packages, action, options=()): argv = self.envconfig.install_command[:] i = argv.index("{packages}") - argv[i:i + 1] = packages + argv[i : i + 1] = packages if "{opts}" in argv: i = argv.index("{opts}") - argv[i:i + 1] = list(options) + argv[i : i + 1] = list(options) for x in ("PIP_RESPECT_VIRTUALENV", "PIP_REQUIRE_VIRTUALENV", "__PYVENV_LAUNCHER__"): os.environ.pop(x, None)