diff test/test_run.py @ 165:c7ac67366492

Make treepkg.run.capture_output include the output in the SubprocessError exception raised when the command fails with an exit code != 0
author Bernhard Herzog <bh@intevation.de>
date Fri, 20 Jun 2008 14:40:29 +0000
parents a68a4e22549c
children 98de92b816d4
line wrap: on
line diff
--- a/test/test_run.py	Fri Jun 20 14:06:27 2008 +0000
+++ b/test/test_run.py	Fri Jun 20 14:40:29 2008 +0000
@@ -11,7 +11,7 @@
 import os
 import unittest
 
-from treepkg.run import call, SubprocessError
+from treepkg.run import call, capture_output, SubprocessError
 
 
 
@@ -61,3 +61,29 @@
             call(subprocess_cmd, inputdata=data)
         except SubprocessError, exc:
             self.assertEquals(exc.returncode, 1)
+
+class TestCaptureOutput(unittest.TestCase):
+
+    def test_capture_output_stdout(self):
+        text = "explicit is better than implicit"
+        self.assertEquals(capture_output([sys.executable, "-c",
+                                          "print %r" % text]),
+                          text + "\n")
+
+    def test_capture_output_stderr(self):
+        self.assertEquals(capture_output([sys.executable, "-c",
+                                          "import sys;"
+                                          "print 'on stdout';"
+                                          " sys.stdout.flush();"
+                                          "print >>sys.stderr, 'on stderr'"]),
+                          "on stdout\non stderr\n")
+
+    def test_capture_output_exception(self):
+        try:
+            capture_output([sys.executable, "-c",
+                            "import sys;"
+                            "print 'Beautiful is better than ugly';"
+                            " sys.exit(1)"])
+        except SubprocessError, exc:
+            self.assertEquals(exc.returncode, 1)
+            self.assertEquals(exc.output, "Beautiful is better than ugly\n")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)