changeset 3391:eea0edb31d9d

pep8 test: use extended attributes (where available) to store last-tested-mtime
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 21 Mar 2008 14:49:39 +0100
parents f1ba94b7913d
children 48b95abf3994
files MoinMoin/_tests/test_sourcecode.py
diffstat 1 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_sourcecode.py	Fri Mar 21 13:31:24 2008 +0100
+++ b/MoinMoin/_tests/test_sourcecode.py	Fri Mar 21 14:49:39 2008 +0100
@@ -30,8 +30,35 @@
                              # use 'fix' with extreme caution and in a separate changeset!
 FIX_TS_RE = re.compile(r' +$', re.M) # 'fix' mode: everything matching the trailing space re will be removed
 
+try:
+    import xattr
+    def mark_file_ok(path, mtime):
+        x = xattr.xattr(path)
+        try:
+            x.set('user.moin-pep8-tested-mtime', '%d' % mtime)
+        except IOError:
+            # probably not supported
+            mark_file_ok = lambda path, mtime: None
+
+    def should_check_file(path, mtime):
+        x = xattr.xattr(path)
+        try:
+            mt = x.get('user.moin-pep8-tested-mtime')
+            mt = long(mt)
+            return mtime > mt
+        except IOError:
+            # probably not supported
+            should_check_file = lambda path, mtime: True
+        return True
+except ImportError:
+    def mark_file_ok(path, mtime):
+        pass
+    def should_check_file(path, mtime):
+        return True
+
 RECENTLY = time.time() - 7 * 24*60*60 # we only check stuff touched recently.
 #RECENTLY = 0 # check everything!
+
 # After doing a fresh clone, this procedure is recommended:
 # 1. Run the tests once to see if everything is OK (as cloning updates the mtime,
 #    it will test every file).
@@ -45,7 +72,7 @@
     error_count = pep8.Checker(path).check_all()
     return error_count
 
-def check_py_file(reldir, path):
+def check_py_file(reldir, path, mtime):
     if TRAILING_SPACES == 'fix':
         f = file(path, 'rb')
         data = f.read()
@@ -64,6 +91,7 @@
     # any type of error is only reported ONCE (even if there are multiple).
     error_count = pep8_error_count(path)
     assert error_count == 0
+    mark_file_ok(path, mtime)
 
 def test_sourcecode():
     def walk(reldir):
@@ -77,8 +105,9 @@
         st = os.stat(path)
         mode = st.st_mode
         if stat.S_ISREG(mode): # is a regular file
-            if path.lower().endswith('.py') and st.st_mtime >= RECENTLY:
-                yield check_py_file, reldir, path
+            if (path.lower().endswith('.py') and st.st_mtime >= RECENTLY and
+                should_check_file(path, st.st_mtime)):
+                yield check_py_file, reldir, path, st.st_mtime
         elif stat.S_ISDIR(mode): # is a directory
             for entry in os.listdir(path):
                 if not entry.startswith('.'):