summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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