Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin._tests.test_sourcecode Namespace Reference

Functions

def mark_file_ok
def should_check_file
def pep8_error_count
def check_py_file
def test_sourcecode

Variables

tuple ROOT = str(moindir)
list EXCLUDE
string TRAILING_SPACES = 'nochange'
tuple FIX_TS_RE = re.compile(r' +$', re.M)
tuple RECENTLY = time.time()

Detailed Description

Verify that the MoinMoin source files conform (mostly) to PEP8 coding style.

Additionally, we check that the files have no crlf (Windows style) line endings.

@copyright: 2006 by Armin Rigo (originally only testing for tab chars),
    2007 adapted and extended (calling the PEP8 checker for most stuff) by MoinMoin:ThomasWaldmann.
@license: MIT licensed

Function Documentation

def MoinMoin._tests.test_sourcecode.check_py_file (   reldir,
  path,
  mtime 
)

Definition at line 77 of file test_sourcecode.py.

00077 
00078 def check_py_file(reldir, path, mtime):
00079     if TRAILING_SPACES == 'fix':
00080         f = file(path, 'rb')
00081         data = f.read()
00082         f.close()
00083         fixed = FIX_TS_RE.sub('', data)
00084 
00085         # Don't write files if there's no need for that,
00086         # as altering timestamps can be annoying with some tools.
00087         if fixed == data:
00088             return
00089 
00090         f = file(path, 'wb')
00091         f.write(fixed)
00092         f.close()
00093     # Please read and follow PEP8 - rerun this test until it does not fail any more,
00094     # any type of error is only reported ONCE (even if there are multiple).
00095     error_count = pep8_error_count(path)
00096     assert error_count == 0
00097     mark_file_ok(path, mtime)

Here is the call graph for this function:

def MoinMoin._tests.test_sourcecode.mark_file_ok (   path,
  mtime 
)

Definition at line 37 of file test_sourcecode.py.

00037 
00038     def mark_file_ok(path, mtime):
00039         x = xattr.xattr(path)
00040         try:
00041             x.set('user.moin-pep8-tested-mtime', '%d' % mtime)
00042         except IOError:
00043             # probably not supported
00044             mark_file_ok = lambda path, mtime: None

Here is the caller graph for this function:

Definition at line 71 of file test_sourcecode.py.

00071 
00072 def pep8_error_count(path):
00073     # process_options initializes some data structures and MUST be called before each Checker().check_all()
00074     pep8.process_options(['pep8', '--ignore=E202,E221,E222,E241,E301,E302,E401,E501,E701,W391,W601,W602', '--show-source', 'dummy_path'])
00075     error_count = pep8.Checker(path).check_all()
00076     return error_count

Here is the caller graph for this function:

Definition at line 45 of file test_sourcecode.py.

00045 
00046     def should_check_file(path, mtime):
00047         x = xattr.xattr(path)
00048         try:
00049             mt = x.get('user.moin-pep8-tested-mtime')
00050             mt = long(mt)
00051             return mtime > mt
00052         except IOError:
00053             # probably not supported
00054             should_check_file = lambda path, mtime: True
        return True

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file test_sourcecode.py.

00098 
00099 def test_sourcecode():
00100     def walk(reldir):
00101         if reldir in EXCLUDE:
00102             #print "Skippping %r..." % reldir
00103             return
00104         if reldir:
00105             path = os.path.join(ROOT, *reldir.split('/'))
00106         else:
00107             path = ROOT
00108         st = os.stat(path)
00109         mode = st.st_mode
00110         if stat.S_ISREG(mode): # is a regular file
00111             if (path.lower().endswith('.py') and st.st_mtime >= RECENTLY and
00112                 should_check_file(path, st.st_mtime)):
00113                 yield check_py_file, reldir, path, st.st_mtime
00114         elif stat.S_ISDIR(mode): # is a directory
00115             for entry in os.listdir(path):
00116                 if not entry.startswith('.'):
00117                     for _ in walk('%s/%s' % (reldir, entry)):
00118                         yield _
00119 
00120     global EXCLUDE
00121     EXCLUDE = dict([(path, True) for path in EXCLUDE]) # dict lookup is faster
00122     for _ in walk(''):
00123         yield _
00124 

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 [
00002     '/contrib/DesktopEdition/setup_py2exe.py', # has crlf
00003     '/contrib/TWikiDrawPlugin', # 3rd party java stuff
00004     '/contrib/flup-server', # 3rd party WSGI adapters
00005     '/MoinMoin/support', # 3rd party libs or non-broken stdlib stuff
00006     '/MoinMoin/web/static/htdocs', # this is our dist static stuff
00007     '/tests/wiki', # this is our test wiki
00008     '/wiki/data/pages', # wiki pages, there may be .py attachments
00009 ]

Definition at line 19 of file test_sourcecode.py.

tuple MoinMoin._tests.test_sourcecode.FIX_TS_RE = re.compile(r' +$', re.M)

Definition at line 31 of file test_sourcecode.py.

Definition at line 61 of file test_sourcecode.py.

Definition at line 17 of file test_sourcecode.py.

Definition at line 29 of file test_sourcecode.py.