Пример #1
0
def test_to_tokens_line_with_error():
    with pytest.raises(MatchError):
        to_tokens_line('"0.0')
    with pytest.raises(DuplicateUniqueToken):
        to_tokens_line('[Red][Red]0.0')
    with pytest.raises(DuplicateUniqueToken):
        to_tokens_line('[>=0][<0]0.0')
    with pytest.raises(DuplicateUniqueToken):
        to_tokens_line('[ss][mm]')
    with pytest.raises(DuplicateUniqueToken):
        to_tokens_line('[$$-409][$$-409]0.0')
Пример #2
0
def test_condition_checker(symbol, r1, r2, r3, part, value, fc):
    value = to_decimal(value)

    part = part(fc=fc, tokens=to_tokens_line('[%s%s]0.0' % (symbol, value)))
    assert part.check_value(value + 1) is r1
    assert part.check_value(value) is r2
    assert part.check_value(value - 1) is r3
Пример #3
0
    def __init__(self, line, asterisk_repeat_count=0):
        self.asterisk_repeat_count = asterisk_repeat_count

        tokens = to_tokens_line(line)
        self.parts = self.parts_from_tokens(tokens)
        self.pos_part, self.neg_part, self.else_part, self.str_part = self.parts

        for part in self.parts:
            part.handler.configure()
Пример #4
0
def test_zero_part(value, fc):
    value = to_decimal(value)

    tokens = to_tokens_line('0.0')
    part = ZeroPart(fc=fc, tokens=tokens)
    is_zero = isinstance(value, Decimal) and value == 0

    assert part.handler_class == DigitHandler
    assert part.check_value(value) is is_zero
Пример #5
0
def test_negative_part(value, fc):
    value = to_decimal(value)

    tokens = to_tokens_line('0.0')
    part = NegativePart(fc=fc, tokens=tokens)
    is_negative = isinstance(value, Decimal) and value < 0

    assert part.handler_class == DigitHandler
    assert part.check_value(value) is is_negative
Пример #6
0
def test_string_part(value, fc):
    value = to_decimal(value)

    tokens = to_tokens_line('"hello"')
    part = StringPart(fc=fc, tokens=tokens)
    is_digit = isinstance(value, Decimal)

    assert part.handler_class == StringHandler
    assert part.check_value(value) is not is_digit
    assert part.check_value(text_type(value)) is not is_digit
Пример #7
0
def test_handler_detect(fc):
    assert PositivePart(
        fc=fc,
        tokens=to_tokens_line('General')).handler_class == GeneralHandler
    assert PositivePart(
        fc=fc, tokens=to_tokens_line('0.0')).handler_class == DigitHandler
    assert PositivePart(
        fc=fc, tokens=to_tokens_line('"hello"')).handler_class == DigitHandler
    assert PositivePart(
        fc=fc, tokens=to_tokens_line('yy:mm:dd')).handler_class == DateHandler
    assert PositivePart(
        fc=fc,
        tokens=to_tokens_line('[h]:mm')).handler_class == TimeDeltaHandler
    assert PositivePart(
        fc=fc,
        tokens=to_tokens_line('[h]:mm.00')).handler_class == TimeDeltaHandler
    assert PositivePart(
        fc=fc, tokens=to_tokens_line('')).handler_class == EmptyHandler
    assert PositivePart(fc=fc, tokens=None).handler_class == UnknownHandler

    assert StringPart(
        fc=fc,
        tokens=to_tokens_line('"hello"@')).handler_class == StringHandler
Пример #8
0
def test_part_validate(fc):
    # GeneralFormatError
    with pytest.raises(GeneralFormatError):
        PositivePart(fc=fc, tokens=to_tokens_line('General0.0General'))

    # DuplicateFractionFormat
    with pytest.raises(DuplicateFractionFormat):
        PositivePart(fc=fc, tokens=to_tokens_line('0.00/0'))

    with pytest.raises(DuplicateFractionFormat):
        PositivePart(fc=fc, tokens=to_tokens_line('0/0E+0'))

    # DateDigitError
    with pytest.raises(DateDigitError):
        PositivePart(fc=fc, tokens=to_tokens_line('yy.00'))

    with pytest.raises(DateDigitError):
        NegativePart(fc=fc, tokens=to_tokens_line('mm.00'))

    with pytest.raises(DateDigitError):
        ZeroPart(fc=fc, tokens=to_tokens_line('dd.00'))

    # ConditionError
    with pytest.raises(ConditionError):
        ZeroPart(fc=fc, tokens=to_tokens_line('[>100]0.0'))

    with pytest.raises(ConditionError):
        StringPart(fc=fc, tokens=to_tokens_line('[>100]0.0'))

    # IllegalPartToken
    with pytest.raises(IllegalPartToken):
        StringPart(fc=fc, tokens=to_tokens_line('0.0'))

    with pytest.raises(IllegalPartToken):
        PositivePart(fc=fc, tokens=to_tokens_line('@0.0'))

    with pytest.raises(IllegalPartToken):
        NegativePart(fc=fc, tokens=to_tokens_line('@0.0'))

    with pytest.raises(IllegalPartToken):
        ZeroPart(fc=fc, tokens=to_tokens_line('@0.0'))

    with pytest.raises(IllegalPartToken):
        ZeroPart(fc=fc, tokens=to_tokens_line('[h]:mm" "?/?'))
Пример #9
0
def test_to_tokens_line(code, result):
    assert to_classes(to_tokens_line(code)) == result