def test_incorrect_noqa_comment(
    parse_tokens,
    assert_errors,
    default_options,
    code,
):
    """Ensures that incorrect `noqa` comments raise a warning."""
    file_tokens = parse_tokens(code)

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [WrongMagicCommentViolation])
Exemple #2
0
def test_noqa_comments_can_be_forbidden(
    parse_tokens,
    assert_errors,
    options,
):
    """Ensures that `noqa` comments can be turned off completely."""
    file_tokens = parse_tokens('wallet = 10  # noqa: WPS002, WPS114')

    options = options(max_noqa_comments=0)
    visitor = WrongCommentVisitor(options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [OveruseOfNoqaCommentViolation])
def test_correct_comments(
    parse_tokens,
    assert_errors,
    default_options,
    code,
):
    """Ensures that correct comments do not raise a warning."""
    file_tokens = parse_tokens(code)

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
Exemple #4
0
def test_noqa_overuse(
    parse_tokens,
    assert_errors,
    default_options,
    code,
):
    """Ensures that `noqa` overuse raises a warning."""
    file_tokens = parse_tokens('{0}\n'.format(code) * (10 + 1))

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [OveruseOfNoqaCommentViolation])
Exemple #5
0
def test_no_cover_overuse(
    parse_tokens,
    assert_errors,
    default_options,
    code,
):
    """Ensures that `no cover` overuse raises a warning."""
    file_tokens = parse_tokens((code + '\n') * (5 + 1))

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [OveruseOfNoCoverCommentViolation])
Exemple #6
0
def test_incorrect_doc_comment(
    parse_tokens,
    assert_errors,
    default_options,
    code,
    comment,
):
    """Ensures that incorrect doc comments raise a warning."""
    file_tokens = parse_tokens(code.format(comment))

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [WrongDocCommentViolation])
Exemple #7
0
def test_noqa_overuse_is_configurable(
    parse_tokens,
    assert_errors,
    options,
):
    """Ensures that `noqa` overuse can be configured by options."""
    file_tokens = parse_tokens(
        'wallet = 10  # noqa: WPS002, WPS114\n' * defaults.MAX_NOQA_COMMENTS,
    )

    options = options(max_noqa_comments=defaults.MAX_NOQA_COMMENTS - 1)
    visitor = WrongCommentVisitor(options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [OveruseOfNoqaCommentViolation])
def test_no_cover_overuse(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    code,
):
    """Ensures that `no cover` overuse raises a warning."""
    file_tokens = parse_tokens('{0}\n'.format(code) * (5 + 1))

    visitor = WrongCommentVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [OveruseOfNoCoverCommentViolation])
    assert_error_text(visitor, '6', MAX_NO_COVER_COMMENTS)