def pep8(self, *args): del sys.stdout[:], sys.stderr[:] sys.argv[1:] = args try: pep8._main() errorcode = None except SystemExit: errorcode = sys.exc_info()[1].code return str(sys.stdout), str(sys.stderr), errorcode
def pep8(self, *args): del sys.stdout[:], sys.stderr[:] sys.argv[1:] = args try: pep8._main() errorcode = None except SystemExit: errorcode = sys.exc_info()[1].code return sys.stdout.getvalue(), sys.stderr.getvalue(), errorcode
def test_pep8_rules(self): import pep8 sys.argv[1:] = ['--filename=*.py', '--show-source', '--show-pep8', '--ignore=W291', moderation.__path__[0]] buf = StringIO() sys.stdout = buf pep8._main() sys.stdout = sys.__stdout__ result = buf.getvalue() self.assertEqual("", result, "Code messages should be empty but was:\n" + result)
def run_pep(): """Runs pep on the module or package supplied via command line. Usage: bin/python tests/pep.py [options] path_to_module_or_package If you want to see full set of command line options offered by pep, pass --help. """ args = ['--show-source', '--show-pep8', '--ignore=W291'] sys.argv.extend(args) pep8._main()
def test_pep8_rules(self): sys.argv[1:] = ['--filename=*.py', '--show-source', '--show-pep8', '--ignore=E201,E202,E203,E221,E222,E231,E241,E251,E303,E501', '--repeat', '--exclude=tagging', './'] buf = StringIO() sys.stdout = buf pep8._main() sys.stdout = sys.__stdout__ result = buf.getvalue() self.assertEqual("", result, "Code messages should be empty but was:\n" + result)
def run_pep(): """Runs pep on the module or package supplied via command line. Usage: bin/python tests/pep.py [options] path_to_module_or_package If you want to see full set of command line options offered by pep, pass --help. """ args = [ '--show-source', '--show-pep8', '--ignore=W291' ] sys.argv.extend(args) pep8._main()
def _reload(script_path, module=None): script_path = os.path.realpath(script_path) try: log_debug('Running static analysis (pyflakes)') reporter = pyflakes.reporter._makeDefaultReporter() warnings = pyflakes.api.checkPath(script_path, reporter) assert warnings == 0, 'Failed static analysis' log_debug('Running tests (pytest)') status = pytest.main('-vx {}'.format(script_path)) assert status in pytest_status_ok, 'Failed tests ({})'.format(status) log_debug('Checking style (pep8)') pep8._main() if module is None: log_debug('Loading') module = import_module_by_path(script_path) # Some things only get called on reload. log_debug('Reloading') return reload(module) except Exception as e: log_error(e) return module
if __name__ == '__main__': import sys import pep8 sys.exit(pep8._main())
print(line.rstrip()) return count_failed, count_all def run_tests(style, doctest=True, testsuite=False): options = style.options if doctest: import doctest fail_d, done_d = doctest.testmod(report=False, verbose=options.verbose) fail_s, done_s = selftest(options) count_failed = fail_s + fail_d if not options.quiet: count_passed = done_d + done_s - count_failed print("%d passed and %d failed." % (count_passed, count_failed)) print("Test failed." if count_failed else "Test passed.") if count_failed: sys.exit(1) if testsuite: init_tests(style) return style.check_files() if __name__ == "__main__": if len(sys.argv) > 1: sys.exit(pep8._main()) pep8style = StyleGuide(paths=[os.path.dirname(__file__)], ignore=None) report = run_tests(pep8style, doctest=True, testsuite=True) report.print_results() sys.exit(1 if report.total_errors else 0)
pep8.current_file = filename return open(filename).readlines() def add_cloud(): """Monkey patch pep8 for cloud-init guidelines. Look for functions that start with cloud_ and add them to pep8 module. Assumes you know how to write pep8.py checks """ for name, function in globals().items(): if not inspect.isfunction(function): continue if name.startswith("cloud_"): exec("pep8.%s = %s" % (name, name)) # pylint: disable=W0122 if __name__ == "__main__": # NOVA based 'hacking.py' error codes start with an N pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}') add_cloud() pep8.current_file = current_file pep8.readlines = readlines try: pep8._main() # pylint: disable=W0212 finally: if len(_missingImport) > 0: print >> sys.stderr, ("%i imports missing in this test environment" % len(_missingImport))
if __name__ == '__main__': import sys from pep8 import _main sys.exit(_main())
def _main(): try: import pep8 pep8._main() except: print 'Unable to import pep8'
def run(self): sys.argv = sys.argv[1:] + ["."] pep8._main()
def main(): pep8.indentation = indentation reset_pep8_checks() pep8._main()
def run_pep8(): pep8._main(file_list)
def readlines(filename): """ record the current file being tested """ pep8.current_file = filename return open(filename).readlines() def add_nova(): """ Look for functions that start with nova_ and have arguments and add them to pep8 module Assumes you know how to write pep8.py checks """ for name, function in globals().items(): if not inspect.isfunction(function): continue args = inspect.getargspec(function)[0] if args and name.startswith("nova"): exec("pep8.%s = %s" % (name, name)) if __name__ == "__main__": #include nova path sys.path.append(os.getcwd()) #NOVA error codes start with an N pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}') add_nova() pep8.current_file = current_file pep8.readlines = readlines pep8._main()
"description of the change, not just a reference to a bug " "or blueprint" % title.strip()) error = True if len(title.decode('utf-8')) > 72: print("T802: git commit title ('%s') should be under 50 chars" % title.strip()) error = True return error if __name__ == "__main__": #include tempest path sys.path.append(os.getcwd()) #Run once tests (not per line) once_error = once_git_check_commit_title() #TEMPEST error codes start with a T pep8.ERRORCODE_REGEX = re.compile(r'[EWT]\d{3}') add_tempest() pep8.current_file = current_file pep8.readlines = readlines pep8.StyleGuide.excluded = excluded pep8.StyleGuide.input_dir = input_dir try: pep8._main() sys.exit(once_error) finally: if len(_missingImport) > 0: print >> sys.stderr, ( "%i imports missing in this test environment" % len(_missingImport))