Exemplo n.º 1
0
def main():
    warnings = 0

    parser = argparse.ArgumentParser(description='Quickly check the correctness of your Python scripts.')
    parser.add_argument('files', nargs='+', help='One or more Python source files that need their imports sorted.')
    parser.add_argument('-r', '--recursive', dest='recursive', action='store_true',
                        help='Recursively look for Python files to check')
    parser.add_argument('-s', '--skip', help='Files that frosted should skip over.', dest='skip', action='append')
    parser.add_argument('-i', '--ignore', help='Specify error codes that should be ignored.', dest='ignore_frosted_errors',
                        action='append')
    parser.add_argument('-vb', '--verbose', help='Explicitly separate each section of data when displaying errors.',
                        dest='verbose', action='store_true')
    parser.add_argument('-v', '--version', action='version', version='frosted {0}'.format(__version__))
    arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
    file_names = arguments.pop('files', [])
    if file_names == ['-']:
        check(sys.stdin.read(), '<stdin>', **arguments)
    elif arguments.get('recursive'):
        warnings = check_recursive(file_names, **arguments)
    else:
        warnings = 0
        for file_path in file_names:
            try:
                warnings += check_path(file_path, directly_being_checked=len(file_names), **arguments)
            except IOError as e:
                print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e))

    raise SystemExit(warnings > 0)
Exemplo n.º 2
0
def main():
    warnings = 0

    parser = argparse.ArgumentParser(description='Quickly check the correctness of your Python scripts.')
    parser.add_argument('files', nargs='+', help='One file or a list of Python source files to check the syntax of.')
    parser.add_argument('-r', '--recursive', dest='recursive', action='store_true',
                        help='Recursively look for Python files to check')
    parser.add_argument('-s', '--skip', help='Files that frosted should skip over.', dest='skip', action='append')
    parser.add_argument('-d', '--with-doctests', help='Run frosted against doctests', dest='run_doctests',
                        action='store_true')
    parser.add_argument('-i', '--ignore', help='Specify error codes that should be ignored.',
                        dest='ignore_frosted_errors', action='append')
    parser.add_argument('-di', '--dont-ignore', help='Specify error codes that should not be ignored in any case.',
                        dest='not_ignore_frosted_errors', action='append')
    parser.add_argument('-vb', '--verbose', help='Explicitly separate each section of data when displaying errors.',
                        dest='verbose', action='store_true')
    parser.add_argument('-v', '--version', action='version', version='frosted {0}'.format(__version__))
    arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
    file_names = arguments.pop('files', [])
    if file_names == ['-']:
        check(sys.stdin.read(), '<stdin>', **arguments)
    elif arguments.get('recursive'):
        warnings = check_recursive(file_names, **arguments)
    else:
        warnings = 0
        for file_path in file_names:
            try:
                warnings += check_path(file_path, directly_being_checked=len(file_names), **arguments)
            except IOError as e:
                print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e))

    raise SystemExit(warnings > 0)
Exemplo n.º 3
0
def test_check_integration():
    """ make sure all the above logic comes together correctly in the check() function """
    output = []
    reporter = LoggingReporter(output)

    result = check('from fu import *', 'test', reporter, not_ignore_frosted_errors=['E103'])

    # errors reported
    assert result == 1
    assert "unable to detect undefined names" in output.pop(0)[1]

    # same test, but with ignore set
    output = []
    reporter = LoggingReporter(output)

    result = check('from fu import * # noqa', 'test', reporter)

    # errors reported
    assert result == 0
    assert len(output) == 0
Exemplo n.º 4
0
def test_check_integration():
    """ make sure all the above logic comes together correctly in the check() function """
    output = []
    reporter = LoggingReporter(output)

    result = check('from fu import *',
                   'test',
                   reporter,
                   not_ignore_frosted_errors=['E103'])

    # errors reported
    assert result == 1
    assert "unable to detect undefined names" in output.pop(0)[1]

    # same test, but with ignore set
    output = []
    reporter = LoggingReporter(output)

    result = check('from fu import * # noqa', 'test', reporter)

    # errors reported
    assert result == 0
    assert len(output) == 0