def test_float_zero(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    mode,
):
    """Ensures that float zeros (0.0) raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format('0.0')))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [FloatZeroViolation])
Beispiel #2
0
def test_correct_float(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    primitive,
    mode,
):
    """Ensures that correct floats are fine."""
    file_tokens = parse_tokens(mode(primitives_usages.format(primitive)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_correct_zero_and_non_zero_numbers(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    primitive,
    mode,
):
    """Ensures that correct zeros and non-zero numbers don't raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format(primitive)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_correct_exponent(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    number,
    mode,
):
    """Ensures that correct exponent is allowed."""
    file_tokens = parse_tokens(mode(primitives_usages.format(number)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_hex_correct_case(
    parse_tokens,
    assert_errors,
    default_options,
    hex_char,
    number,
    number_sign,
):
    """Ensures that numbers with correct numbers do not raise a warning."""
    file_tokens = parse_tokens(number_sign(number.format(hex_char)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_similar_strings(
    parse_tokens,
    assert_errors,
    default_options,
    code,
    number,
    mode,
):
    """Ensures that strings are fine."""
    file_tokens = parse_tokens(mode(code.format(number)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_correct_number_suffixes(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    number,
    number_sign,
    mode,
):
    """Ensures that correct numbers are fine."""
    file_tokens = parse_tokens(
        mode(primitives_usages.format(number_sign(number))), )

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
def test_positive_exponent(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    number,
    mode,
):
    """Ensures that numbers with positive exponent are incorrect."""
    file_tokens = parse_tokens(mode(primitives_usages.format(number)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [PositiveExponentViolation])
    assert_error_text(visitor, number.lstrip('-').lstrip('+'))
Beispiel #9
0
def test_correct_complex_suffix(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    number,
    number_sign,
    mode,
):
    """Ensures that numbers with suffix not in lowercase raise a warning."""
    file_tokens = parse_tokens(
        mode(primitives_usages.format(number_sign(number))), )

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [])
Beispiel #10
0
def test_partial_float(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    primitive,
    mode,
):
    """Ensures that partial floats raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format(primitive)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [PartialFloatViolation])
    assert_error_text(visitor, primitive.replace('-', ''))
def test_underscored_number(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    primitive,
    mode,
):
    """Ensures that underscored numbers raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format(primitive)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [UnderscoredNumberViolation])
    assert_error_text(visitor, primitive.replace('-', ''))
def test_bad_number_suffixes(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    number,
    mode,
):
    """Ensures that numbers with suffix not in lowercase raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format(number)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [BadNumberSuffixViolation])
    assert_error_text(visitor, number.replace('-', ''))
def test_hex_wrong_case(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    hex_char,
    number,
    number_sign,
):
    """Ensures that numbers with suffix not in lowercase raise a warning."""
    real_number = number.format(hex_char)
    file_tokens = parse_tokens(number_sign(real_number))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [WrongHexNumberCaseViolation])
    assert_error_text(visitor, real_number)
def test_hex_double_wrong_case(
    parse_tokens,
    assert_errors,
    default_options,
    hex_char,
    number,
    number_sign,
):
    """Ensures that numbers with suffix not in lowercase raise a warning."""
    real_number = number.format(hex_char).replace('x', 'X')
    file_tokens = parse_tokens(number_sign(real_number))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [
        BadNumberSuffixViolation,
        WrongHexNumberCaseViolation,
    ])
def test_all_error_in_exponent(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    number,
    mode,
):
    """Ensures that numbers with positive exponent are incorrect."""
    file_tokens = parse_tokens(mode(primitives_usages.format(number)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [
        BadNumberSuffixViolation,
        NumberWithMeaninglessZeroViolation,
        PositiveExponentViolation,
    ])
Beispiel #16
0
def test_double_incorrect_float(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    primitive,
    mode,
):
    """Ensures that partial floats raise a warning."""
    file_tokens = parse_tokens(mode(primitives_usages.format(primitive)))

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [
        PartialFloatViolation,
        NumberWithMeaninglessZeroViolation,
    ])
def test_meaningless_zeros(
    parse_tokens,
    assert_errors,
    assert_error_text,
    default_options,
    primitives_usages,
    number,
    number_sign,
    mode,
):
    """Ensures that numbers with suffix not in lowercase raise a warning."""
    file_tokens = parse_tokens(
        mode(primitives_usages.format(number_sign(number))), )

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [NumberWithMeaninglessZeroViolation])
    assert_error_text(visitor, number.lstrip('-').lstrip('+'))
def test_meaningless_zeros_and_case(
    parse_tokens,
    assert_errors,
    default_options,
    primitives_usages,
    number,
    number_sign,
    mode,
):
    """Ensures that numbers raise two violations."""
    file_tokens = parse_tokens(
        mode(primitives_usages.format(number_sign(number))), )

    visitor = WrongNumberTokenVisitor(default_options, file_tokens=file_tokens)
    visitor.run()

    assert_errors(visitor, [
        BadNumberSuffixViolation,
        NumberWithMeaninglessZeroViolation,
    ])