summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rose <offby1@offby1.net>2011-05-01 23:22:08 -0600
committerChris Rose <offby1@offby1.net>2011-05-01 23:22:08 -0600
commit201268090ce7ed4ccf24e9346901904513de6bc8 (patch)
tree1584ff9446fd2895cec9a28e3d2f2bc5e64e2696
parent7d545e197215f5c08a64ce71b520b381bb826f1f (diff)
parent49f43dea65758d62308bea2e7e1708262bbcb622 (diff)
downloadtox-201268090ce7ed4ccf24e9346901904513de6bc8.tar.gz
Merged upstream
-rw-r--r--tests/test_config.py30
-rw-r--r--tests/test_venv.py28
-rw-r--r--tox/_config.py16
-rw-r--r--tox/_venv.py15
4 files changed, 82 insertions, 7 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index e4e49e3..7d2db89 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -138,6 +138,21 @@ class TestIniParser:
x = reader.getlist("section", "key2")
assert x == ['item1', 'grr']
+ def test_getdict(self, tmpdir, newconfig):
+ config = newconfig("""
+ [section]
+ key2=
+ key1=item1
+ key2={item2}
+ """)
+ reader = IniReader(config._cfg)
+ reader.addsubstitions(item1="not", item2="grr")
+ x = reader.getdict("section", "key2")
+ assert 'key1' in x
+ assert 'key2' in x
+ assert x['key1'] == 'item1'
+ assert x['key2'] == 'grr'
+
def test_getdefault_environment_substitution(self, monkeypatch, newconfig):
monkeypatch.setenv("KEY1", "hello")
config = newconfig("""
@@ -296,6 +311,7 @@ class TestConfigTestEnv:
assert envconfig.distribute == True
assert envconfig.sitepackages == False
assert envconfig.envlogdir == envconfig.envdir.join("log")
+ assert envconfig.environment is None
def test_specific_command_overrides(self, tmpdir, newconfig):
config = newconfig("""
@@ -336,6 +352,20 @@ class TestConfigTestEnv:
envconfig = config.envconfigs['python']
assert envconfig.envpython == envconfig.envbindir.join("jython")
+ def test_environment_overrides(self, tmpdir, newconfig):
+ config = newconfig("""
+ [testenv]
+ environment =
+ PYTHONPATH = something
+ ANOTHER_VAL=else
+ """)
+ assert len(config.envconfigs) == 1
+ envconfig = config.envconfigs['python']
+ assert 'PYTHONPATH' in envconfig.environment
+ assert 'ANOTHER_VAL' in envconfig.environment
+ assert envconfig.environment['PYTHONPATH'] == 'something'
+ assert envconfig.environment['ANOTHER_VAL'] == 'else'
+
def test_changedir_override(self, tmpdir, newconfig):
config = newconfig("""
[testenv]
diff --git a/tests/test_venv.py b/tests/test_venv.py
index e8dd793..3def794 100644
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -207,7 +207,7 @@ def test_install_error(newmocksession):
venv = mocksession.getenv('python')
venv.test()
mocksession.report.expect("error", "*not find*qwelkqw*")
-
+
def test_install_python3(tmpdir, newmocksession):
if not py.path.local.sysfind('python3.1'):
py.test.skip("needs python3.1")
@@ -340,7 +340,7 @@ class TestCreationConfig:
mocksession._clearmocks()
venv.update()
mocksession.report.expect("action", "recreating virtualenv*")
-
+
class TestVenvTest:
def test_patchPATH(self, newmocksession, monkeypatch):
@@ -373,6 +373,30 @@ class TestVenvTest:
assert 'PIP_RESPECT_VIRTUALENV' not in os.environ
os.environ['PIP_RESPECT_VIRTUALENV'] = "1"
+def test_session_environment_added_to_pcall(mocksession, newconfig):
+ config = newconfig([], """
+ [testenv:python]
+ commands=%s -V
+ environment =
+ ENV_VAR = value
+ """ % sys.executable)
+ mocksession._clearmocks()
+
+ venv = VirtualEnv(config.envconfigs['python'], session=mocksession)
+ # import pdb; pdb.set_trace()
+ venv.test()
+
+ l = mocksession._pcalls
+ assert len(l) == 1
+ args = l[0].args
+ env = l[0].env
+ assert env is not None
+ assert 'ENV_VAR' in env
+ assert env['ENV_VAR'] == 'value'
+
+ for e in os.environ:
+ assert e in env
+
def test_install_sdist_upgrade_mode(newmocksession):
mocksession = newmocksession([], "")
venv = mocksession.getenv('python')
diff --git a/tox/_config.py b/tox/_config.py
index d76fed4..738da33 100644
--- a/tox/_config.py
+++ b/tox/_config.py
@@ -209,6 +209,10 @@ class parseini:
arg = vc.changedir.bestrelpath(origpath)
args.append(arg)
reader.addsubstitions(args)
+ vc.environment = reader.getdict(section, 'environment')
+ if not vc.environment:
+ vc.environment = None
+
vc.commands = reader.getargvlist(section, "commands")
vc.deps = []
for depline in reader.getlist(section, "deps"):
@@ -285,6 +289,18 @@ class IniReader:
return []
return [x.strip() for x in s.split(sep) if x.strip()]
+ def getdict(self, section, name, sep="\n"):
+ s = self.getdefault(section, name, None)
+ if s is None:
+ return {}
+
+ value = {}
+ for line in s.split(sep):
+ name, rest = line.split('=', 1)
+ value[name.strip()] = rest.strip()
+
+ return value
+
def getargvlist(self, section, name):
s = self.getdefault(section, name, '', replace=False)
#if s is None:
diff --git a/tox/_venv.py b/tox/_venv.py
index 597ab2c..8128be4 100644
--- a/tox/_venv.py
+++ b/tox/_venv.py
@@ -231,14 +231,21 @@ class VirtualEnv(object):
def test(self):
self.session.make_emptydir(self.envconfig.envtmpdir)
cwd = self.envconfig.changedir
+ env = self.envconfig.environment
+ if env:
+ env_arg = os.environ.copy()
+ env_arg.update(env)
+ else:
+ env_arg = None
+
for argv in self.envconfig.commands:
try:
- self._pcall(argv, log=-1, cwd=cwd)
+ self._pcall(argv, log=-1, cwd=cwd, env=env_arg)
except tox.exception.InvocationError:
self.session.report.error(str(sys.exc_info()[1]))
return True
- def _pcall(self, args, venv=True, log=None, cwd=None):
+ def _pcall(self, args, venv=True, log=None, cwd=None, env=None):
try:
del os.environ['PYTHONDONTWRITEBYTECODE']
except KeyError:
@@ -249,7 +256,7 @@ class VirtualEnv(object):
args = [self.getcommandpath(args[0])] + args[1:]
if log is None:
log = self.path.ensure("log", dir=1)
- return self.session.pcall(args, log=log, cwd=cwd)
+ return self.session.pcall(args, log=log, cwd=cwd, env=env)
finally:
os.environ['PATH'] = old
@@ -289,5 +296,3 @@ else:
actual = py.path.local(actual)
if actual.check():
return actual
-
-