コード例 #1
0
def test_nested_offset(assert_errors, parse_ast_tree, code, default_options):
    """Testing that nested expression with default options works well."""
    tree = parse_ast_tree(code)

    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
コード例 #2
0
def test_nested_offset_errors(
    assert_errors, parse_ast_tree, code, number_of_errors, options,
):
    """Testing that nested expressions are restricted."""
    tree = parse_ast_tree(code)

    option_values = options(max_offset_blocks=1)
    visitor = OffsetVisitor(option_values, tree=tree)
    visitor.run()

    errors = [TooDeepNestingViolation for _ in range(number_of_errors)]
    assert_errors(visitor, errors)
コード例 #3
0
def test_real_nesting_config(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    mode,
):
    """Ensures that real configuration works."""
    tree = parse_ast_tree(mode(real_nested_values))

    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooDeepNestingViolation])
    assert_error_text(visitor, '24')
コード例 #4
0
def test_nested_offset_regression320(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """
    Testing that await works well with long lines.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/320
    """
    tree = parse_ast_tree(real_await_nested_values)

    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
コード例 #5
0
def test_regression_282(assert_errors, parse_ast_tree, options):
    """
    Testing that issue-282 will not happen again.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/282
    """
    tree = parse_ast_tree("""
    async def no_offset():
        ...
    """)

    option_values = options(max_offset_blocks=1)
    visitor = OffsetVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
コード例 #6
0
def test_nested_offset_error_text(
    monkeypatch,
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that nested expressions are restricted."""
    tree = parse_ast_tree(mode(code))

    monkeypatch.setattr(OffsetVisitor, '_max_offset_blocks', 1)
    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooDeepNestingViolation])
    assert_error_text(visitor, '8')
コード例 #7
0
def test_nested_offset_errors(
    monkeypatch,
    assert_errors,
    parse_ast_tree,
    code,
    number_of_errors,
    default_options,
    mode,
):
    """Testing that nested expressions are restricted."""
    tree = parse_ast_tree(mode(code))

    monkeypatch.setattr(OffsetVisitor, '_max_offset_blocks', 1)
    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    errors = [TooDeepNestingViolation for _ in range(number_of_errors)]
    assert_errors(visitor, errors)
コード例 #8
0
def test_regression282(
    monkeypatch,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """
    Testing that issue-282 will not happen again.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/282
    """
    tree = parse_ast_tree("""
    async def no_offset():
        ...
    """)

    monkeypatch.setattr(OffsetVisitor, '_max_offset_blocks', 1)
    visitor = OffsetVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])