[pypy-svn] r69647 - in pypy/trunk/pypy/module/posix: . test

fijal at codespeak.net fijal at codespeak.net
Thu Nov 26 11:29:07 CET 2009


Author: fijal
Date: Thu Nov 26 11:29:07 2009
New Revision: 69647

Modified:
   pypy/trunk/pypy/module/posix/__init__.py
   pypy/trunk/pypy/module/posix/app_posix.py
   pypy/trunk/pypy/module/posix/test/test_posix2.py
Log:
(Ademan) Implement os.wait using waitpid


Modified: pypy/trunk/pypy/module/posix/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/posix/__init__.py	(original)
+++ pypy/trunk/pypy/module/posix/__init__.py	Thu Nov 26 11:29:07 2009
@@ -26,6 +26,9 @@
                 'popen3' : 'app_posix.popen3',
                 'popen4' : 'app_posix.popen4',
                 })
+
+    if hasattr(os, 'wait'):
+        appleveldefs['wait'] = 'app_posix.wait'
         
     interpleveldefs = {
     'open'      : 'interp_posix.open',

Modified: pypy/trunk/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/app_posix.py	(original)
+++ pypy/trunk/pypy/module/posix/app_posix.py	Thu Nov 26 11:29:07 2009
@@ -153,6 +153,9 @@
             try_close(read_end)
             raise Exception, e     # bare 'raise' does not work here :-(
 
+    def wait():
+        return posix.waitpid(-1, 0)
+
 else:
     # Windows implementations
     
@@ -170,6 +173,7 @@
         univ_nl = ('b' not in mode)
 
         import subprocess
+
         if mode.startswith('r'):
             proc = subprocess.Popen(cmd,
                                     shell=True,
@@ -194,7 +198,6 @@
             raise ValueError("invalid mode %r" % (mode,))
 
         import subprocess
-        
         p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
@@ -210,7 +213,6 @@
             raise ValueError("invalid mode %r" % (mode,))
 
         import subprocess
-        
         p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
@@ -228,7 +230,6 @@
             raise ValueError("invalid mode %r" % (mode,))
 
         import subprocess
-        
         p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,

Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py	Thu Nov 26 11:29:07 2009
@@ -290,6 +290,7 @@
         for i in range(5):
             stream = os.popen('echo 1')
             assert stream.read() == '1\n'
+            stream.close()
 
     if hasattr(__import__(os.name), '_getfullpathname'):
         def test__getfullpathname(self):
@@ -393,6 +394,22 @@
         def test_os_sysconf_error(self):
             os = self.posix
             raises(ValueError, os.sysconf, "!@#$%!#$!@#")
+    
+    if hasattr(os, 'wait'):
+        def test_os_wait(self):
+            os = self.posix
+            exit_status = 0x33
+
+            if not hasattr(os, "fork"):
+                skip("Need fork() to test wait()")
+            child = os.fork()
+            if child == 0: # in child
+                os._exit(exit_status)
+            else:
+                pid, status = os.wait()
+                assert child == pid
+                assert os.WIFEXITED(status)
+                assert os.WEXITSTATUS(status) == exit_status
 
     if hasattr(os, 'fsync'):
         def test_fsync(self):



More information about the Pypy-commit mailing list