##// END OF EJS Templates
Merge pull request #3301 from juliantaylor/no-python-test...
Bradley M. Froehle -
r10608:262abcd3 merge
parent child Browse files
Show More
@@ -103,9 +103,7 b' def process_handler(cmd, callback, stderr=subprocess.PIPE):'
103 103
104 104
105 105 def getoutput(cmd):
106 """Return standard output of executing cmd in a shell.
107
108 Accepts the same arguments as os.system().
106 """Run a command and return its stdout/stderr as a string.
109 107
110 108 Parameters
111 109 ----------
@@ -114,9 +112,12 b' def getoutput(cmd):'
114 112
115 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 121 out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
121 122 if out is None:
122 123 return ''
@@ -15,6 +15,7 b' Tests for platutils.py'
15 15 #-----------------------------------------------------------------------------
16 16
17 17 import sys
18 import os
18 19 from unittest import TestCase
19 20
20 21 import nose.tools as nt
@@ -24,13 +25,15 b' from IPython.utils.process import (find_cmd, FindCmdError, arg_split,'
24 25 from IPython.testing import decorators as dec
25 26 from IPython.testing import tools as tt
26 27
28 python = os.path.basename(sys.executable)
29
27 30 #-----------------------------------------------------------------------------
28 31 # Tests
29 32 #-----------------------------------------------------------------------------
30 33
31 34 def test_find_cmd_python():
32 35 """Make sure we find sys.exectable for python."""
33 nt.assert_equal(find_cmd('python'), sys.executable)
36 nt.assert_equal(find_cmd(python), sys.executable)
34 37
35 38
36 39 @dec.skip_win32
@@ -102,30 +105,34 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):'
102 105 self.mktmp('\n'.join(lines))
103 106
104 107 def test_system(self):
105 status = system('python "%s"' % self.fname)
108 status = system('%s "%s"' % (python, self.fname))
106 109 self.assertEqual(status, 0)
107 110
108 111 def test_system_quotes(self):
109 status = system('python -c "import sys"')
112 status = system('%s -c "import sys"' % python)
110 113 self.assertEqual(status, 0)
111 114
112 115 def test_getoutput(self):
113 out = getoutput('python "%s"' % self.fname)
114 self.assertEqual(out, 'on stdout')
116 out = getoutput('%s "%s"' % (python, self.fname))
117 # we can't rely on the order the line buffered streams are flushed
118 try:
119 self.assertEqual(out, 'on stderron stdout')
120 except AssertionError:
121 self.assertEqual(out, 'on stdouton stderr')
115 122
116 123 def test_getoutput_quoted(self):
117 out = getoutput('python -c "print (1)"')
124 out = getoutput('%s -c "print (1)"' % python)
118 125 self.assertEqual(out.strip(), '1')
119 126
120 127 #Invalid quoting on windows
121 128 @dec.skip_win32
122 129 def test_getoutput_quoted2(self):
123 out = getoutput("python -c 'print (1)'")
130 out = getoutput("%s -c 'print (1)'" % python)
124 131 self.assertEqual(out.strip(), '1')
125 out = getoutput("python -c 'print (\"1\")'")
132 out = getoutput("%s -c 'print (\"1\")'" % python)
126 133 self.assertEqual(out.strip(), '1')
127 134
128 def test_getoutput(self):
129 out, err = getoutputerror('python "%s"' % self.fname)
135 def test_getoutput_error(self):
136 out, err = getoutputerror('%s "%s"' % (python, self.fname))
130 137 self.assertEqual(out, 'on stdout')
131 138 self.assertEqual(err, 'on stderr')
General Comments 0
You need to be logged in to leave comments. Login now