[pypy-svn] r31428 - in pypy/dist/pypy/module/posix: . test

rhymes at codespeak.net rhymes at codespeak.net
Mon Aug 21 00:49:36 CEST 2006


Author: rhymes
Date: Mon Aug 21 00:49:33 2006
New Revision: 31428

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/interp_posix.py
   pypy/dist/pypy/module/posix/test/test_posix2.py
Log:
more functions again: sysconf(), wait(), uname(), umask(), ttyname()

Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Mon Aug 21 00:49:33 2006
@@ -28,7 +28,8 @@
         'minor', 'major', 'access', 'abort', '_exit', 'rename', 'chmod',
         'pipe', 'strerror', 'listdir', 'rmdir', 'mkdir', 'chdir', 'getcwdu',
         'getcwd', 'remove', 'unlink', 'system', 'dup2', 'dup', 'lstat',
-        'stat', 'fstat', 'close', 'read', 'write', 'isatty', 'lseek', 'open']:
+        'stat', 'fstat', 'close', 'read', 'write', 'isatty', 'lseek', 'open',
+        'sysconf', 'wait', 'uname', 'umask', 'ttyname']:
         if hasattr(os, func_name):
             interpleveldefs[func_name] = 'interp_posix.%s' % func_name
     
@@ -36,6 +37,6 @@
     value = getattr(os, constant)
     if constant.isupper() and type(value) is int:
         Module.interpleveldefs[constant] = "space.wrap(%s)" % value
-for const in ['confstr_names', 'pathconf_names']:
+for const in ['confstr_names', 'pathconf_names', 'sysconf_names']:
     if hasattr(os, const):
         Module.interpleveldefs[const] = "space.wrap(%s)" % getattr(os, const)

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Mon Aug 21 00:49:33 2006
@@ -302,7 +302,6 @@
         del get(space).posix_putenv_garbage[name]
 unsetenv.unwrap_spec = [ObjSpace, str]
 
-
 def enumeratedir(space, dir):
     result = []
     while True:
@@ -403,6 +402,12 @@
 waitpid.unwrap_spec = [ObjSpace, int, int]
 waitpid.__doc__ = os.waitpid.__doc__
 
+def wait(space):
+    pid, status = os.wait()
+    return space.newtuple([space.wrap(pid), space.wrap(status)])
+wait.unwrap_spec = [ObjSpace]
+wait.__doc__ = os.wait.__doc__
+
 def _exit(space, status):
     os._exit(status)
 _exit.unwrap_spec = [ObjSpace, int]
@@ -616,3 +621,48 @@
 minor.unwrap_spec = [ObjSpace, int]
 minor.__doc__ = os.minor.__doc__
 
+def sysconf(space, w_name):
+    w_name_type = space.type(w_name)
+    is_str = space.is_w(w_name_type, space.w_str)
+    is_int = space.is_w(w_name_type, space.w_int)
+
+    res = ''
+    try:
+        if is_str:
+            res = os.sysconf(space.str_w(w_name))
+        elif is_int:
+            res = os.sysconf(space.int_w(w_name))
+        else:
+            raise OperationError(space.w_TypeError,
+                space.wrap("configuration names must be strings or integers"))
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    except ValueError, e:
+        raise OperationError(space.w_ValueError,
+            space.wrap(e.args[0]))
+    else:
+        return space.wrap(res)
+sysconf.unwrap_spec = [ObjSpace, W_Root]
+sysconf.__doc__ = os.sysconf.__doc__
+
+def uname(space):
+    name = os.uname()
+    name_w = [space.wrap(i) for i in name]
+    return space.newtuple(name_w)
+uname.unwrap_spec = [ObjSpace]
+uname.__doc__ == os.uname.__doc__
+
+def umask(space, mask):
+    return space.wrap(os.umask(mask))
+umask.unwrap_spec = [ObjSpace, int]
+umask.__doc__ == os.umask.__doc__
+
+def ttyname(space, fd):
+    try:
+        res = os.ttyname(fd)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    else:
+        return space.wrap(res)
+ttyname.unwrap_spec = [ObjSpace, int]
+ttyname.__doc__ = os.ttyname.__doc__

Modified: pypy/dist/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/dist/pypy/module/posix/test/test_posix2.py	Mon Aug 21 00:49:33 2006
@@ -88,6 +88,8 @@
         ex(self.posix.getsid, UNUSEDFD)
         ex(self.posix.link, "foo", "foo")
         ex(self.posix.readlink, "foo")
+        ex(self.posix.sysconf, UNUSEDFD)
+        ex(self.posix.ttyname, UNUSEDFD)
 
     def test_fdopen(self):
         path = self.path 
@@ -358,6 +360,50 @@
         fd = posix.open("/dev/urandom", posix.O_RDONLY)
         assert isinstance(posix.major(fd), int)
         assert isinstance(posix.minor(fd), int)
+
+    def test_sysconf(self):
+        import os
+        if hasattr(__import__(os.name), "sysconf"):
+            posix = self.posix
+            assert isinstance(posix.sysconf_names, dict)
+            name = posix.sysconf_names.keys()[0]
+            assert isinstance(posix.sysconf(name), int)
+            val = posix.sysconf_names.values()[0]
+            assert isinstance(posix.sysconf(val), int)
+            raises(ValueError, posix.sysconf, 'xYz')
+            raises(TypeError, posix.sysconf, None)
+            raises(TypeError, posix.sysconf, dict())
+        else:
+            skip("confstr and confstr_names not supported")
+            
+    def test_wait(self):
+        import os
+        if hasattr(__import__(os.name), "wait"):
+            posix = self.posix
+            pid = posix.fork()
+            if pid == 0:   # child
+                posix._exit(4)
+            pid1, status1 = os.wait()
+            assert pid1 == pid
+        else:
+            skip("wait not supported")
+            
+    def test_uname(self):
+        import os
+        if hasattr(__import__(os.name), "uname"):
+            uname = self.posix.uname()
+            assert isinstance(uname, tuple)
+            assert len(uname) == 5
+    
+    def test_umask(self):
+        import os
+        if hasattr(__import__(os.name), "umask"):
+            assert isinstance(self.posix.umask(022), int)
+            
+    def test_ttyname(self):
+        import os
+        if hasattr(__import__(os.name), "umask"):
+            assert isinstance(self.posix.ttyname(0), str)
         
 class AppTestEnvironment(object):
     def setup_class(cls): 



More information about the Pypy-commit mailing list