[pypy-svn] r31421 - in pypy/dist/pypy/module/posix: . test
rhymes at codespeak.net
rhymes at codespeak.net
Sun Aug 20 23:14:32 CEST 2006
Author: rhymes
Date: Sun Aug 20 23:14:29 2006
New Revision: 31421
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:
getcwdu(), ctermid(), fchdir() fpathconf() and pathconf_names
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:14:29 2006
@@ -34,6 +34,7 @@
'unlink' : 'interp_posix.unlink',
'remove' : 'interp_posix.remove',
'getcwd' : 'interp_posix.getcwd',
+ 'getcwdu' : 'interp_posix.getcwdu',
'chdir' : 'interp_posix.chdir',
'mkdir' : 'interp_posix.mkdir',
'rmdir' : 'interp_posix.rmdir',
@@ -71,6 +72,12 @@
interpleveldefs['chroot'] = 'interp_posix.chroot'
if hasattr(os, 'confstr'):
interpleveldefs['confstr'] = 'interp_posix.confstr'
+ if hasattr(os, 'ctermid'):
+ interpleveldefs['ctermid'] = 'interp_posix.ctermid'
+ if hasattr(os, 'fchdir'):
+ interpleveldefs['fchdir'] = 'interp_posix.fchdir'
+ if hasattr(os, 'fpathconf'):
+ interpleveldefs['fpathconf'] = 'interp_posix.fpathconf'
for constant in dir(os):
value = getattr(os, constant)
@@ -78,3 +85,5 @@
Module.interpleveldefs[constant] = "space.wrap(%s)" % value
if hasattr(os, 'confstr_names'):
Module.interpleveldefs['confstr_names'] = "space.wrap(%s)" % os.confstr_names
+if hasattr(os, 'pathconf_names'):
+ Module.interpleveldefs['pathconf_names'] = "space.wrap(%s)" % os.pathconf_names
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:14:29 2006
@@ -201,7 +201,6 @@
remove.unwrap_spec = [ObjSpace, str]
def getcwd(space):
- """Return the current working directory."""
try:
cur = os.getcwd()
except OSError, e:
@@ -209,6 +208,17 @@
else:
return space.wrap(cur)
getcwd.unwrap_spec = [ObjSpace]
+getcwd.__doc__ = os.getcwd.__doc__
+
+def getcwdu(space):
+ try:
+ cur = os.getcwdu()
+ except OSError, e:
+ raise wrap_oserror(space, e)
+ else:
+ return space.wrap(cur)
+getcwdu.unwrap_spec = [ObjSpace]
+getcwdu.__doc__ = os.getcwdu.__doc__
def chdir(space, path):
"""Change the current working directory to the specified path."""
@@ -447,7 +457,46 @@
except ValueError, e:
raise OperationError(space.w_ValueError,
space.wrap(e.args[0]))
- return space.wrap(res)
+ else:
+ return space.wrap(res)
confstr.unwrap_spec = [ObjSpace, W_Root]
confstr.__doc__ = os.confstr.__doc__
+def ctermid(space):
+ return space.wrap(os.ctermid())
+ctermid.unwrap_spec = [ObjSpace]
+ctermid.__doc__ = os.ctermid.__doc__
+
+def fchdir(space, fd):
+ try:
+ os.fchdir(fd)
+ except OSError, e:
+ raise wrap_oserror(space, e)
+fchdir.unwrap_spec = [ObjSpace, int]
+fchdir.__doc__ = os.fchdir.__doc__
+
+def fpathconf(space, fd, 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.fpathconf(fd, space.str_w(w_name))
+ elif is_int:
+ res = os.fpathconf(fd, 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)
+fpathconf.unwrap_spec = [ObjSpace, int, W_Root]
+fpathconf.__doc__ = os.fpathconf.__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:14:29 2006
@@ -83,6 +83,7 @@
ex(self.posix.chmod, str(UNUSEDFD), 0777)
ex(self.posix.chown, str(UNUSEDFD), -1, -1)
ex(self.posix.chroot, str(UNUSEDFD))
+ ex(self.posix.fchdir, UNUSEDFD)
def test_fdopen(self):
path = self.path
@@ -195,47 +196,96 @@
def test_ftruncate(self):
import os
- pdir = self.pdir
- posix = self.posix
- path = os.path.join(pdir, 'file1')
- fd = posix.open(path, posix.O_WRONLY)
- posix.ftruncate(fd, 2)
- assert posix.stat(path)[6] == 2
- posix.close(fd)
- raises(IOError, posix.ftruncate, 123123, 1)
+ if hasattr(__import__(os.name), "ftruncate"):
+ pdir = self.pdir
+ posix = self.posix
+ path = os.path.join(pdir, 'file1')
+ fd = posix.open(path, posix.O_WRONLY)
+ posix.ftruncate(fd, 2)
+ assert posix.stat(path)[6] == 2
+ posix.close(fd)
+ raises(IOError, posix.ftruncate, 123123, 1)
+ else:
+ skip("ftruncate not supported")
def test_abort(self):
- posix = self.posix
- pid = posix.fork()
- if pid == 0: # child
- posix.abort()
+ import os
+ if hasattr(__import__(os.name), "fork"):
+ posix = self.posix
+ pid = posix.fork()
+ if pid == 0: # child
+ posix.abort()
+ else:
+ skip("can't test abort, because fork is missing")
def test_access(self):
posix = self.posix
assert posix.access('.', posix.W_OK)
def test_chown(self):
- posix = self.posix
- path = self.path
- stat_info = posix.stat(path)
- uid, gid = stat_info.st_uid, stat_info.st_gid
- posix.chown(path, -1, -1)
- stat_info = posix.stat(path)
- assert uid == stat_info.st_uid
- assert gid == stat_info.st_gid
- raises(OSError, posix.chown, path, 1000, 1000)
+ import os
+ if hasattr(__import__(os.name), "chown"):
+ posix = self.posix
+ path = self.path
+ stat_info = posix.stat(path)
+ uid, gid = stat_info.st_uid, stat_info.st_gid
+ posix.chown(path, -1, -1)
+ stat_info = posix.stat(path)
+ assert uid == stat_info.st_uid
+ assert gid == stat_info.st_gid
+ raises(OSError, posix.chown, path, 1000, 1000)
+ else:
+ skip("chown not supported")
def test_confstr(self):
- posix = self.posix
- assert isinstance(posix.confstr_names, dict)
- name = posix.confstr_names.keys()[0]
- assert isinstance(posix.confstr(name), str)
- val = posix.confstr_names.values()[0]
- assert isinstance(posix.confstr(val), str)
- raises(ValueError, posix.confstr, 'xYz')
- raises(TypeError, posix.confstr, None)
- raises(TypeError, posix.confstr, dict())
- assert isinstance(posix.confstr(12345), str)
+ import os
+ if hasattr(__import__(os.name), "confstr"):
+ posix = self.posix
+ assert isinstance(posix.confstr_names, dict)
+ name = posix.confstr_names.keys()[0]
+ assert isinstance(posix.confstr(name), str)
+ val = posix.confstr_names.values()[0]
+ assert isinstance(posix.confstr(val), str)
+ raises(ValueError, posix.confstr, 'xYz')
+ raises(TypeError, posix.confstr, None)
+ raises(TypeError, posix.confstr, dict())
+ assert isinstance(posix.confstr(12345), str)
+ else:
+ skip("confstr and confstr_names not supported")
+
+ def test_ctermid(self):
+ import os
+ if hasattr(__import__(os.name), "ctermid"):
+ assert isinstance(self.posix.ctermid(), str)
+
+ def test_fchdir(self):
+ import os
+ if hasattr(__import__(os.name), "fchdir"):
+ pdir = self.pdir
+ posix = self.posix
+ whereami = posix.getcwd()
+ fd = posix.open(pdir, posix.O_RDONLY)
+ posix.fchdir(fd)
+ posix.chdir(whereami)
+
+ def test_fpathconf(self):
+ import os
+ if hasattr(__import__(os.name), "fork"):
+ posix = self.posix
+ fd = posix.open(self.path, posix.O_RDONLY)
+ assert isinstance(posix.pathconf_names, dict)
+ name = posix.pathconf_names.keys()[-1]
+ assert isinstance(posix.fpathconf(fd, name), int)
+ val = posix.pathconf_names.values()[-1]
+ assert isinstance(posix.fpathconf(fd, val), int)
+ raises(ValueError, posix.fpathconf, fd, 'xYz')
+ raises(TypeError, posix.fpathconf, fd, None)
+ raises(TypeError, posix.fpathconf, fd, dict())
+ else:
+ skip("fpathconf nad pathconf_names not supported")
+
+ def test_getcwdu(self):
+ assert isinstance(self.posix.getcwdu(), unicode)
class AppTestEnvironment(object):
def setup_class(cls):
More information about the Pypy-commit
mailing list