2 """Test script for popen2.py
8 from test
.test_support
import TestSkipped
10 # popen2 contains its own testing routine
11 # which is especially useful to see if open files
12 # like stdin can be read successfully by a forked
16 print "Test popen2 module:"
17 if (sys
.platform
[:4] == 'beos' or sys
.platform
[:6] == 'atheos') \
18 and __name__
!= '__main__':
19 # Locks get messed up or something. Generally we're supposed
20 # to avoid mixing "posix" fork & exec with native threads, and
21 # they may be right about that after all.
22 raise TestSkipped
, "popen2() doesn't work during import on " + sys
.platform
26 # if we don't have os.popen, check that
27 # we have os.fork. if not, skip the test
28 # (by raising an ImportError)
35 # same test as popen2._test(), but using the os.popen*() API
36 print "Testing os module:"
42 # "more" doesn't act the same way across Windows flavors,
43 # sometimes adding an extra newline at the start or the
44 # end. So we strip whitespace off both ends for comparison.
45 expected
= teststr
.strip()
46 print "testing popen2..."
51 if got
.strip() != expected
:
52 raise ValueError("wrote %s read %s" % (`teststr`
, `got`
))
53 print "testing popen3..."
55 w
, r
, e
= os
.popen3([cmd
])
57 w
, r
, e
= os
.popen3(cmd
)
61 if got
.strip() != expected
:
62 raise ValueError("wrote %s read %s" % (`teststr`
, `got`
))
65 raise ValueError("unexected %s on stderr" % `got`
)
66 for inst
in popen2
._active
[:]:
69 raise ValueError("_active not empty")