Пример #1
0
def test_protected_attribute_is_allowed(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Ensures that it is possible to use protected attributes."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_whitelist_magic_attributes_are_allowed(
    assert_errors,
    parse_ast_tree,
    code,
    attribute,
    default_options,
    mode,
):
    """Ensures that it is possible to use magic attributes."""
    tree = parse_ast_tree(mode(code.format(attribute)))

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

    assert_errors(visitor, [])
Пример #3
0
def test_magic_attribute_correct_contexts(
    assert_errors,
    parse_ast_tree,
    code,
    attribute,
    default_options,
    mode,
):
    """Ensures it is possible to use magic attributes in certain contexts."""
    tree = parse_ast_tree(mode(code.format(attribute)))

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

    assert_errors(visitor, [])
Пример #4
0
def test_protected_attribute_is_restricted(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
):
    """Ensures that it is impossible to use protected attributes."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [ProtectedAttributeViolation])
    assert_error_text(visitor, '_protected')
Пример #5
0
def test_magic_attribute_is_restricted(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Ensures that it is impossible to use magic attributes."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [DirectMagicAttributeAccessViolation])
    assert_error_text(visitor, '__magic__')
Пример #6
0
def test_other_magic_attributs_allowed(
    assert_errors,
    parse_ast_tree,
    code,
    attribute,
    default_options,
    mode,
):
    """
    Tests if regular attributes are allowed.

    Ensures that it is possible to use regular attributes, as well as
    magic attributes for which no (known) alternative exists.
    """
    tree = parse_ast_tree(mode(code.format(attribute)))

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

    assert_errors(visitor, [])