changeset 2279:938d6761519f

test_sourcecode: ignore/test/fix modes for trailing spaces, fixed file mode to use binary
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 02 Jul 2007 17:05:40 +0200
parents 9df10b5358b5
children 27cd29db1b96 a6a4eaa948aa
files MoinMoin/_tests/test_sourcecode.py
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_sourcecode.py	Mon Jul 02 16:32:28 2007 +0200
+++ b/MoinMoin/_tests/test_sourcecode.py	Mon Jul 02 17:05:40 2007 +0200
@@ -3,14 +3,14 @@
  * have no tabs,
  * end with \n,
  * have no crlf (Windows style) line endings,
- * have no trailing spaces at line endings (test currently disabled).
- 
+ * have no trailing spaces at line endings.
+
 @copyright: 2006 by Armin Rigo,
             2007 adapted and extended for MoinMoin by MoinMoin:ThomasWaldmann.
 @license: MIT licensed
 """
 
-import os
+import os, re
 
 from MoinMoin.conftest import moindir
 
@@ -22,6 +22,10 @@
     '/wiki/htdocs/applets/FCKeditor', # 3rd party GUI editor
 ]
 
+TRAILING_SPACES = 'ignore' # 'ignore', 'test' or 'fix'
+                           # 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
+
 def test_sourcecode():
     def walk(reldir):
         if reldir in EXCLUDE:
@@ -32,14 +36,20 @@
             path = ROOT
         if os.path.isfile(path):
             if path.lower().endswith('.py'):
-                f = open(path, 'r')
+                f = file(path, 'rb')
                 data = f.read()
                 f.close()
                 assert '\t' not in data, "%r contains tabs (please use 4 space chars for indenting)!" % (reldir,)
                 assert not data or data.endswith('\n'), "%r does not end with a newline char!" % (reldir,)
                 assert '\r\n' not in data, "%r contains crlf line endings (please use UNIX style, lf only)!" % (reldir,)
-                #triggers too often currently, developers please clean up your src files!
-                #assert ' \n' not in data, "%r contains line(s) with trailing spaces!" % (reldir,)
+                if TRAILING_SPACES != 'ignore':
+                    if TRAILING_SPACES == 'test':
+                        assert ' \n' not in data, "%r contains line(s) with trailing spaces!" % (reldir,)
+                    elif TRAILING_SPACES == 'fix':
+                        data = FIX_TS_RE.sub('', data)
+                        f = file(path, 'wb')
+                        f.write(data)
+                        f.close()
         elif os.path.isdir(path):
             for entry in os.listdir(path):
                 if not entry.startswith('.'):