changeset 2377:656685f94105

test_sourcecode: only test recently changed stuff, use a single os.stat call's results
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 15 Jul 2007 14:05:12 +0200
parents d1b05e0eb6ea
children a7f4b02f5fdb
files MoinMoin/_tests/test_sourcecode.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_sourcecode.py	Sun Jul 15 13:24:07 2007 +0200
+++ b/MoinMoin/_tests/test_sourcecode.py	Sun Jul 15 14:05:12 2007 +0200
@@ -8,7 +8,7 @@
 @license: MIT licensed
 """
 
-import os, re
+import os, re, time, stat
 
 import pep8
 
@@ -30,6 +30,14 @@
 FIX_TS_RE = re.compile(r' +$', re.M) # 'fix' mode: everything matching the trailing space re will be removed
 
 
+RECENTLY = time.time() - 7 * 24*60*60 # we only check stuff touched recently.
+# 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).
+# 2. Before starting to make new changes, use "touch" to change all timestamps
+#    to a time before <RECENTLY>.
+# 3. Regularly run the tests, they will run much faster now.
+
 def pep8_error_count(path):
     # process_options initializes some data structures and MUST be called before each Checker().check_all()
     pep8.process_options(['pep8', '--ignore=E202,E221,E222,E241,E301,E302,E401,E501,E701,W391,W601,W602', '--show-source', 'dummy_path'])
@@ -59,10 +67,12 @@
             path = os.path.join(ROOT, *reldir.split('/'))
         else:
             path = ROOT
-        if os.path.isfile(path):
-            if path.lower().endswith('.py'):
+        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
-        elif os.path.isdir(path):
+        elif stat.S_ISDIR(mode): # is a directory
             for entry in os.listdir(path):
                 if not entry.startswith('.'):
                     for _ in walk('%s/%s' % (reldir, entry)):