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

rhymes at codespeak.net rhymes at codespeak.net
Mon Aug 21 00:18:38 CEST 2006


Author: rhymes
Date: Mon Aug 21 00:18:34 2006
New Revision: 31426

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: major(), minor(), pathconf() and lchown()

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:18:34 2006
@@ -47,13 +47,15 @@
     '_exit'     : 'interp_posix._exit',
     'abort'     : 'interp_posix.abort',
     'access'    : 'interp_posix.access',
+    'major'     : 'interp_posix.major',
+    'minor'     : 'interp_posix.minor',
     }
     
     for func_name in ['ftruncate', 'putenv', 'unsetenv', 'getpid', 'link',
         'symlink', 'readlink', 'fork', 'waitpid', 'chown', 'chroot',
         'confstr', 'ctermid', 'fchdir', 'fpathconf', 'getegid', 'geteuid',
         'getgid', 'getuid', 'getpgid', 'getpid', 'getppid', 'getpgrp',
-        'getsid', 'getlogin', 'getgroups', 'getloadavg']:
+        'getsid', 'getlogin', 'getgroups', 'getloadavg', 'lchown', 'pathconf']:
         if hasattr(os, func_name):
             interpleveldefs[func_name] = 'interp_posix.%s' % func_name
     

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:18:34 2006
@@ -430,6 +430,14 @@
 chown.unwrap_spec = [ObjSpace, str, int, int]
 chown.__doc__ = os.chown.__doc__
 
+def lchown(space, path, uid, gid):
+    try:
+        os.lchown(path, uid, gid)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+lchown.unwrap_spec = [ObjSpace, str, int, int]
+lchown.__doc__ = os.lchown.__doc__
+
 def chroot(space, path):
     try:
         os.chroot(path)
@@ -498,6 +506,30 @@
         return space.wrap(res)
 fpathconf.unwrap_spec = [ObjSpace, int, W_Root]
 fpathconf.__doc__ = os.fpathconf.__doc__
+
+def pathconf(space, path, 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.pathconf(path, space.str_w(w_name))
+        elif is_int:
+            res = os.pathconf(path, 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)
+pathconf.unwrap_spec = [ObjSpace, str, W_Root]
+pathconf.__doc__ = os.pathconf.__doc__
     
 def getegid(space):
     return space.wrap(os.getegid())
@@ -574,4 +606,13 @@
 getloadavg.unwrap_spec = [ObjSpace]
 getloadavg.__doc__ = os.getloadavg.__doc__
 
+def major(space, device):
+    return space.wrap(os.major(device))
+major.unwrap_spec = [ObjSpace, int]
+major.__doc__ = os.major.__doc__
+
+def minor(space, device):
+    return space.wrap(os.minor(device))
+minor.unwrap_spec = [ObjSpace, int]
+minor.__doc__ = os.minor.__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:18:34 2006
@@ -234,6 +234,7 @@
             stat_info = posix.stat(path)
             uid, gid = stat_info.st_uid, stat_info.st_gid
             posix.chown(path, -1, -1)
+            posix.lchown(path, -1, -1)
             stat_info = posix.stat(path)
             assert uid == stat_info.st_uid
             assert gid == stat_info.st_gid
@@ -286,7 +287,23 @@
             raises(TypeError, posix.fpathconf, fd, None)
             raises(TypeError, posix.fpathconf, fd, dict())
         else:
-            skip("fpathconf nad pathconf_names not supported")
+            skip("fpathconf and pathconf_names not supported")
+    
+    def test_pathconf(self):
+        import os
+        if hasattr(__import__(os.name), "pathconf"):
+            posix = self.posix
+            path = self.path
+            assert isinstance(posix.pathconf_names, dict)
+            name = posix.pathconf_names.keys()[-1]
+            assert isinstance(posix.pathconf(path, name), int)
+            val = posix.pathconf_names.values()[-1]
+            assert isinstance(posix.pathconf(path, val), int)
+            raises(ValueError, posix.pathconf, path, 'xYz')
+            raises(TypeError, posix.pathconf, path, None)
+            raises(TypeError, posix.pathconf, path, dict())
+        else:
+            skip("pathconf nad pathconf_names not supported")
             
     def test_getcwdu(self):
         assert isinstance(self.posix.getcwdu(), unicode)
@@ -335,6 +352,12 @@
             hard_link = os.path.join(pdir, 'hard_link')
             posix.link(path, hard_link)
             assert posix.readlink(link) == path
+    
+    def test_major_minor(self):
+        posix = self.posix
+        fd = posix.open("/dev/urandom", posix.O_RDONLY)
+        assert isinstance(posix.major(fd), int)
+        assert isinstance(posix.minor(fd), int)
         
 class AppTestEnvironment(object):
     def setup_class(cls): 



More information about the Pypy-commit mailing list