#!/usr/bin/env python
import os
import sys
from unittest import defaultTestLoader, TextTestRunner, TestSuite

TESTS = ('form', 'fields', 'validators', 'widgets', 'webob_wrapper', 'translations', 'ext_csrf', 'i18n')

OPTIONAL_TESTS = ('ext_django.tests', 'ext_sqlalchemy', 'ext_dateutil', 'locale_babel')

def make_suite(prefix='', extra=()):
    tests = TESTS + extra
    test_names = list(prefix + x for x in tests)
    suite = TestSuite()
    suite.addTest(defaultTestLoader.loadTestsFromNames(test_names))
    for name in OPTIONAL_TESTS:
        test_name = prefix + name
        try:
            suite.addTest(defaultTestLoader.loadTestsFromName(test_name))
        except (ImportError, AttributeError):
            sys.stderr.write("### Disabled test '%s', dependency not found\n" % name)
    return suite

def additional_tests():
    """
    This is called automatically by setup.py test
    """
    return make_suite('tests.')

def main():
    my_dir = os.path.dirname(os.path.abspath(__file__))
    sys.path.insert(0, os.path.abspath(os.path.join(my_dir, '..')))

    extra_tests = tuple(x for x in sys.argv[1:] if '-' not in x)
    suite = make_suite('', extra_tests)

    runner = TextTestRunner(verbosity=(sys.argv.count('-v') - sys.argv.count('-q') + 1))
    result = runner.run(suite)
    sys.exit(not result.wasSuccessful())

if __name__ == '__main__':
    main()

@@ -1063,16 +1063,552 @@
  '..')))
+%0A    has_pep8 = False%0A    try:%0A        import pep8%0A        has_pep8 = True%0A    except ImportError:%0A        if '--with-pep8' in sys.argv%5B1:%5D:%0A            sys.stderr.write('# Could not find pep8 library.')%0A            sys.exit(1)%0A%0A    if has_pep8:%0A        guide = pep8.StyleGuide(%0A            ignore=%5B'E501'%5D,%0A            paths=%5B'wtforms/'%5D,%0A            exclude=%5B'wtforms/ext/sqlalchemy', 'wtforms/ext/appengine', 'wtforms/ext/django'%5D%0A        )%0A        report = guide.check_files()%0A        if report.total_errors:%0A            sys.exit(1)
 %0A%0A    ex

Allow running pep8 in runtests.