summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorholger krekel <holger@merlinux.eu>2015-12-09 11:53:22 +0100
committerholger krekel <holger@merlinux.eu>2015-12-09 11:53:22 +0100
commit0727c11dc89eac86c14ac87f049f7f7b184fe720 (patch)
treece1c662705134d6fd74745cbf107c9e897f4d849
parentd04020f40e5108a4662c045748c966c70edebe5c (diff)
downloadtox-0727c11dc89eac86c14ac87f049f7f7b184fe720.tar.gz
internal: push some optional object creation into tests because
tox core doesn't need it.
-rw-r--r--CHANGELOG2
-rw-r--r--tests/test_venv.py77
-rw-r--r--tests/test_z_cmdline.py3
-rw-r--r--tox/venv.py15
4 files changed, 58 insertions, 39 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1358ca6..3396dd7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -16,6 +16,8 @@
- fix issue252: allow environment names with special characters.
Thanks Julien Castets for initial PR and patience.
+- internal: push some optional object creation into tests because
+ tox core doesn't need it.
2.2.1
-----
diff --git a/tests/test_venv.py b/tests/test_venv.py
index b454f5b..217b21e 100644
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -56,7 +56,8 @@ def test_create(monkeypatch, mocksession, newconfig):
venv = VirtualEnv(envconfig, session=mocksession)
assert venv.path == envconfig.envdir
assert not venv.path.check()
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) >= 1
args = l[0].args
@@ -96,7 +97,8 @@ def test_create_sitepackages(monkeypatch, mocksession, newconfig):
""")
envconfig = config.envconfigs['site']
venv = VirtualEnv(envconfig, session=mocksession)
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) >= 1
args = l[0].args
@@ -105,7 +107,8 @@ def test_create_sitepackages(monkeypatch, mocksession, newconfig):
envconfig = config.envconfigs['nosite']
venv = VirtualEnv(envconfig, session=mocksession)
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) >= 1
args = l[0].args
@@ -122,14 +125,15 @@ def test_install_deps_wildcard(newmocksession):
{distshare}/dep1-*
""")
venv = mocksession.getenv("py123")
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) == 1
distshare = venv.session.config.distshare
distshare.ensure("dep1-1.0.zip")
distshare.ensure("dep1-1.1.zip")
- venv.install_deps()
+ venv.install_deps(action)
assert len(l) == 2
args = l[-1].args
assert l[-1].cwd == venv.envconfig.config.toxinidir
@@ -154,11 +158,12 @@ def test_install_downloadcache(newmocksession, monkeypatch, tmpdir, envdc):
dep2
""")
venv = mocksession.getenv("py123")
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) == 1
- venv.install_deps()
+ venv.install_deps(action)
assert len(l) == 2
args = l[-1].args
assert l[-1].cwd == venv.envconfig.config.toxinidir
@@ -183,12 +188,13 @@ def test_install_deps_indexserver(newmocksession):
:abc2:dep3
""")
venv = mocksession.getenv('py123')
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) == 1
l[:] = []
- venv.install_deps()
+ venv.install_deps(action)
# two different index servers, two calls
assert len(l) == 3
args = " ".join(l[0].args)
@@ -211,12 +217,13 @@ def test_install_deps_pre(newmocksession):
dep1
""")
venv = mocksession.getenv('python')
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) == 1
l[:] = []
- venv.install_deps()
+ venv.install_deps(action)
assert len(l) == 1
args = " ".join(l[0].args)
assert "--pre " in args
@@ -246,10 +253,12 @@ def test_install_recreate(newmocksession, tmpdir):
deps=xyz
""")
venv = mocksession.getenv('python')
- venv.update()
+
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
mocksession.installpkg(venv, pkg)
mocksession.report.expect("verbosity0", "*create*")
- venv.update()
+ venv.update(action)
mocksession.report.expect("verbosity0", "*recreate*")
@@ -263,7 +272,8 @@ def test_test_hashseed_is_in_output(newmocksession):
finally:
tox.config.make_hashseed = original_make_hashseed
venv = mocksession.getenv('python')
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
venv.test()
mocksession.report.expect("verbosity0", "python runtests: PYTHONHASHSEED='123456789'")
@@ -274,7 +284,8 @@ def test_test_runtests_action_command_is_in_output(newmocksession):
commands = echo foo bar
''')
venv = mocksession.getenv('python')
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
venv.test()
mocksession.report.expect("verbosity0", "*runtests*commands?0? | echo foo bar")
@@ -343,7 +354,8 @@ def test_install_python3(tmpdir, newmocksession):
dep2
""")
venv = mocksession.getenv('py123')
- venv.create()
+ action = mocksession.newaction(venv, "getenv")
+ venv.create(action)
l = mocksession._pcalls
assert len(l) == 1
args = l[0].args
@@ -429,7 +441,8 @@ class TestCreationConfig:
envconfig = config.envconfigs['python']
venv = VirtualEnv(envconfig, session=mocksession)
cconfig = venv._getliveconfig()
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
assert not venv.path_config.check()
mocksession.installpkg(venv, pkg)
assert venv.path_config.check()
@@ -439,36 +452,42 @@ class TestCreationConfig:
mocksession.report.expect("*", "*create*")
# modify config and check that recreation happens
mocksession._clearmocks()
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
mocksession.report.expect("*", "*reusing*")
mocksession._clearmocks()
+ action = mocksession.newaction(venv, "update")
cconfig.python = py.path.local("balla")
cconfig.writeconfig(venv.path_config)
- venv.update()
+ venv.update(action)
mocksession.report.expect("verbosity0", "*recreate*")
def test_dep_recreation(self, newconfig, mocksession):
config = newconfig([], "")
envconfig = config.envconfigs['python']
venv = VirtualEnv(envconfig, session=mocksession)
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
cconfig = venv._getliveconfig()
cconfig.deps[:] = [("1" * 32, "xyz.zip")]
cconfig.writeconfig(venv.path_config)
mocksession._clearmocks()
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
mocksession.report.expect("*", "*recreate*")
def test_develop_recreation(self, newconfig, mocksession):
config = newconfig([], "")
envconfig = config.envconfigs['python']
venv = VirtualEnv(envconfig, session=mocksession)
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
cconfig = venv._getliveconfig()
cconfig.usedevelop = True
cconfig.writeconfig(venv.path_config)
mocksession._clearmocks()
- venv.update()
+ action = mocksession.newaction(venv, "update")
+ venv.update(action)
mocksession.report.expect("verbosity0", "*recreate*")
@@ -481,21 +500,25 @@ class TestVenvTest:
commands=abc
""")
venv = mocksession.getenv("python")
+ action = mocksession.newaction(venv, "getenv")
monkeypatch.setenv("PATH", "xyz")
l = []
monkeypatch.setattr("py.path.local.sysfind", classmethod(
lambda *args, **kwargs: l.append(kwargs) or 0 / 0))
- py.test.raises(ZeroDivisionError, "venv._install(list('123'))")
+ with pytest.raises(ZeroDivisionError):
+ venv._install(list('123'), action=action)
assert l.pop()["paths"] == [venv.envconfig.envbindir]
- py.test.raises(ZeroDivisionError, "venv.test()")
+ with pytest.raises(ZeroDivisionError):
+ venv.test(action)
assert l.pop()["paths"] == [venv.envconfig.envbindir]
- py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'])")
+ with pytest.raises(ZeroDivisionError):
+ venv.run_install_command(['qwe'], action=action)
assert l.pop()["paths"] == [venv.envconfig.envbindir]
monkeypatch.setenv("PIP_RESPECT_VIRTUALENV", "1")
monkeypatch.setenv("PIP_REQUIRE_VIRTUALENV", "1")
monkeypatch.setenv("__PYVENV_LAUNCHER__", "1")
- py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'])")
+ py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'], action=action)")
assert 'PIP_RESPECT_VIRTUALENV' not in os.environ
assert 'PIP_REQUIRE_VIRTUALENV' not in os.environ
assert '__PYVENV_LAUNCHER__' not in os.environ
diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py
index d589a1d..a98d211 100644
--- a/tests/test_z_cmdline.py
+++ b/tests/test_z_cmdline.py
@@ -34,7 +34,8 @@ def test_report_protocol(newconfig):
report = session.report
report.expect("using")
venv = session.getvenv("mypython")
- venv.update()
+ action = session.newaction(venv, "update")
+ venv.update(action)
report.expect("logpopen")
diff --git a/tox/venv.py b/tox/venv.py
index eaa555a..499c6f1 100644
--- a/tox/venv.py
+++ b/tox/venv.py
@@ -114,12 +114,10 @@ class VirtualEnv(object):
def _ispython3(self):
return "python3" in str(self.envconfig.basepython)
- def update(self, action=None):
+ def update(self, action):
""" return status string for updating actual venv to match configuration.
if status string is empty, all is ok.
"""
- if action is None:
- action = self.session.newaction(self, "update")
rconfig = CreationConfig.readconfig(self.path_config)
if not self.envconfig.recreate and rconfig and \
rconfig.matches(self._getliveconfig()):
@@ -172,12 +170,9 @@ class VirtualEnv(object):
def matching_platform(self):
return re.match(self.envconfig.platform, sys.platform)
- def create(self, action=None):
+ def create(self, action):
# if self.getcommandpath("activate").dirpath().check():
# return
- if action is None:
- action = self.session.newaction(self, "create")
-
config_interpreter = self.getsupportedinterpreter()
args = [sys.executable, '-m', 'virtualenv']
if self.envconfig.sitepackages:
@@ -239,9 +234,7 @@ class VirtualEnv(object):
extraopts = ['-U', '--no-deps']
self._install([sdistpath], extraopts=extraopts, action=action)
- def install_deps(self, action=None):
- if action is None:
- action = self.session.newaction(self, "install_deps")
+ def install_deps(self, action):
deps = self._getresolvedeps()
if deps:
depinfo = ", ".join(map(str, deps))
@@ -259,7 +252,7 @@ class VirtualEnv(object):
l.append("--pre")
return l
- def run_install_command(self, packages, options=(), action=None):
+ def run_install_command(self, packages, action, options=()):
argv = self.envconfig.install_command[:]
# use pip-script on win32 to avoid the executable locking
i = argv.index('{packages}')