Exemplo n.º 1
0
def test_context_manager_alone_target(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing correct count context manager assignment."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [])
def test_context_manager_correct_definitions(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing correct definitions context manager assignment."""
    tree = parse_ast_tree(mode(context_manager_definition.format(code)))

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

    assert_errors(visitor, [])
Exemplo n.º 3
0
def test_context_manager_multiple_targets(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing incorrect count context manager assignment."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [MultipleContextManagerAssignmentsViolation])