[pypy-svn] r64302 - in pypy/trunk/pypy/translator: jvm/src/pypy oosupport/test_template
niko at codespeak.net
niko at codespeak.net
Fri Apr 17 19:28:49 CEST 2009
Author: niko
Date: Fri Apr 17 19:28:49 2009
New Revision: 64302
Modified:
pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java
pypy/trunk/pypy/translator/oosupport/test_template/builtin.py
Log:
improve support to use libc so that we don't just
return true for os.access()
Modified: pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java
==============================================================================
--- pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java (original)
+++ pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java Fri Apr 17 19:28:49 2009
@@ -170,6 +170,7 @@
static public interface Libc extends Library {
public int getpid();
public int symlink(String path1, String path2);
+ public int access(String path, int mode);
}
static final Libc libc;
static {
@@ -297,7 +298,7 @@
//if ((mode & X_OK) != 0 && !file.canExecute())
// return false;
- return true;
+ return libc.access(path, mode) == 0; // note that 0==success
}
public int ll_os_open(String name, int flags, int mode)
Modified: pypy/trunk/pypy/translator/oosupport/test_template/builtin.py
==============================================================================
--- pypy/trunk/pypy/translator/oosupport/test_template/builtin.py (original)
+++ pypy/trunk/pypy/translator/oosupport/test_template/builtin.py Fri Apr 17 19:28:49 2009
@@ -126,23 +126,41 @@
ACCESS_FLAGS = [os.F_OK, os.R_OK, os.W_OK, os.X_OK]
- def test_os_access_nonexisting(self):
- def nonexisting(flag):
- return os.access('some_file_that_does_not_exist', flag)
- for flag in self.ACCESS_FLAGS:
- assert self.interpret(nonexisting, [flag]) == nonexisting(flag)
-
- def test_os_access_allowed(self):
- def dot(flag):
- return os.access('.', flag)
- for flag in self.ACCESS_FLAGS:
- assert self.interpret(dot, [flag]) == dot(flag)
-
- def test_os_access_denied(self):
- def slash(flag):
- return os.access('/', flag)
- for flag in self.ACCESS_FLAGS:
- assert self.interpret(slash, [flag]) == slash(flag)
+ def test_os_access(self):
+ def create_fn(filenm):
+ return lambda flag: os.access(filenm, flag)
+ def try_file(filenm):
+ for flag in self.ACCESS_FLAGS:
+ print filenm, flag
+ fn = create_fn(filenm)
+ act = self.interpret(fn, [flag])
+ assert act == fn(flag)
+ assert not os.access('some_file_that_does_not_exist', os.F_OK) # shouldn't exist
+ try_file('some_file_that_does_not_exist')
+ try_file('.')
+
+ open('some_file_that_DID_not_exist', 'w').close()
+ os.chmod('some_file_that_DID_not_exist', 0)
+ assert os.access('some_file_that_DID_not_exist', os.F_OK) # should exist now
+ assert not os.access('some_file_that_DID_not_exist', os.W_OK) # should not be writable
+ try_file('some_file_that_DID_not_exist')
+ os.remove('some_file_that_DID_not_exist')
+
+ #def test_os_access_allowed(self):
+ # def fn(flag):
+ # return os.access('.', flag)
+ # for flag in self.ACCESS_FLAGS:
+ # print flag
+ # act = self.interpret(fn, [flag])
+ # assert act == fn(flag)
+ #
+ #def test_os_access_denied(self):
+ #
+ # def fn(flag):
+ # return os.access('/', flag)
+ # for flag in self.ACCESS_FLAGS:
+ # act = self.interpret(fn, [flag])
+ # assert act == fn(flag)
def test_os_stat_oserror(self):
def fn():
More information about the Pypy-commit
mailing list