summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_popen2.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-09-01 20:38:55 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-09-01 20:38:55 (GMT)
commit3620857d60e000300d5fa475fa9404bc535b536f (patch)
treee444cdfcc631ba5f37883a183781070791a1e6f1 /Lib/test/test_popen2.py
parentf4a090d57953e69a2bb79230751e25690915d2df (diff)
downloadcpython-3620857d60e000300d5fa475fa9404bc535b536f.zip
cpython-3620857d60e000300d5fa475fa9404bc535b536f.tar.gz
cpython-3620857d60e000300d5fa475fa9404bc535b536f.tar.bz2
The "more" cmd varies across Windows flavors, sometimes adding stray
newlines at the start or end. Fiddle test_popen2 and popen2._test() to tolerate this. Also change all "assert"s in these tests to raise explicit exceptions, so that python -O doesn't render them useless. Also, in case of error, make the msg display the reprs of what we wrote and what we read, so we can tell exactly why it's failing.
Diffstat (limited to 'Lib/test/test_popen2.py')
-rw-r--r--Lib/test/test_popen2.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/test/test_popen2.py b/Lib/test/test_popen2.py
index 26ef9d9..1215847 100644
--- a/Lib/test/test_popen2.py
+++ b/Lib/test/test_popen2.py
@@ -28,16 +28,20 @@ def _test():
print "Testing os module:"
import popen2
cmd = "cat"
- teststr = "abc\n"
- resultstr = teststr
+ teststr = "ab cd\n"
if os.name == "nt":
cmd = "more"
- resultstr = "\n" + resultstr
+ # "more" doesn't act the same way across Windows flavors,
+ # sometimes adding an extra newline at the start or the
+ # end. So we strip whitespace off both ends for comparison.
+ expected = teststr.strip()
print "testing popen2..."
w, r = os.popen2(cmd)
w.write(teststr)
w.close()
- assert r.read() == resultstr
+ got = r.read()
+ if got.strip() != expected:
+ raise ValueError("wrote %s read %s" % (`teststr`, `got`))
print "testing popen3..."
try:
w, r, e = os.popen3([cmd])
@@ -45,11 +49,16 @@ def _test():
w, r, e = os.popen3(cmd)
w.write(teststr)
w.close()
- assert r.read() == resultstr
- assert e.read() == ""
+ got = r.read()
+ if got.strip() != expected:
+ raise ValueError("wrote %s read %s" % (`teststr`, `got`))
+ got = e.read()
+ if got:
+ raise ValueError("unexected %s on stderr" % `got`)
for inst in popen2._active[:]:
inst.wait()
- assert not popen2._active
+ if popen2._active:
+ raise ValueError("_active not empty")
print "All OK"
main()