[Treepkg-commits] r89 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jun 20 16:06:27 CEST 2008
Author: bh
Date: 2008-06-20 16:06:27 +0200 (Fri, 20 Jun 2008)
New Revision: 89
Modified:
trunk/test/test_run.py
trunk/treepkg/run.py
Log:
Extend treepkg.run.call so that data can be fed to stdin of the subprocess.
Modified: trunk/test/test_run.py
===================================================================
--- trunk/test/test_run.py 2008-06-20 10:19:26 UTC (rev 88)
+++ trunk/test/test_run.py 2008-06-20 14:06:27 UTC (rev 89)
@@ -48,3 +48,16 @@
else:
# test OK
pass
+
+ def test_call_inputdata(self):
+ """Test call with inputdata passed to the subprocesses stdin"""
+ # FIXME: If the feature being tested is not implemented
+ # properly, it's likely that the subprocess will wait
+ # indefinitely waiting for input.
+ data = "1"
+ subprocess_cmd = [sys.executable, "-c",
+ "import sys; sys.exit(int(raw_input("")))"]
+ try:
+ call(subprocess_cmd, inputdata=data)
+ except SubprocessError, exc:
+ self.assertEquals(exc.returncode, 1)
Modified: trunk/treepkg/run.py
===================================================================
--- trunk/treepkg/run.py 2008-06-20 10:19:26 UTC (rev 88)
+++ trunk/treepkg/run.py 2008-06-20 14:06:27 UTC (rev 89)
@@ -20,13 +20,15 @@
self.returncode = returncode
-def call(command, suppress_output=False, extra_env=None, **kw):
+def call(command, suppress_output=False, extra_env=None, inputdata=None, **kw):
"""Run command as a subprocess and wait until it is finished.
The command should be given as a list of strings to avoid problems
with shell quoting. If the command exits with a return code other
than 0, a SubprocessError is raised.
"""
+ if inputdata is not None:
+ kw["stdin"] = subprocess.PIPE
if suppress_output:
kw["stdout"] = open(os.devnull, "w")
kw["stderr"] = open(os.devnull, "w")
@@ -35,7 +37,12 @@
if env is None:
env = os.environ.copy()
env.update(extra_env)
- ret = subprocess.call(command, env=env, **kw)
+
+ process = subprocess.Popen(command, env=env, **kw)
+ if inputdata is not None:
+ process.stdin.write(inputdata)
+ process.stdin.close()
+ ret = process.wait()
if ret != 0:
raise SubprocessError(command, ret)
More information about the Treepkg-commits
mailing list