Exemplo n.º 1
0
def frosted(filename):
    codeString = open(filename, 'U').read() + '\n'
    errors = []
    try:
        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
    except SyntaxError as e:
        errors.append(
            dict(lnum=e.lineno or 0,
                 col=e.offset or 0,
                 text=getattr(e, 'msg', None) or str(e),
                 type='E'))
    else:
        w = checker.Checker(tree,
                            filename,
                            ignore_lines=_noqa_lines(codeString))
        for w in sorted(w.messages, key=attrgetter('lineno')):
            errors.append(
                dict(lnum=w.lineno,
                     col=0,
                     text=u'{0} {1}'.format(
                         flake_class_mapping.get(w.__class__, ''),
                         w.message.split(':', 2)[-1].strip()),
                     type='E'))
    return errors
Exemplo n.º 2
0
def frosted(filename):
    codeString = open(filename, 'U').read() + '\n'
    errors = []
    try:
        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
    except SyntaxError as e:
        errors.append(dict(
            lnum=e.lineno or 0,
            col=e.offset or 0,
            text=getattr(e, 'msg', None) or str(e),
            type='E'
        ))
    else:
        w = checker.Checker(tree, filename, ignore_lines=_noqa_lines(codeString))
        for w in sorted(w.messages, key=attrgetter('lineno')):
            errors.append(dict(
                lnum=w.lineno,
                col=0,
                text=u'{0} {1}'.format(
                    flake_class_mapping.get(w.__class__, ''),
                    w.message.split(':', 2)[-1].strip()),
                type='E'
            ))
    return errors
Exemplo n.º 3
0
def test_noqa_lines():
    assert _noqa_lines('from fu import bar; bar') == []
    assert _noqa_lines('from fu import * # noqa; bar') == [1]
    assert _noqa_lines('from fu import * #noqa\nbar\nfoo # frosted: noqa') == [1, 3]
Exemplo n.º 4
0
def test_noqa_lines():
    assert _noqa_lines('from fu import bar; bar') == []
    assert _noqa_lines('from fu import * # noqa; bar') == [1]
    assert _noqa_lines('from fu import * #noqa\nbar\nfoo # frosted: noqa') == [
        1, 3
    ]