示例#1
0
def test_module_condition_counts_normal(
    assert_errors, parse_ast_tree, code, default_options,
):
    """Testing that conditions in a module work well."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
示例#2
0
def test_module_condition_counts_violation(
    assert_errors, parse_ast_tree, code, options,
):
    """Testing that violations are raised when reaching max value."""
    tree = parse_ast_tree(code)

    option_values = options(max_conditions=1)
    visitor = ConditionsVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooManyConditionsViolation])
示例#3
0
def test_module_compare_counts_violation(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that violations are raised when reaching max value."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [TooLongCompareViolation])
def test_module_condition_real_config(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    code,
):
    """Testing that violations are raised when reaching max value."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [TooManyConditionsViolation])
    assert_error_text(visitor, '5', baseline=4)
def test_module_condition_counts_violation(
    monkeypatch,
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that violations are raised when reaching max value."""
    tree = parse_ast_tree(code)

    monkeypatch.setattr(ConditionsVisitor, '_max_conditions', 1)
    visitor = ConditionsVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooManyConditionsViolation])
    assert_error_text(visitor, '2', baseline=1)