summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorholger krekel <holger@merlinux.eu>2014-05-15 11:33:28 +0200
committerholger krekel <holger@merlinux.eu>2014-05-15 11:33:28 +0200
commit360ee98eae10511bb32c82997052ff1ab278033f (patch)
treed8b30b7e0fed866b427ec3992bc427f797d4ca19 /tests
parent23380da3f729a37106cc6ca2023429bdb547c780 (diff)
parent20de40c837b9616bb08c155fe108b61cc50cfae6 (diff)
downloadtox-360ee98eae10511bb32c82997052ff1ab278033f.tar.gz
Merged in cboylan/tox (pull request #85)
Fix command expansion and parsing.
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/test_config.py27
-rw-r--r--tests/test_interpreters.py2
-rw-r--r--tests/test_quickstart.py180
-rw-r--r--tests/test_venv.py17
-rw-r--r--tests/test_z_cmdline.py35
6 files changed, 214 insertions, 49 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 1d4bdde..3e2493b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,2 +1,2 @@
-from tox._pytestplugin import *
+from tox._pytestplugin import * # noqa
diff --git a/tests/test_config.py b/tests/test_config.py
index 93d7659..c55f43a 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -1,12 +1,11 @@
-import tox
-import pytest
-import os, sys
-import subprocess
+import sys
from textwrap import dedent
import py
+import pytest
+import tox
import tox._config
-from tox._config import *
+from tox._config import * # noqa
from tox._config import _split_env
@@ -110,7 +109,6 @@ class TestConfigPackage:
def test_defaults_distshare(self, tmpdir, newconfig):
config = newconfig([], "")
- envconfig = config.envconfigs['python']
assert config.distshare == config.homedir.join(".tox", "distshare")
def test_defaults_changed_dir(self, tmpdir, newconfig):
@@ -168,6 +166,7 @@ class TestIniParser:
key2={xyz}
""")
reader = IniReader(config._cfg, fallbacksections=['mydefault'])
+ assert reader is not None
py.test.raises(tox.exception.ConfigError,
'reader.getdefault("mydefault", "key2")')
@@ -242,6 +241,22 @@ class TestIniParser:
py.test.raises(tox.exception.ConfigError,
'reader.getdefault("section", "key2")')
+ def test_getdefault_environment_substitution_with_default(self, monkeypatch, newconfig):
+ monkeypatch.setenv("KEY1", "hello")
+ config = newconfig("""
+ [section]
+ key1={env:KEY1:DEFAULT_VALUE}
+ key2={env:KEY2:DEFAULT_VALUE}
+ key3={env:KEY3:}
+ """)
+ reader = IniReader(config._cfg)
+ x = reader.getdefault("section", "key1")
+ assert x == "hello"
+ x = reader.getdefault("section", "key2")
+ assert x == "DEFAULT_VALUE"
+ x = reader.getdefault("section", "key3")
+ assert x == ""
+
def test_getdefault_other_section_substitution(self, newconfig):
config = newconfig("""
[section]
diff --git a/tests/test_interpreters.py b/tests/test_interpreters.py
index 39eabc6..f06a69a 100644
--- a/tests/test_interpreters.py
+++ b/tests/test_interpreters.py
@@ -2,7 +2,7 @@ import sys
import os
import pytest
-from tox.interpreters import *
+from tox.interpreters import * # noqa
@pytest.fixture
def interpreters():
diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py
index c376d4b..df8a98f 100644
--- a/tests/test_quickstart.py
+++ b/tests/test_quickstart.py
@@ -6,6 +6,7 @@ import tox._quickstart
def cleandir(tmpdir):
tmpdir.chdir()
+
class TestToxQuickstartMain(object):
def mock_term_input_return_values(self, return_values):
@@ -23,12 +24,26 @@ class TestToxQuickstartMain(object):
return mock_term_input
- def test_quickstart_main_choose_individual_pythons_and_pytest(self,
- monkeypatch):
+ def test_quickstart_main_choose_individual_pythons_and_pytest(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
self.get_mock_term_input(
- ['4', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'py.test', 'pytest']))
+ [
+ '4', # Python versions: choose one by one
+ 'Y', # py26
+ 'Y', # py27
+ 'Y', # py32
+ 'Y', # py33
+ 'Y', # py34
+ 'Y', # pypy
+ 'N', # jython
+ 'py.test', # command to run tests
+ 'pytest' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -39,7 +54,7 @@ class TestToxQuickstartMain(object):
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy
+envlist = py26, py27, py32, py33, py34, pypy
[testenv]
commands = py.test
@@ -49,11 +64,26 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_individual_pythons_and_nose_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_individual_pythons_and_nose_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'Y', 'N',
- 'nosetests', '']))
+ self.get_mock_term_input(
+ [
+ '4', # Python versions: choose one by one
+ 'Y', # py26
+ 'Y', # py27
+ 'Y', # py32
+ 'Y', # py33
+ 'Y', # py34
+ 'Y', # pypy
+ 'N', # jython
+ 'nosetests', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -64,7 +94,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy
+envlist = py26, py27, py32, py33, py34, pypy
[testenv]
commands = nosetests
@@ -74,11 +104,26 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_individual_pythons_and_trial_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_individual_pythons_and_trial_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'Y', 'N',
- 'trial', '']))
+ self.get_mock_term_input(
+ [
+ '4', # Python versions: choose one by one
+ 'Y', # py26
+ 'Y', # py27
+ 'Y', # py32
+ 'Y', # py33
+ 'Y', # py34
+ 'Y', # pypy
+ 'N', # jython
+ 'trial', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -89,7 +134,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy
+envlist = py26, py27, py32, py33, py34, pypy
[testenv]
commands = trial
@@ -99,11 +144,26 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_individual_pythons_and_pytest_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_individual_pythons_and_pytest_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'Y', 'N',
- 'py.test', '']))
+ self.get_mock_term_input(
+ [
+ '4', # Python versions: choose one by one
+ 'Y', # py26
+ 'Y', # py27
+ 'Y', # py32
+ 'Y', # py33
+ 'Y', # py34
+ 'Y', # pypy
+ 'N', # jython
+ 'py.test', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
expected_tox_ini = """
@@ -113,7 +173,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy
+envlist = py26, py27, py32, py33, py34, pypy
[testenv]
commands = py.test
@@ -123,10 +183,19 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_py27_and_pytest_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_py27_and_pytest_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['1', 'py.test', '']))
+ self.get_mock_term_input(
+ [
+ '1', # py27
+ 'py.test', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -147,10 +216,19 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_py27_and_py33_and_pytest_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_py27_and_py33_and_pytest_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['2', 'py.test', '']))
+ self.get_mock_term_input(
+ [
+ '2', # py27 and py33
+ 'py.test', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -171,10 +249,19 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_all_pythons_and_pytest_adds_deps(self, monkeypatch):
+ def test_quickstart_main_choose_all_pythons_and_pytest_adds_deps(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['3', 'py.test', '']))
+ self.get_mock_term_input(
+ [
+ '3', # all Python versions
+ 'py.test', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -185,7 +272,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy, jython
+envlist = py26, py27, py32, py33, py34, pypy, jython
[testenv]
commands = py.test
@@ -195,10 +282,26 @@ deps =
result = open('tox.ini').read()
assert(result == expected_tox_ini)
- def test_quickstart_main_choose_individual_pythons_and_defaults(self, monkeypatch):
+ def test_quickstart_main_choose_individual_pythons_and_defaults(
+ self,
+ monkeypatch):
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['4', '', '', '', '', '', '', '', '', '', '']))
+ self.get_mock_term_input(
+ [
+ '4', # Python versions: choose one by one
+ '', # py26
+ '', # py27
+ '', # py32
+ '', # py33
+ '', # py34
+ '', # pypy
+ '', # jython
+ '', # command to run tests
+ '' # test dependencies
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -209,7 +312,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy, jython
+envlist = py26, py27, py32, py33, py34, pypy, jython
[testenv]
commands = {envpython} setup.py test
@@ -228,7 +331,22 @@ deps =
monkeypatch.setattr(
tox._quickstart, 'term_input',
- self.get_mock_term_input(['4', '', '', '', '', '', '', '', '', '', '', '']))
+ self.get_mock_term_input(
+ [
+ '4', # Python versions: choose one by one
+ '', # py26
+ '', # py27
+ '', # py32
+ '', # py33
+ '', # py34
+ '', # pypy
+ '', # jython
+ '', # command to run tests
+ '', # test dependencies
+ '', # tox.ini already exists; overwrite?
+ ]
+ )
+ )
tox._quickstart.main(argv=['tox-quickstart'])
@@ -239,7 +357,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy, jython
+envlist = py26, py27, py32, py33, py34, pypy, jython
[testenv]
commands = {envpython} setup.py test
@@ -257,6 +375,7 @@ class TestToxQuickstart(object):
'py27': True,
'py32': True,
'py33': True,
+ 'py34': True,
'pypy': True,
'commands': 'py.test',
'deps': 'pytest',
@@ -268,7 +387,7 @@ class TestToxQuickstart(object):
# and then run "tox" from this directory.
[tox]
-envlist = py26, py27, py32, py33, pypy
+envlist = py26, py27, py32, py33, py34, pypy
[testenv]
commands = py.test
@@ -339,6 +458,7 @@ deps =
'py27': True,
'py32': True,
'py33': True,
+ 'py34': True,
'pypy': True,
'commands': 'nosetests -v',
'deps': 'nose',
@@ -350,7 +470,7 @@ deps =
# and then run "tox" from this directory.
[tox]
-envlist = py27, py32, py33, pypy
+envlist = py27, py32, py33, py34, pypy
[testenv]
commands = nosetests -v
diff --git a/tests/test_venv.py b/tests/test_venv.py
index c2ed371..dbfec41 100644
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -3,7 +3,7 @@ import tox
import pytest
import os, sys
import tox._config
-from tox._venv import *
+from tox._venv import * # noqa
#def test_global_virtualenv(capfd):
# v = VirtualEnv()
@@ -48,8 +48,11 @@ def test_create(monkeypatch, mocksession, newconfig):
l = mocksession._pcalls
assert len(l) >= 1
args = l[0].args
- assert "virtualenv" in str(args[0])
+ assert "virtualenv" in str(args[1])
if sys.platform != "win32":
+ # realpath is needed for stuff like the debian symlinks
+ assert py.path.local(sys.executable).realpath() \
+ == py.path.local(args[0]).realpath()
#assert Envconfig.toxworkdir in args
assert venv.getcommandpath("easy_install", cwd=py.path.local())
interp = venv._getliveconfig().python
@@ -274,7 +277,7 @@ def test_install_command_not_installed(newmocksession, monkeypatch):
venv = mocksession.getenv('python')
venv.test()
mocksession.report.expect("warning", "*test command found but not*")
- assert venv.status == "commands failed"
+ assert venv.status == 0
def test_install_command_whitelisted(newmocksession, monkeypatch):
mocksession = newmocksession(['--recreate'], """
@@ -292,7 +295,7 @@ def test_install_command_whitelisted(newmocksession, monkeypatch):
assert venv.status == "commands failed"
@pytest.mark.skipif("not sys.platform.startswith('linux')")
-def test_install_command_not_installed(newmocksession):
+def test_install_command_not_installed_bash(newmocksession):
mocksession = newmocksession(['--recreate'], """
[testenv]
commands=
@@ -318,7 +321,7 @@ def test_install_python3(tmpdir, newmocksession):
l = mocksession._pcalls
assert len(l) == 1
args = l[0].args
- assert str(args[0]).endswith('virtualenv')
+ assert str(args[1]).endswith('virtualenv')
l[:] = []
action = mocksession.newaction(venv, "hello")
venv._install(["hello"], action=action)
@@ -384,7 +387,7 @@ class TestCreationConfig:
[testenv]
deps={distshare}/xyz-*
""")
- xyz = config.distshare.ensure("xyz-1.2.0.zip")
+ config.distshare.ensure("xyz-1.2.0.zip")
xyz2 = config.distshare.ensure("xyz-1.2.1.zip")
envconfig = config.envconfigs['python']
venv = VirtualEnv(envconfig, session=mocksession)
@@ -504,7 +507,6 @@ def test_setenv_added_to_pcall(tmpdir, mocksession, newconfig):
l = mocksession._pcalls
assert len(l) == 2
for x in l:
- args = x.args
env = x.env
assert env is not None
assert 'ENV_VAR' in env
@@ -582,6 +584,7 @@ def test_command_relative_issue26(newmocksession, tmpdir, monkeypatch):
mocksession.report.not_expect("warning", "*test command found but not*")
monkeypatch.setenv("PATH", str(tmpdir))
x4 = venv.getcommandpath("x", cwd=tmpdir)
+ assert x4.endswith('/x')
mocksession.report.expect("warning", "*test command found but not*")
def test_sethome_only_on_option(newmocksession, monkeypatch):
diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py
index 343c142..283c993 100644
--- a/tests/test_z_cmdline.py
+++ b/tests/test_z_cmdline.py
@@ -1,7 +1,6 @@
import tox
import py
import pytest
-import sys
from tox._pytestplugin import ReportExpectMock
try:
import json
@@ -129,7 +128,6 @@ class TestSession:
})
config = parseconfig([])
session = Session(config)
- envlist = ['hello', 'world']
envs = session.venvlist
assert len(envs) == 2
env1, env2 = envs
@@ -193,6 +191,19 @@ def test_minversion(cmd, initproj):
])
assert result.ret
+def test_run_custom_install_command_error(cmd, initproj):
+ initproj("interp123-0.5", filedefs={
+ 'tox.ini': '''
+ [testenv]
+ install_command=./tox.ini {opts} {packages}
+ '''
+ })
+ result = cmd.run("tox")
+ result.stdout.fnmatch_lines([
+ "ERROR: invocation failed, args: ['*/tox.ini*",
+ ])
+ assert result.ret
+
def test_unknown_interpreter_and_env(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
@@ -231,6 +242,22 @@ def test_unknown_interpreter(cmd, initproj):
"*ERROR*InterpreterNotFound*xyz_unknown_interpreter*",
])
+def test_skip_unknown_interpreter(cmd, initproj):
+ initproj("interp123-0.5", filedefs={
+ 'tests': {'test_hello.py': "def test_hello(): pass"},
+ 'tox.ini': '''
+ [testenv:python]
+ basepython=xyz_unknown_interpreter
+ [testenv]
+ changedir=tests
+ '''
+ })
+ result = cmd.run("tox", "--skip-missing-interpreters")
+ assert not result.ret
+ result.stdout.fnmatch_lines([
+ "*SKIPPED*InterpreterNotFound*xyz_unknown_interpreter*",
+ ])
+
def test_unknown_dep(cmd, initproj):
initproj("dep123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
@@ -567,7 +594,7 @@ def test_sdistonly(initproj, cmd):
result.stdout.fnmatch_lines([
"*sdist-make*setup.py*",
])
- assert "virtualenv" not in result.stdout.str()
+ assert "-mvirtualenv" not in result.stdout.str()
def test_separate_sdist_no_sdistfile(cmd, initproj):
distshare = cmd.tmpdir.join("distshare")
@@ -582,6 +609,7 @@ def test_separate_sdist_no_sdistfile(cmd, initproj):
l = distshare.listdir()
assert len(l) == 1
sdistfile = l[0]
+ assert 'pkg123-0.7.zip' in str(sdistfile)
def test_separate_sdist(cmd, initproj):
distshare = cmd.tmpdir.join("distshare")
@@ -611,7 +639,6 @@ def test_sdist_latest(tmpdir, newconfig):
distshare=%s
sdistsrc={distshare}/pkg123-*
""" % distshare)
- p0 = distshare.ensure("pkg123-1.3.5.zip")
p = distshare.ensure("pkg123-1.4.5.zip")
distshare.ensure("pkg123-1.4.5a1.zip")
session = Session(config)