Esempio n. 1
0
def test_private_variable_names(
    assert_errors, parse_ast_tree, code, default_options,
):
    """Testing that variable can not have private names."""
    tree = parse_ast_tree(code.format('__private_value'))

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

    assert_errors(visitor, [PrivateNameViolation])
Esempio n. 2
0
def test_snake_case_class_attributes(
    assert_errors, parse_ast_tree, snake_case_name, default_options,
):
    """Testing that attribute can not have too short names."""
    tree = parse_ast_tree(static_attribute.format(snake_case_name))

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

    assert_errors(visitor, [])
Esempio n. 3
0
def test_too_short_variable_names(
    assert_errors, parse_ast_tree, short_name, code, default_options,
):
    """Testing that variable can not have too short names."""
    tree = parse_ast_tree(code.format(short_name))

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

    assert_errors(visitor, [TooShortVariableNameViolation])
Esempio n. 4
0
def test_correct_variable_name(
    assert_errors, parse_ast_tree, code, correct_name, default_options,
):
    """Testing that variable can have normal names."""
    tree = parse_ast_tree(code.format(correct_name))

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

    assert_errors(visitor, [])
Esempio n. 5
0
def test_wrong_variable_names(
    assert_errors, parse_ast_tree, bad_name, code, default_options,
):
    """Testing that variable can not have blacklisted names."""
    tree = parse_ast_tree(code.format(bad_name))

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

    assert_errors(visitor, [WrongVariableNameViolation])
Esempio n. 6
0
def test_too_short_variable_names_configured(
    assert_errors, parse_ast_tree, code, options,
):
    """Testing that variable length can be configured."""
    tree = parse_ast_tree(code.format('kira'))

    option_values = options(min_variable_length=5)
    visitor = WrongNameVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooShortVariableNameViolation])
Esempio n. 7
0
def test_consecutive_underscores_in_variable_name(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that variable can not have private names."""
    tree = parse_ast_tree(code.format('some__value'))

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

    assert_errors(visitor, [ConsecutiveUnderscoresInNameViolation])
Esempio n. 8
0
def test_private_import_alias_names(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that import aliases can not have too private names."""
    tree = parse_ast_tree(code.format('__hidden'))

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

    assert_errors(visitor, [PrivateNameViolation])
def test_correct_function_arguments(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that function can have normal arguments."""
    tree = parse_ast_tree(code.format('good_name', 'normal_name'))

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

    assert_errors(visitor, [])
def test_underscored_number_not_in_variable_names(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that variable can not have private names."""
    tree = parse_ast_tree(code.format('test34', 'test32_109'))

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

    assert_errors(visitor, [])
Esempio n. 11
0
def test_correct_variable_usage(
    assert_errors,
    parse_ast_tree,
    bad_name,
    code,
    default_options,
):
    """Testing that any variable can used without raising violations."""
    tree = parse_ast_tree(code.format(bad_name))

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

    assert_errors(visitor, [])
Esempio n. 12
0
def test_naming_correct(
    assert_errors,
    parse_ast_tree,
    naming_template,
    options,
    correct_name,
):
    """Ensures that correct names are allowed."""
    tree = parse_ast_tree(naming_template.format(correct_name))

    option_values = options(min_name_length=3)
    visitor = WrongNameVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_correct_trailing_underscore(
    assert_errors,
    parse_ast_tree,
    naming_template,
    default_options,
    correct_name,
    mode,
):
    """Test names with correct trailing underscores."""
    tree = parse_ast_tree(mode(naming_template.format(correct_name)))

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

    assert_errors(visitor, [])
Esempio n. 14
0
def test_correct_argument_name(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    mode,
    argument,
):
    """Ensures that special names for arguments are restricted."""
    tree = parse_ast_tree(mode(code.format(argument)))

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

    assert_errors(visitor, [])
Esempio n. 15
0
def test_correct_unused_variable_name(
    assert_errors,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    wrong_name,
):
    """Ensures that wrong names are not allowed."""
    tree = parse_ast_tree(mode(naming_template.format(wrong_name)))

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

    assert_errors(visitor, [])
Esempio n. 16
0
def test_upper_case_class_attributes(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    non_snake_case_name,
    default_options,
):
    """Testing that attribute can not have too short names."""
    tree = parse_ast_tree(static_attribute.format(non_snake_case_name))

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

    assert_errors(visitor, [UpperCaseAttributeViolation])
    assert_error_text(visitor, non_snake_case_name)
Esempio n. 17
0
def test_naming_correct(
    assert_errors,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    correct_name,
):
    """Ensures that correct names are allowed."""
    tree = parse_ast_tree(mode(naming_template.format(correct_name)))

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

    assert_errors(visitor, [])
def test_correct_first_arguments(
    assert_errors,
    parse_ast_tree,
    argument,
    code,
    default_options,
    mode,
):
    """Testing that first arguments are allowed."""
    tree = parse_ast_tree(mode(code.format(argument)))

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

    assert_errors(visitor, [])
Esempio n. 19
0
def test_underscored_number_in_variable_names(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    underscored_name,
    code,
    default_options,
):
    """Testing that variable can not have private names."""
    tree = parse_ast_tree(code.format(underscored_name))

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

    assert_errors(visitor, [UnderscoredNumberNameViolation])
    assert_error_text(visitor, underscored_name)
Esempio n. 20
0
def test_regression423(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """
    Tests that this issue-423 won't happen again.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/423
    """
    tree = parse_ast_tree(regression423)

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

    assert_errors(visitor, [])
Esempio n. 21
0
def test_underscored_function_arguments(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that function can not have arguments with two underscores."""
    tree = parse_ast_tree(code.format('underscore___name', 'other__name'))

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

    assert_errors(visitor, [
        ConsecutiveUnderscoresInNameViolation,
        ConsecutiveUnderscoresInNameViolation,
    ])
def test_private_function_arguments(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that function can not have private arguments."""
    tree = parse_ast_tree(code.format('__private', '__name'))

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

    assert_errors(visitor, [
        PrivateNameViolation,
        PrivateNameViolation,
    ])
Esempio n. 23
0
def test_short_variable_name_underscore(
    assert_errors,
    parse_ast_tree,
    naming_template,
    default_options,
    short_name,
    mode,
):
    """Ensures that short names are not allowed."""
    tree = parse_ast_tree(mode(naming_template.format(short_name)))

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

    assert_errors(visitor, [TooShortNameViolation],
                  (TrailingUnderscoreViolation, ))
Esempio n. 24
0
def test_long_variable_name_config(
    assert_errors,
    parse_ast_tree,
    naming_template,
    options,
    mode,
):
    """Ensures that it is possible to configure `max_name_length`."""
    long_name = 'incredibly_long_name_that_should_not_pass_the_long_name_test'
    tree = parse_ast_tree(mode(naming_template.format(long_name)))

    option_values = options(max_name_length=len(long_name) + 1)
    visitor = WrongNameVisitor(option_values, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Esempio n. 25
0
def test_underscored_variable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    underscored_name,
):
    """Ensures that underscored names are not allowed."""
    tree = parse_ast_tree(mode(naming_template.format(underscored_name)))

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

    assert_errors(visitor, [ConsecutiveUnderscoresInNameViolation])
    assert_error_text(visitor, underscored_name)
Esempio n. 26
0
def test_private_variable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
):
    """Ensures that private names are not allowed."""
    private_name = '__private'
    tree = parse_ast_tree(mode(naming_template.format(private_name)))

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

    assert_errors(visitor, [PrivateNameViolation])
    assert_error_text(visitor, private_name)
Esempio n. 27
0
def test_short_variable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
):
    """Ensures that short names are not allowed."""
    short_name = 'y'
    tree = parse_ast_tree(mode(naming_template.format(short_name)))

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

    assert_errors(visitor, [TooShortNameViolation])
    assert_error_text(visitor, short_name)
Esempio n. 28
0
def test_wrong_variable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    wrong_name,
):
    """Ensures that wrong names are not allowed."""
    tree = parse_ast_tree(mode(naming_template.format(wrong_name)))

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

    assert_errors(visitor, [WrongVariableNameViolation])
    assert_error_text(visitor, wrong_name)
Esempio n. 29
0
def test_number_prefix_variable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    number_suffix,
):
    """Ensures that number suffix names are not allowed."""
    tree = parse_ast_tree(mode(naming_template.format(number_suffix)))

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

    assert_errors(visitor, [UnderscoredNumberNameViolation])
    assert_error_text(visitor, number_suffix)
Esempio n. 30
0
def test_wrong_unicode(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    naming_template,
    default_options,
    mode,
    wrong_name,
):
    """Test names with unicode."""
    tree = parse_ast_tree(mode(naming_template.format(wrong_name)))

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

    assert_errors(visitor, [UnicodeNameViolation])
    assert_error_text(visitor, wrong_name)