6 new commits in tox:
https://bitbucket.org/hpk42/tox/commits/a9f2579c2505/
Changeset: a9f2579c2505
Branch: fix_env_use
User: itxaka
Date: 2015-08-23 18:50:15+00:00
Summary: If the {env:key:default} paremeter is found in the config but
there are no environment variables yet, fall back to the current section setenv
variables
Affected #: 1 file
diff -r 3ed5dc353a99acf57859a2dd265b5c2e973480e3 -r
a9f2579c2505ddfac7201dda089d6c47ae8acf81 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -903,6 +903,7 @@
return '\n'.join(filter(None, map(factor_line, lines)))
def _replace_env(self, match):
+ env_list = self._build_envs_list()
match_value = match.group('substitution_value')
if not match_value:
raise tox.exception.ConfigError(
@@ -917,11 +918,21 @@
envkey = match_value
if envkey not in os.environ and default is None:
- raise tox.exception.ConfigError(
- "substitution env:%r: unknown environment variable %r" %
- (envkey, envkey))
+ if envkey not in env_list and default is None:
+ raise tox.exception.ConfigError(
+ "substitution env:%r: unknown environment variable %r" %
+ (envkey, envkey))
+ if envkey in os.environ:
+ return os.environ.get(envkey, default)
+ else:
+ return env_list.get(envkey, default)
- return os.environ.get(envkey, default)
+ def _build_envs_list(self):
+ full_envs = self._cfg[self.section_name].get('setenv')
+ if full_envs:
+ return {k.split('=')[0]: k.split('=')[1] for k in
full_envs.split('\n')}
+ else:
+ return {}
def _substitute_from_other_section(self, key):
if key.startswith("[") and "]" in key:
https://bitbucket.org/hpk42/tox/commits/cbd7d04d37b5/
Changeset: cbd7d04d37b5
Branch: fix_env_use
User: itxaka
Date: 2015-08-24 07:58:06+00:00
Summary: if there is no setenv section, return an empty dict
Affected #: 1 file
diff -r a9f2579c2505ddfac7201dda089d6c47ae8acf81 -r
cbd7d04d37b59a0c46620195538b57b9a8ae0303 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -928,7 +928,7 @@
return env_list.get(envkey, default)
def _build_envs_list(self):
- full_envs = self._cfg[self.section_name].get('setenv')
+ full_envs = self._cfg[self.section_name].get('setenv', False)
if full_envs:
return {k.split('=')[0]: k.split('=')[1] for k in
full_envs.split('\n')}
else:
https://bitbucket.org/hpk42/tox/commits/ab76209b4106/
Changeset: ab76209b4106
Branch: fix_env_use
User: itxaka
Date: 2015-08-31 09:26:00+00:00
Summary: Add tests
Affected #: 1 file
diff -r cbd7d04d37b59a0c46620195538b57b9a8ae0303 -r
ab76209b41064bcfd9fe9d67e422487daaca9cd0 tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -254,6 +254,28 @@
["echo", "cmd", "1", "2", "3", "4", "cmd", "2"],
]
+ def test_command_env_substitution(self, newconfig):
+ """Ensure referenced {env:key:default} values are substituted
correctly."""
+ config = newconfig("""
+ [testenv:py27]
+ setenv =
+ TEST=testvalue
+ commands =
+ ls {env:TEST}
+ """)
+ reader = SectionReader("testenv:py27", config._cfg)
+ x = reader.getargvlist("commands")
+ assert x == [
+ "ls testvalue".split()
+ ]
+ assert x != [
+ "ls {env:TEST}".split()
+ ]
+ y = reader.getargvlist("setenv")
+ assert y == [
+ "TEST=testvalue".split()
+ ]
+
class TestIniParser:
def test_getstring_single(self, tmpdir, newconfig):
https://bitbucket.org/hpk42/tox/commits/b611c45a558b/
Changeset: b611c45a558b
Branch: fix_env_use
User: itxaka
Date: 2015-08-31 13:08:54+00:00
Summary: better workflow, picks the resolved envs instead of the written
string
Affected #: 1 file
diff -r ab76209b41064bcfd9fe9d67e422487daaca9cd0 -r
b611c45a558b9c15687bd5e198a1ba04a0a55067 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -928,11 +928,12 @@
return env_list.get(envkey, default)
def _build_envs_list(self):
- full_envs = self._cfg[self.section_name].get('setenv', False)
- if full_envs:
- return {k.split('=')[0]: k.split('=')[1] for k in
full_envs.split('\n')}
- else:
- return {}
+ full_envs = self.getargvlist('setenv')
+ return_data = {}
+ for item in full_envs:
+ splitted = " ".join(item).split("=")
+ return_data[splitted[0]] = splitted[1]
+ return return_data
def _substitute_from_other_section(self, key):
if key.startswith("[") and "]" in key:
https://bitbucket.org/hpk42/tox/commits/d21e7d2340a0/
Changeset: d21e7d2340a0
Branch: fix_env_use
User: itxaka
Date: 2015-10-30 08:49:50+00:00
Summary: use self.getdict('setenv') instead of extra parsing that fails
Affected #: 1 file
diff -r b611c45a558b9c15687bd5e198a1ba04a0a55067 -r
d21e7d2340a0351b730daa8824786ef666a89e28 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -903,7 +903,7 @@
return '\n'.join(filter(None, map(factor_line, lines)))
def _replace_env(self, match):
- env_list = self._build_envs_list()
+ env_list = self.getdict('setenv')
match_value = match.group('substitution_value')
if not match_value:
raise tox.exception.ConfigError(
@@ -927,14 +927,6 @@
else:
return env_list.get(envkey, default)
- def _build_envs_list(self):
- full_envs = self.getargvlist('setenv')
- return_data = {}
- for item in full_envs:
- splitted = " ".join(item).split("=")
- return_data[splitted[0]] = splitted[1]
- return return_data
-
def _substitute_from_other_section(self, key):
if key.startswith("[") and "]" in key:
i = key.find("]")
https://bitbucket.org/hpk42/tox/commits/763eeed49a7c/
Changeset: 763eeed49a7c
User: hpk42
Date: 2015-10-30 09:26:00+00:00
Summary: Merged in itxaka/tox/fix_env_use (pull request #169)
Tries to fix #99
Affected #: 2 files
diff -r 7e30b4b4591bb51fae92791a60adc98fe21733bb -r
763eeed49a7c572a9c31940932cfbeaff8d32ab1 tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -254,6 +254,28 @@
["echo", "cmd", "1", "2", "3", "4", "cmd", "2"],
]
+ def test_command_env_substitution(self, newconfig):
+ """Ensure referenced {env:key:default} values are substituted
correctly."""
+ config = newconfig("""
+ [testenv:py27]
+ setenv =
+ TEST=testvalue
+ commands =
+ ls {env:TEST}
+ """)
+ reader = SectionReader("testenv:py27", config._cfg)
+ x = reader.getargvlist("commands")
+ assert x == [
+ "ls testvalue".split()
+ ]
+ assert x != [
+ "ls {env:TEST}".split()
+ ]
+ y = reader.getargvlist("setenv")
+ assert y == [
+ "TEST=testvalue".split()
+ ]
+
class TestIniParser:
def test_getstring_single(self, tmpdir, newconfig):
diff -r 7e30b4b4591bb51fae92791a60adc98fe21733bb -r
763eeed49a7c572a9c31940932cfbeaff8d32ab1 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -902,6 +902,7 @@
return '\n'.join(filter(None, map(factor_line, lines)))
def _replace_env(self, match):
+ env_list = self.getdict('setenv')
match_value = match.group('substitution_value')
if not match_value:
raise tox.exception.ConfigError(
@@ -916,11 +917,14 @@
envkey = match_value
if envkey not in os.environ and default is None:
- raise tox.exception.ConfigError(
- "substitution env:%r: unknown environment variable %r" %
- (envkey, envkey))
-
- return os.environ.get(envkey, default)
+ if envkey not in env_list and default is None:
+ raise tox.exception.ConfigError(
+ "substitution env:%r: unknown environment variable %r" %
+ (envkey, envkey))
+ if envkey in os.environ:
+ return os.environ.get(envkey, default)
+ else:
+ return env_list.get(envkey, default)
def _substitute_from_other_section(self, key):
if key.startswith("[") and "]" in key:
Repository URL: https://bitbucket.org/hpk42/tox/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit