Пример #1
0
def test_abc_with_decimal_argument_fails():
    """Test that string with letters in fails when we supply 'decimal'."""
    test = CastToInteger()(
        'abc',
        'decimal',
    )
    assert not is_successful(test)
    assert isinstance(test.failure(), ValueError)
    assert 'Illegal characters in value' in str(test.failure())
Пример #2
0
def test_cast_string():
    """Cast a string with numbers to integer."""
    assert CastToInteger()('123').unwrap() == target
Пример #3
0
def test_cast_decimal_string_rounds_down():
    """Cast a decimal string < .0 should round down."""
    assert CastToInteger()(
        '123.49',
        'decimal',
    ).unwrap() == target
Пример #4
0
def test_abc_fails():
    """Test that string with letters in fails."""
    test = CastToInteger()('abc')
    assert not is_successful(test)
    assert isinstance(test.failure(), ValueError)
    assert 'Illegal characters in value' in str(test.failure())
Пример #5
0
def test_once_more_cast_decimal_string_rounds_up():
    """Cast a decimal string >= .5 should round up."""
    assert CastToInteger()(
        '123.5',
        'decimal',
    ).unwrap() == 124
Пример #6
0
def test_cast_decimal_string_rounds_up():
    """Cast a decimal string >= .5 should round up."""
    assert CastToInteger()(
        '122.5',
        'decimal',
    ).unwrap() == target
Пример #7
0
def test_cast_negative_decimal_string():
    """Cast a negative decimal string to integer."""
    assert CastToInteger()(
        '-123.0', 'decimal',
    ).unwrap() == -target
Пример #8
0
def test_cast_decimal_string():
    """Cast a decimal string to integer."""
    assert CastToInteger()(
        '123.0',
        'decimal',
    ).unwrap() == target
Пример #9
0
def test_cast_negative_string():
    """Cast string with negative number to integer."""
    assert CastToInteger()('-123').unwrap() == -target