changeset 2446:70b1a82ec75b

test_sourcecode: add pep8 test for 1 space on each side of an operator
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 20 Jul 2007 20:27:00 +0200
parents 2dc7a3be8ec9
children 45641cbe7729
files MoinMoin/_tests/pep8.py MoinMoin/_tests/test_sourcecode.py
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/pep8.py	Fri Jul 20 18:39:33 2007 +0200
+++ b/MoinMoin/_tests/pep8.py	Fri Jul 20 20:27:00 2007 +0200
@@ -102,6 +102,8 @@
 equals_boolean_search = re.compile(r'([!=]=\s*(True|False))|((True|False)\s*[!=]=)').search
 equals_None_search = re.compile(r'([!=]=\s*None)|(None\s*[!=]=)').search
 
+not_one_ws_around_operators_match = re.compile(r'^[^\(\[]+[^\s](\+|\-|\*|/|%|\^|&|\||=|<|>|>>|<<|\+=|\-=|\*=|/=|%=|\^=|&=|\|=|==|<=|>=|>>=|<<=|!=|<>)[^\s][^\)\]]+$').match
+
 operators = """
 +  -  *  /  %  ^  &  |  =  <  >  >>  <<
 += -= *= /= %= ^= &= |= == <= >= >>= <<=
@@ -318,7 +320,7 @@
         prev_end = end
 
 
-def whitespace_around_operator(logical_line):
+def extra_whitespace_around_operator(logical_line):
     """
     Avoid extraneous whitespace in the following situations:
 
@@ -341,6 +343,15 @@
             return found, "E224 tab after operator"
 
 
+def whitespace_around_operator(logical_line):
+    """
+    Have exactly 1 space left and right of the operator.
+    """
+    match = not_one_ws_around_operators_match(logical_line)
+    if match and not 'lambda' in logical_line:
+        return match.start(1), "E225 operators shall be surrounded by a single space on each side %s" % logical_line
+
+
 def whitespace_around_comma(logical_line):
     """
     Avoid extraneous whitespace in the following situations:
--- a/MoinMoin/_tests/test_sourcecode.py	Fri Jul 20 18:39:33 2007 +0200
+++ b/MoinMoin/_tests/test_sourcecode.py	Fri Jul 20 20:27:00 2007 +0200
@@ -40,7 +40,7 @@
 
 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'])
+    pep8.process_options(['pep8', '--ignore=E202,E221,E222,E241,E301,E302,E401,E501,E701,W391,W601,W602,E225', '--show-source', 'dummy_path'])
     error_count = pep8.Checker(path).check_all()
     return error_count