[Pytest-commit] commit/tox: hpk42: Merged in cboylan/tox (pull request #85)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu May 15 11:33:32 CEST 2014
1 new commit in tox:
https://bitbucket.org/hpk42/tox/commits/169574bf58a4/
Changeset: 169574bf58a4
User: hpk42
Date: 2014-05-15 11:33:28
Summary: Merged in cboylan/tox (pull request #85)
Fix command expansion and parsing.
Affected #: 2 files
diff -r 65be9669e403386305e091ff55c2b3e9fb8c6410 -r 169574bf58a499d179ece389b75a83ee8b6fba4a tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -293,7 +293,7 @@
# "reader.getargvlist('section', 'key1')")
assert reader.getargvlist('section', 'key1') == []
x = reader.getargvlist("section", "key2")
- assert x == [["cmd1", "with space", "grr"],
+ assert x == [["cmd1", "with", "space", "grr"],
["cmd2", "grr"]]
def test_argvlist_windows_escaping(self, tmpdir, newconfig):
@@ -319,7 +319,7 @@
# "reader.getargvlist('section', 'key1')")
assert reader.getargvlist('section', 'key1') == []
x = reader.getargvlist("section", "key2")
- assert x == [["cmd1", "with space", "grr"]]
+ assert x == [["cmd1", "with", "space", "grr"]]
def test_argvlist_quoting_in_command(self, tmpdir, newconfig):
@@ -361,6 +361,34 @@
assert argvlist[0] == ["cmd1"]
assert argvlist[1] == ["cmd2", "value2", "other"]
+ def test_argvlist_quoted_posargs(self, tmpdir, newconfig):
+ config = newconfig("""
+ [section]
+ key2=
+ cmd1 --foo-args='{posargs}'
+ cmd2 -f '{posargs}'
+ cmd3 -f {posargs}
+ """)
+ reader = IniReader(config._cfg)
+ reader.addsubstitutions(["foo", "bar"])
+ assert reader.getargvlist('section', 'key1') == []
+ x = reader.getargvlist("section", "key2")
+ assert x == [["cmd1", "--foo-args=foo bar"],
+ ["cmd2", "-f", "foo bar"],
+ ["cmd3", "-f", "foo", "bar"]]
+
+ def test_argvlist_posargs_with_quotes(self, tmpdir, newconfig):
+ config = newconfig("""
+ [section]
+ key2=
+ cmd1 -f {posargs}
+ """)
+ reader = IniReader(config._cfg)
+ reader.addsubstitutions(["foo", "'bar", "baz'"])
+ assert reader.getargvlist('section', 'key1') == []
+ x = reader.getargvlist("section", "key2")
+ assert x == [["cmd1", "-f", "foo", "bar baz"]]
+
def test_positional_arguments_are_only_replaced_when_standing_alone(self,
tmpdir, newconfig):
config = newconfig("""
diff -r 65be9669e403386305e091ff55c2b3e9fb8c6410 -r 169574bf58a499d179ece389b75a83ee8b6fba4a tox/_config.py
--- a/tox/_config.py
+++ b/tox/_config.py
@@ -530,30 +530,35 @@
def _processcommand(self, command):
posargs = getattr(self, "posargs", None)
- # special treat posargs which might contain multiple arguments
- # in their defaults
+ # Iterate through each word of the command substituting as
+ # appropriate to construct the new command string. This
+ # string is then broken up into exec argv components using
+ # shlex.
newcommand = ""
for word in CommandParser(command).words():
- if word.startswith("{posargs:") and word.endswith("}"):
+ if word == "{posargs}" or word == "[]":
if posargs:
- word = "{posargs}"
+ newcommand += " ".join(posargs)
+ continue
+ elif word.startswith("{posargs:") and word.endswith("}"):
+ if posargs:
+ newcommand += " ".join(posargs)
+ continue
else:
word = word[9:-1]
- newcommand += word
+ new_arg = ""
+ new_word = self._replace(word)
+ new_word = self._replace(new_word)
+ new_arg += new_word
+ newcommand += new_arg
- # now we can properly parse the command
- argv = []
- for arg in shlex.split(newcommand):
- if arg in ('[]', "{posargs}"):
- if posargs:
- argv.extend(posargs)
- continue
- new_arg = ""
- for word in CommandParser(arg).words():
- new_word = self._replace(word)
- new_word = self._replace(new_word)
- new_arg += new_word
- argv.append(new_arg)
+ # Construct shlex object that will not escape any values,
+ # use all values as is in argv.
+ shlexer = shlex.shlex(newcommand, posix=True)
+ shlexer.whitespace_split = True
+ shlexer.escape = ''
+ shlexer.commenters = ''
+ argv = list(shlexer)
return argv
def getargv(self, section, name, default=None, replace=True):
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.
More information about the pytest-commit
mailing list