changeset 2285:751e149a9a0a

test_sourcecode: fix generative test
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 02 Jul 2007 20:46:01 +0200
parents 71f7bde1077b
children 01f05e74aa9c
files MoinMoin/_tests/test_sourcecode.py
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_sourcecode.py	Mon Jul 02 19:42:57 2007 +0200
+++ b/MoinMoin/_tests/test_sourcecode.py	Mon Jul 02 20:46:01 2007 +0200
@@ -12,6 +12,8 @@
 
 import os, re
 
+import pep8
+
 from MoinMoin.conftest import moindir
 
 ROOT = str(moindir)
@@ -28,7 +30,13 @@
 
 PEP8_CHECKS = True
 
-def check_file(path):
+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,E302,E401,E501,E701,W', '--show-source', 'dummy_path'])
+    error_count = pep8.Checker(path).check_all()
+    return error_count
+
+def check_file(reldir, path):
     if path.lower().endswith('.py'):
         f = file(path, 'rb')
         data = f.read()
@@ -47,7 +55,8 @@
         if PEP8_CHECKS:
             # Please read and follow PEP8 - rerun this test until it does not fail any more,
             # any type of error is only reported ONCE (even if there are multiple).
-            assert pep8_error_count(path) == 0
+            error_count = pep8_error_count(path)
+            assert error_count == 0
 
 def test_sourcecode():
     def walk(reldir):
@@ -58,21 +67,14 @@
         else:
             path = ROOT
         if os.path.isfile(path):
-            yield check_file, path
+            yield check_file, reldir, path
         elif os.path.isdir(path):
             for entry in os.listdir(path):
                 if not entry.startswith('.'):
-                    walk('%s/%s' % (reldir, entry))
+                    for _ in walk('%s/%s' % (reldir, entry)):
+                        yield _
 
     global EXCLUDE
     EXCLUDE = dict([(path, True) for path in EXCLUDE]) # dict lookup is faster
-    walk('')
-
-import pep8
-pep8.process_options(['pep8', '--ignore=E302,E401,E501,E701,W', 'dummy_path'])
-#pep8.process_options(['pep8', path])
-
-def pep8_error_count(path):
-    error_count = pep8.Checker(path).check_all()
-    return error_count
-
+    for _ in walk(''):
+        yield _