def test_string_overuse_exceptions(
    assert_errors,
    parse_ast_tree,
    default_options,
    prefix,
    string_value,
):
    """Ensures that over-used strings raise violations."""
    snippet = string_actions.format(prefix + string_value)
    tree = parse_ast_tree(snippet)

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

    assert_errors(visitor, [])
def test_common_strings_allowed(
    assert_errors,
    parse_ast_tree,
    default_options,
    prefix,
    string_value,
):
    """Ensures that common strings do not count against the overuse limit."""
    snippet = string_actions.format(prefix + string_value)
    tree = parse_ast_tree(snippet)

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

    assert_errors(visitor, [])
def test_string_type_annotations(
    assert_errors,
    parse_ast_tree,
    options,
    strings,
    string_value,
    mode,
):
    """Ensures that type annotations do not raise violations."""
    tree = parse_ast_tree(mode(strings.format(string_value)))

    option_values = options(max_string_usages=0)
    visitor = StringOveruseVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_string_overuse_settings(
    assert_errors,
    parse_ast_tree,
    options,
    strings,
    string_value,
    mode,
):
    """Ensures that settings for string over-use work."""
    tree = parse_ast_tree(mode(strings.format(string_value)))

    option_values = options(max_string_usages=5)
    visitor = StringOveruseVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_string_overuse(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    strings,
    string_value,
):
    """Ensures that over-used strings raise violations."""
    tree = parse_ast_tree(strings.format(string_value))

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

    assert_errors(visitor, [OverusedStringViolation])
    assert_error_text(visitor, string_value.replace('"', '') or "''")