From: <pj...@us...> - 2009-05-23 02:03:16
|
Revision: 6366 http://jython.svn.sourceforge.net/jython/?rev=6366&view=rev Author: pjenvey Date: 2009-05-23 02:01:49 +0000 (Sat, 23 May 2009) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_popen2.py Added Paths: ----------- trunk/jython/Lib/test/test_popen2.py Added: trunk/jython/Lib/test/test_popen2.py =================================================================== --- trunk/jython/Lib/test/test_popen2.py (rev 0) +++ trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:01:49 UTC (rev 6366) @@ -0,0 +1,78 @@ +#! /usr/bin/env python +"""Test script for popen2.py + Christian Tismer +""" + +import os +import sys +from test.test_support import TestSkipped, reap_children + +# 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:" + if (sys.platform[:4] == 'beos' or sys.platform[:6] == 'atheos') \ + and __name__ != '__main__': + # Locks get messed up or something. Generally we're supposed + # to avoid mixing "posix" fork & exec with native threads, and + # they may be right about that after all. + raise TestSkipped, "popen2() doesn't work during import on " + sys.platform + try: + from os import popen + except ImportError: + # if we don't have os.popen, check that + # we have os.fork. if not, skip the test + # (by raising an ImportError) + from os import fork + import popen2 + popen2._test() + + +def _test(): + # same test as popen2._test(), but using the os.popen*() API + print "Testing os module:" + import popen2 + # When the test runs, there shouldn't be any open pipes + popen2._cleanup() + assert not popen2._active, "Active pipes when test starts " + repr([c.cmd for c in popen2._active]) + cmd = "cat" + teststr = "ab cd\n" + if os.name == "nt": + cmd = "more" + # "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() + got = r.read() + if got.strip() != expected: + raise ValueError("wrote %r read %r" % (teststr, got)) + print "testing popen3..." + try: + w, r, e = os.popen3([cmd]) + except: + w, r, e = os.popen3(cmd) + w.write(teststr) + w.close() + got = r.read() + if got.strip() != expected: + raise ValueError("wrote %r read %r" % (teststr, got)) + got = e.read() + if got: + raise ValueError("unexpected %r on stderr" % (got,)) + for inst in popen2._active[:]: + inst.wait() + popen2._cleanup() + if popen2._active: + raise ValueError("_active not empty") + print "All OK" + +main() +_test() +reap_children() Property changes on: trunk/jython/Lib/test/test_popen2.py ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-23 02:03:37
|
Revision: 6367 http://jython.svn.sourceforge.net/jython/?rev=6367&view=rev Author: pjenvey Date: 2009-05-23 02:02:32 +0000 (Sat, 23 May 2009) Log Message: ----------- fix windows detection Modified Paths: -------------- trunk/jython/Lib/test/test_popen2.py Modified: trunk/jython/Lib/test/test_popen2.py =================================================================== --- trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:01:49 UTC (rev 6366) +++ trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:02:32 UTC (rev 6367) @@ -5,7 +5,7 @@ import os import sys -from test.test_support import TestSkipped, reap_children +from test.test_support import TestSkipped, is_jython, reap_children # popen2 contains its own testing routine # which is especially useful to see if open files @@ -40,7 +40,7 @@ assert not popen2._active, "Active pipes when test starts " + repr([c.cmd for c in popen2._active]) cmd = "cat" teststr = "ab cd\n" - if os.name == "nt": + if os.name == "nt" or (is_jython and os._name == 'nt'): cmd = "more" # "more" doesn't act the same way across Windows flavors, # sometimes adding an extra newline at the start or the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |