Skip to content

Commit

Permalink
pr feedback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed May 13, 2018
1 parent 7474be8 commit 8cafe90
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 142 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
151 changes: 64 additions & 87 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
26 changes: 10 additions & 16 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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", "<command>", exit_code)
)
call_args = tox.exception.exit_code_str.call_args
assert call_args == mocker.call("InvocationError", "<command>", exit_code)
if exit_code is None:
assert "(exited with code" not in result
else:
Expand Down
29 changes: 17 additions & 12 deletions tests/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions tox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +34,5 @@
except DistributionNotFound:
__version__ = "0.0.0.dev0"


# NOTE: must come last due to circular import
from .session import cmdline # noqa
6 changes: 3 additions & 3 deletions tox/_pytestplugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox/_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import codecs
import os
import sys
import textwrap

import six
import textwrap

import tox

Expand Down
Loading

0 comments on commit 8cafe90

Please sign in to comment.