summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Jehannet <julien.jehannet@logilab.fr>2010-09-30 11:45:15 +0200
committerJulien Jehannet <julien.jehannet@logilab.fr>2010-09-30 11:45:15 +0200
commite50c533617e26304a3c30d61d73305c39920df66 (patch)
tree9448978dc9b1cc9adabff02123f42245b825b521
parent792dd0e553191c96dc33a086de5d7ca4bc4d3240 (diff)
downloadlogilab-common-e50c533617e26304a3c30d61d73305c39920df66.tar.gz
[tests] fix usage of os.access in unittest_fileutils.py
os.access is often problematic in some environments (chroot, fakeroot, nfs, ...) since it uses read uid instead of effective uid in contrast to other file utilities found in posix world. Consider using os.stat() and stat constants when possible.
-rw-r--r--compat.py2
-rw-r--r--test/unittest_fileutils.py26
2 files changed, 20 insertions, 8 deletions
diff --git a/compat.py b/compat.py
index 699fa0d..480fb78 100644
--- a/compat.py
+++ b/compat.py
@@ -23,7 +23,7 @@ See another compatibility snippets from other projects:
:mod:`lib2to3.fixes`
:mod:`coverage.backward`
- :mod:``unittest2.compatibility
+ :mod:`unittest2.compatibility`
"""
from __future__ import generators
diff --git a/test/unittest_fileutils.py b/test/unittest_fileutils.py
index 82d0677..d900b3f 100644
--- a/test/unittest_fileutils.py
+++ b/test/unittest_fileutils.py
@@ -18,16 +18,17 @@
"""unit tests for logilab.common.fileutils"""
import sys, os, tempfile, shutil
+from stat import S_IWRITE
from os.path import join
-from logilab.common.testlib import TestCase, unittest_main
+from logilab.common.testlib import TestCase, unittest_main, unittest
from logilab.common.fileutils import *
-
DATA_DIR = 'data'
NEWLINES_TXT = join(DATA_DIR,'newlines.txt')
+
class FirstleveldirectoryTC(TestCase):
def test_known_values_first_level_directory(self):
@@ -92,32 +93,43 @@ class ProtectedFileTC(TestCase):
def test_mode_change(self):
"""tests that mode is changed when needed"""
# test on non-writable file
- self.assert_(not os.access(self.rpath, os.W_OK))
+ #self.assert_(not os.access(self.rpath, os.W_OK))
+ self.assert_(not os.stat(self.rpath).st_mode & S_IWRITE)
wp_file = ProtectedFile(self.rpath, 'w')
+ self.assert_(os.stat(self.rpath).st_mode & S_IWRITE)
self.assert_(os.access(self.rpath, os.W_OK))
# test on writable-file
+ self.assert_(os.stat(self.rwpath).st_mode & S_IWRITE)
self.assert_(os.access(self.rwpath, os.W_OK))
wp_file = ProtectedFile(self.rwpath, 'w')
+ self.assert_(os.stat(self.rwpath).st_mode & S_IWRITE)
self.assert_(os.access(self.rwpath, os.W_OK))
def test_restore_on_close(self):
"""tests original mode is restored on close"""
# test on non-writable file
- self.assert_(not os.access(self.rpath, os.W_OK))
+ #self.assert_(not os.access(self.rpath, os.W_OK))
+ self.assert_(not os.stat(self.rpath).st_mode & S_IWRITE)
ProtectedFile(self.rpath, 'w').close()
- self.assert_(not os.access(self.rpath, os.W_OK))
+ #self.assert_(not os.access(self.rpath, os.W_OK))
+ self.assert_(not os.stat(self.rpath).st_mode & S_IWRITE)
# test on writable-file
self.assert_(os.access(self.rwpath, os.W_OK))
+ self.assert_(os.stat(self.rwpath).st_mode & S_IWRITE)
ProtectedFile(self.rwpath, 'w').close()
self.assert_(os.access(self.rwpath, os.W_OK))
+ self.assert_(os.stat(self.rwpath).st_mode & S_IWRITE)
def test_mode_change_on_append(self):
"""tests that mode is changed when file is opened in 'a' mode"""
- self.assert_(not os.access(self.rpath, os.W_OK))
+ #self.assert_(not os.access(self.rpath, os.W_OK))
+ self.assert_(not os.stat(self.rpath).st_mode & S_IWRITE)
wp_file = ProtectedFile(self.rpath, 'a')
self.assert_(os.access(self.rpath, os.W_OK))
+ self.assert_(os.stat(self.rpath).st_mode & S_IWRITE)
wp_file.close()
- self.assert_(not os.access(self.rpath, os.W_OK))
+ #self.assert_(not os.access(self.rpath, os.W_OK))
+ self.assert_(not os.stat(self.rpath).st_mode & S_IWRITE)
from logilab.common.testlib import DocTest