def test_correct_subscripts(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that non-redundant subscripts are allowed."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
def test_redundant_subscript(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that redundant subscripts are forbidden."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [RedundantSubscriptViolation])
def test_nonconsecutive_slices(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that non-consecutive slices are allowed."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
def test_forbidden_consecutive_slices(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that consecutive slices are forbidden."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [ConsecutiveSlicesViolation])
Exemple #5
0
def test_regular_index_assignment(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that regular index assignment is allowed."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
Exemple #6
0
def test_slice_assignment(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that slice assignments are forbidden."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [AssignToSliceViolation])