summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-08-28 17:20:05 (GMT)
committerFred Drake <fdrake@acm.org>2000-08-28 17:20:05 (GMT)
commit31f182e830db13c3edbe12e58f9c737cc21583fa (patch)
tree6138744d553c71b9eef48a43bc8a4ab201c5f9c3 /Lib/test
parente67d8e514f7d7b49faec3e5a181c7019f07467ba (diff)
downloadcpython-31f182e830db13c3edbe12e58f9c737cc21583fa.zip
cpython-31f182e830db13c3edbe12e58f9c737cc21583fa.tar.gz
cpython-31f182e830db13c3edbe12e58f9c737cc21583fa.tar.bz2
Added os.popen2() and os.popen3() for non-Windows platforms.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/output/test_popen25
-rw-r--r--Lib/test/test_popen2.py35
2 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/output/test_popen2 b/Lib/test/output/test_popen2
index 1fadf1b..a66cde9 100644
--- a/Lib/test/output/test_popen2
+++ b/Lib/test/output/test_popen2
@@ -1,4 +1,9 @@
test_popen2
+Test popen2 module:
+testing popen2...
+testing popen3...
+All OK
+Testing os module:
testing popen2...
testing popen3...
All OK
diff --git a/Lib/test/test_popen2.py b/Lib/test/test_popen2.py
index f6359ce..26ef9d9 100644
--- a/Lib/test/test_popen2.py
+++ b/Lib/test/test_popen2.py
@@ -3,12 +3,15 @@
Christian Tismer
"""
+import os
+
# popen2 contains its own testing routine
# which is especially useful to see if open files
# like stdin can be read successfully by a forked
# subprocess.
def main():
+ print "Test popen2 module:"
try:
from os import popen
except ImportError:
@@ -19,5 +22,35 @@ def main():
import popen2
popen2._test()
-main()
+def _test():
+ # same test as popen2._test(), but using the os.popen*() API
+ print "Testing os module:"
+ import popen2
+ cmd = "cat"
+ teststr = "abc\n"
+ resultstr = teststr
+ if os.name == "nt":
+ cmd = "more"
+ resultstr = "\n" + resultstr
+ print "testing popen2..."
+ w, r = os.popen2(cmd)
+ w.write(teststr)
+ w.close()
+ assert r.read() == resultstr
+ print "testing popen3..."
+ try:
+ w, r, e = os.popen3([cmd])
+ except:
+ w, r, e = os.popen3(cmd)
+ w.write(teststr)
+ w.close()
+ assert r.read() == resultstr
+ assert e.read() == ""
+ for inst in popen2._active[:]:
+ inst.wait()
+ assert not popen2._active
+ print "All OK"
+
+main()
+_test()