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

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

    assert_errors(visitor, [NestedFunctionViolation])
def test_whitelist_nested_functions(
    assert_errors, parse_ast_tree, whitelist_name, code, default_options,
):
    """Testing that it is possible to nest whitelisted functions."""
    tree = parse_ast_tree(code.format(whitelist_name))

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

    assert_errors(visitor, [])
def test_ordinary_class(assert_errors, parse_ast_tree, default_options):
    """Testing that it is possible to write basic classes."""
    tree = parse_ast_tree("""
    class Ordinary:
        def method(self): ...
    """)

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

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

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

    assert_errors(visitor, [])
示例#5
0
def test_lambda_nested_functions(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that it is possible to nest lambda inside functions."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_whitelist_nested_classes_in_functions(
    assert_errors,
    parse_ast_tree,
    whitelist_name,
    code,
    default_options,
):
    """Testing that it is restricted to nest any classes in functions."""
    tree = parse_ast_tree(code.format(whitelist_name))

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

    assert_errors(visitor, [NestedClassViolation])
def test_lambda_nested_lambdas(assert_errors, parse_ast_tree, default_options):
    """
    Testing that it is restricted to nest lambdas.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/94
    """
    tree = parse_ast_tree("""
    def container():
        nested_lambda = lambda: lambda value: value + 12
    """)

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

    assert_errors(visitor, [NestedFunctionViolation])
def test_nested_class(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that nested classes are restricted."""
    nested_name = 'NestedClass'
    tree = parse_ast_tree(mode(code.format(nested_name)))

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

    assert_errors(visitor, [NestedClassViolation])
    assert_error_text(visitor, nested_name)
def test_custom_whitelist_nested_classes(
    assert_errors,
    parse_ast_tree,
    whitelist_name,
    code,
    options,
    mode,
):
    """Testing that it is possible to nest custom whitelisted classes."""
    tree = parse_ast_tree(mode(code.format(whitelist_name)))

    option_values = options(
        nested_classes_whitelist=[*NESTED_CLASSES_WHITELIST, 'NestedClass'], )

    visitor = NestedComplexityVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
示例#10
0
def test_lambda_nested_lambdas(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    code,
    mode,
):
    """
    Testing that it is restricted to nest lambdas.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/94
    """
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [NestedFunctionViolation])
    assert_error_text(visitor, 'lambda')
def test_ordinary_class(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
):
    """Testing that it is possible to write basic classes."""
    code = """
    class Ordinary(object):
        def method(self): ...

    class Second(Ordinary):
        def method(self): ...
    """
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [])