Пример #1
0
def test_nested_class(assert_errors, parse_ast_tree, code):
    """Testing that nested classes are restricted."""
    tree = parse_ast_tree(code.format('NestedClass'))

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [NestedClassViolation])
def test_nested_function(assert_errors, parse_ast_tree, code):
    """Testing that nested functions are restricted."""
    tree = parse_ast_tree(code.format('nested'))

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [NestedFunctionViolation])
Пример #3
0
def test_ordinary_class(assert_errors, parse_ast_tree):
    """Testing that it is possible to write basic classes."""
    tree = parse_ast_tree("""
    class Ordinary:
        def method(self): ...
    """)

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [])
def test_lambda_nested_lambdas(assert_errors, parse_ast_tree):
    """Testing that it is possible to nest lambdas."""
    tree = parse_ast_tree("""
    def container():
        nested_lambda = lambda: lambda value: value + 12
    """)

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [])
def test_lambda_nested_functions(assert_errors, parse_ast_tree):
    """Testing that it is possible to nest lambda inside functions."""
    tree = parse_ast_tree("""
    def container():
        lazy_value = lambda: 12
    """)

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [])
def test_lambda_nested_method(assert_errors, parse_ast_tree):
    """Testing that it is possible to nest lambda inside methods."""
    tree = parse_ast_tree("""
    class Raw:
        def container(self):
            lazy_value = lambda: 12
    """)

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [])
Пример #7
0
def test_whitelist_nested_classes_in_functions(
    assert_errors,
    parse_ast_tree,
    whitelist_name,
    code,
):
    """Testing that it is restricted to nest any classes in functions."""
    tree = parse_ast_tree(code.format(whitelist_name))

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [NestedClassViolation])
Пример #8
0
def test_whitelist_nested_classes(
    assert_errors,
    parse_ast_tree,
    whitelist_name,
    code,
):
    """Testing that it is possible to nest whitelisted classes."""
    tree = parse_ast_tree(code.format(whitelist_name))

    visiter = WrongNestedVisitor()
    visiter.visit(tree)

    assert_errors(visiter, [])