comparison 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
comparison
equal deleted inserted replaced
164:a68a4e22549c 165:c7ac67366492
9 9
10 import sys 10 import sys
11 import os 11 import os
12 import unittest 12 import unittest
13 13
14 from treepkg.run import call, SubprocessError 14 from treepkg.run import call, capture_output, SubprocessError
15 15
16 16
17 17
18 class TestCall(unittest.TestCase): 18 class TestCall(unittest.TestCase):
19 19
59 "import sys; sys.exit(int(raw_input("")))"] 59 "import sys; sys.exit(int(raw_input("")))"]
60 try: 60 try:
61 call(subprocess_cmd, inputdata=data) 61 call(subprocess_cmd, inputdata=data)
62 except SubprocessError, exc: 62 except SubprocessError, exc:
63 self.assertEquals(exc.returncode, 1) 63 self.assertEquals(exc.returncode, 1)
64
65 class TestCaptureOutput(unittest.TestCase):
66
67 def test_capture_output_stdout(self):
68 text = "explicit is better than implicit"
69 self.assertEquals(capture_output([sys.executable, "-c",
70 "print %r" % text]),
71 text + "\n")
72
73 def test_capture_output_stderr(self):
74 self.assertEquals(capture_output([sys.executable, "-c",
75 "import sys;"
76 "print 'on stdout';"
77 " sys.stdout.flush();"
78 "print >>sys.stderr, 'on stderr'"]),
79 "on stdout\non stderr\n")
80
81 def test_capture_output_exception(self):
82 try:
83 capture_output([sys.executable, "-c",
84 "import sys;"
85 "print 'Beautiful is better than ugly';"
86 " sys.exit(1)"])
87 except SubprocessError, exc:
88 self.assertEquals(exc.returncode, 1)
89 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)