[Treepkg-commits] r118 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jul 31 12:00:26 CEST 2008
Author: bh
Date: 2008-07-31 12:00:25 +0200 (Thu, 31 Jul 2008)
New Revision: 118
Modified:
trunk/test/test_run.py
trunk/treepkg/run.py
Log:
Add logfile argument to treepkg.run.call to log the output of the
subprocess. Add a corresponding test case.
Modified: trunk/test/test_run.py
===================================================================
--- trunk/test/test_run.py 2008-07-30 19:30:21 UTC (rev 117)
+++ trunk/test/test_run.py 2008-07-31 10:00:25 UTC (rev 118)
@@ -11,6 +11,8 @@
import os
import unittest
+from filesupport import FileTestMixin
+
from treepkg.run import call, capture_output, SubprocessError
@@ -62,6 +64,16 @@
except SubprocessError, exc:
self.assertEquals(exc.returncode, 1)
+
+class TestRunWithLogging(unittest.TestCase, FileTestMixin):
+
+ def test_run_with_logfile(self):
+ logfilename = self.temp_file_name("logfile")
+ call([sys.executable, "-c", "print \"I'm a lumber jack and I'm OK\""],
+ logfile=logfilename)
+ self.checkFileContents(logfilename, "I'm a lumber jack and I'm OK\n")
+
+
class TestCaptureOutput(unittest.TestCase):
def test_capture_output_stdout(self):
Modified: trunk/treepkg/run.py
===================================================================
--- trunk/treepkg/run.py 2008-07-30 19:30:21 UTC (rev 117)
+++ trunk/treepkg/run.py 2008-07-31 10:00:25 UTC (rev 118)
@@ -21,7 +21,8 @@
self.output = output
-def call(command, suppress_output=False, extra_env=None, inputdata=None, **kw):
+def call(command, suppress_output=False, extra_env=None, inputdata=None,
+ logfile=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
@@ -30,7 +31,9 @@
"""
if inputdata is not None:
kw["stdin"] = subprocess.PIPE
- if suppress_output:
+ if logfile:
+ kw["stdout"] = kw["stderr"] = open(logfile, "w")
+ elif suppress_output:
kw["stdout"] = open(os.devnull, "w")
kw["stderr"] = open(os.devnull, "w")
env = kw.pop("env", None)
More information about the Treepkg-commits
mailing list