##// END OF EJS Templates
fix documentation and test of getoutput...
Julian Taylor -
Show More
@@ -103,9 +103,7 b' def process_handler(cmd, callback, stderr=subprocess.PIPE):'
103
103
104
104
105 def getoutput(cmd):
105 def getoutput(cmd):
106 """Return standard output of executing cmd in a shell.
106 """Run a command and return its stdout/stderr as a string.
107
108 Accepts the same arguments as os.system().
109
107
110 Parameters
108 Parameters
111 ----------
109 ----------
@@ -114,9 +112,12 b' def getoutput(cmd):'
114
112
115 Returns
113 Returns
116 -------
114 -------
117 stdout : str
115 output : str
116 A string containing the combination of stdout and stderr from the
117 subprocess, in whatever order the subprocess originally wrote to its
118 file descriptors (so the order of the information in this string is the
119 correct order as would be seen if running the command in a terminal).
118 """
120 """
119
120 out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
121 out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
121 if out is None:
122 if out is None:
122 return ''
123 return ''
@@ -111,7 +111,11 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):'
111
111
112 def test_getoutput(self):
112 def test_getoutput(self):
113 out = getoutput('python "%s"' % self.fname)
113 out = getoutput('python "%s"' % self.fname)
114 self.assertEqual(out, 'on stdout')
114 # we can't rely on the order the line buffered streams are flushed
115 try:
116 self.assertEqual(out, 'on stderron stdout')
117 except AssertionError:
118 self.assertEqual(out, 'on stdouton stderr')
115
119
116 def test_getoutput_quoted(self):
120 def test_getoutput_quoted(self):
117 out = getoutput('python -c "print (1)"')
121 out = getoutput('python -c "print (1)"')
@@ -125,7 +129,7 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):'
125 out = getoutput("python -c 'print (\"1\")'")
129 out = getoutput("python -c 'print (\"1\")'")
126 self.assertEqual(out.strip(), '1')
130 self.assertEqual(out.strip(), '1')
127
131
128 def test_getoutput(self):
132 def test_getoutput_error(self):
129 out, err = getoutputerror('python "%s"' % self.fname)
133 out, err = getoutputerror('python "%s"' % self.fname)
130 self.assertEqual(out, 'on stdout')
134 self.assertEqual(out, 'on stdout')
131 self.assertEqual(err, 'on stderr')
135 self.assertEqual(err, 'on stderr')
General Comments 0
You need to be logged in to leave comments. Login now