def test_wrong_string(assert_errors, parse_ast_tree, code, default_options):
    """Testing that violations are raised when reaching max value."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [FormattedStringViolation])
Пример #2
0
def test_string_normal(
    assert_errors, parse_ast_tree, code, default_options,
):
    """Testing that regular strings work well."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
Пример #3
0
def test_alphabet_as_string_no_violation(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that regular strings work well."""
    tree = parse_ast_tree('"{0}"'.format(code))

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

    assert_errors(visitor, [])
Пример #4
0
def test_alphabet_as_fstring_violation(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing that the fstrings violate the rules."""
    tree = parse_ast_tree('f"{0}"'.format(string.ascii_letters))

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

    assert_errors(visitor, [StringConstantRedefinedViolation],
                  (FormattedStringViolation, ))
def test_string_overuse_settings(
    assert_errors,
    parse_ast_tree,
    options,
):
    """Ensures that settings for string over-use work."""
    tree = parse_ast_tree(string_actions.format('"same-string"'))

    option_values = options(max_string_usages=4)
    visitor = WrongStringVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Пример #6
0
def test_docstring_modulo_operations(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that the docstrings are allowed."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
Пример #7
0
def test_modulo_operations(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that the modulo operations are not affected."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_functions_modulo_string(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that the strings violate the rules."""
    tree = parse_ast_tree(code)

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

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

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

    assert_errors(visitor, [OverusedStringViolation])
    assert_error_text(visitor, string_value.replace('"', ''))
Пример #10
0
def test_regular_modulo_string(
    assert_errors,
    parse_ast_tree,
    code,
    prefix,
    default_options,
):
    """Testing that the strings violate the rules."""
    tree = parse_ast_tree('x = {0}"{1}"'.format(prefix, code))

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

    assert_errors(visitor, [], (FormattedStringViolation, ))
def test_alphabet_as_string_violation(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that the strings violate the rules."""
    tree = parse_ast_tree('"{0}"'.format(code))

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

    assert_errors(visitor, [StringConstantRedefinedViolation])
    assert_error_text(visitor, code)
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 = WrongStringVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])