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

rhymes at codespeak.net rhymes at codespeak.net
Sun Aug 20 23:47:53 CEST 2006


Author: rhymes
Date: Sun Aug 20 23:47:50 2006
New Revision: 31422

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:
getXYZid functions, getpgrp(), getgroups(), getlogin() and getloadavg()


Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Sun Aug 20 23:47:50 2006
@@ -78,6 +78,31 @@
         interpleveldefs['fchdir'] = 'interp_posix.fchdir'
     if hasattr(os, 'fpathconf'):
         interpleveldefs['fpathconf'] = 'interp_posix.fpathconf'
+    if hasattr(os, 'getegid'):
+        interpleveldefs['getegid'] = 'interp_posix.getegid'
+    if hasattr(os, 'geteuid'):
+        interpleveldefs['geteuid'] = 'interp_posix.geteuid'
+    if hasattr(os, 'getgid'):
+        interpleveldefs['getgid'] = 'interp_posix.getgid'
+    if hasattr(os, 'getuid'):
+        interpleveldefs['getuid'] = 'interp_posix.getuid'    
+    if hasattr(os, 'getpgid'):
+        interpleveldefs['getpgid'] = 'interp_posix.getpgid'
+    if hasattr(os, 'getpid'):
+        interpleveldefs['getpid'] = 'interp_posix.getpid'
+    if hasattr(os, 'getppid'):
+        interpleveldefs['getppid'] = 'interp_posix.getppid'
+    if hasattr(os, 'getpgrp'):
+        interpleveldefs['getpgrp'] = 'interp_posix.getpgrp'
+    if hasattr(os, 'getsid'):
+        interpleveldefs['getsid'] = 'interp_posix.getsid'
+    if hasattr(os, 'getlogin'):
+        interpleveldefs['getlogin'] = 'interp_posix.getlogin'
+    if hasattr(os, 'getgroups'):
+        interpleveldefs['getgroups'] = 'interp_posix.getgroups'
+    if hasattr(os, 'getloadavg'):
+        interpleveldefs['getloadavg'] = 'interp_posix.getloadavg'
+    
 
 for constant in dir(os):
     value = getattr(os, constant)

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	Sun Aug 20 23:47:50 2006
@@ -499,4 +499,79 @@
 fpathconf.unwrap_spec = [ObjSpace, int, W_Root]
 fpathconf.__doc__ = os.fpathconf.__doc__
     
+def getegid(space):
+    return space.wrap(os.getegid())
+getegid.unwrap_spec = [ObjSpace]
+getegid.__doc__ = os.getegid.__doc__
+
+def geteuid(space):
+    return space.wrap(os.geteuid())
+geteuid.unwrap_spec = [ObjSpace]
+geteuid.__doc__ = os.geteuid.__doc__
+
+def getgid(space):
+    return space.wrap(os.getgid())
+getgid.unwrap_spec = [ObjSpace]
+getgid.__doc__ = os.getgid.__doc__
+
+def getuid(space):
+    return space.wrap(os.getuid())
+getuid.unwrap_spec = [ObjSpace]
+getuid.__doc__ = os.getuid.__doc__
+
+def getpgid(space, pid):
+    try:
+        res = os.getpgid(pid)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    else:
+        return space.wrap(res)
+getpgid.unwrap_spec = [ObjSpace, int]
+getpgid.__doc__ = os.getpgid.__doc__
+
+def getpid(space):
+    return space.wrap(os.getpid())
+getpid.unwrap_spec = [ObjSpace]
+getpid.__doc__ = os.getpid.__doc__
+
+def getppid(space):
+    return space.wrap(os.getppid())
+getppid.unwrap_spec = [ObjSpace]
+getppid.__doc__ = os.getppid.__doc__
+
+def getpgrp(space):
+    return space.wrap(os.getpgrp())
+getpgrp.unwrap_spec = [ObjSpace]
+getpgrp.__doc__ = os.getpgrp.__doc__
+
+def getsid(space, pid):
+    try:
+        res = os.getsid(pid)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    else:
+        return space.wrap(res)
+getsid.unwrap_spec = [ObjSpace, int]
+getsid.__doc__ = os.getsid.__doc__
+
+def getlogin(space):
+    return space.wrap(os.getlogin())
+getlogin.unwrap_spec = [ObjSpace]
+getlogin.__doc__ = os.getlogin.__doc__
+
+def getgroups(space):
+    return space.newlist(os.getgroups())
+getgroups.unwrap_spec = [ObjSpace]
+getgroups.__doc__ = os.getgroups.__doc__
+
+def getloadavg(space):
+    try:
+        res = os.getloadavg()
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    else:
+        return space.wrap(res)
+getloadavg.unwrap_spec = [ObjSpace]
+getloadavg.__doc__ = os.getloadavg.__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	Sun Aug 20 23:47:50 2006
@@ -84,6 +84,8 @@
         ex(self.posix.chown, str(UNUSEDFD), -1, -1)
         ex(self.posix.chroot, str(UNUSEDFD))
         ex(self.posix.fchdir, UNUSEDFD)
+        ex(self.posix.getpgid, UNUSEDFD)
+        ex(self.posix.getsid, UNUSEDFD)
 
     def test_fdopen(self):
         path = self.path 
@@ -270,7 +272,7 @@
     
     def test_fpathconf(self):
         import os
-        if hasattr(__import__(os.name), "fork"):
+        if hasattr(__import__(os.name), "fpathconf"):
             posix = self.posix
             fd = posix.open(self.path, posix.O_RDONLY)
             assert isinstance(posix.pathconf_names, dict)
@@ -286,6 +288,39 @@
             
     def test_getcwdu(self):
         assert isinstance(self.posix.getcwdu(), unicode)
+    
+    def test_get_ids(self):
+        import os
+        if hasattr(__import__(os.name), "getegid"):
+            posix = self.posix
+            assert isinstance(posix.getegid(), int)
+            assert isinstance(posix.geteuid(), int)
+            assert isinstance(posix.getgid(), int)
+            assert isinstance(posix.getuid(), int)
+            assert posix.getpgid(0) == posix.getpgrp()
+            assert isinstance(posix.getpid(), int)
+            assert isinstance(posix.getppid(), int)
+            assert isinstance(posix.getsid(0), int)
+    
+    def test_getlogin(self):
+        import os
+        if hasattr(__import__(os.name), "getlogin"):
+            posix = self.posix
+            assert isinstance(posix.getlogin(), str)
+            # assert posix.getlogin() == pwd.getpwuid(os.getuid())[0]
+            
+    def test_getgroups(self):
+        import os
+        if hasattr(__import__(os.name), "getgroups"):
+            assert isinstance(self.posix.getgroups(), list)
+            
+    def test_getloadavg(self):
+        import os
+        if hasattr(__import__(os.name), "getloadavg"):
+            posix = self.posix
+            load = posix.getloadavg()
+            assert isinstance(load, tuple)
+            assert len(load) == 3
         
 class AppTestEnvironment(object):
     def setup_class(cls): 



More information about the Pypy-commit mailing list