コード例 #1
0
def test_valid_key_forms():
    valid_names = ['cast']

    for name in valid_names:
        caster = from_config({name: 'float'})
        assert caster is not None
        assert caster.cast('1.1') == 1.1
コード例 #2
0
def test_hex_cast_value_error():
    caster = from_config({'cast': 'hex'})
    with pytest.raises(SpecException):
        caster.cast('abc123')
コード例 #3
0
def test_none_is_none():
    caster = from_config({'cast': None})
    assert caster is None
コード例 #4
0
def test_invalid_casting_float():
    with pytest.raises(SpecException):
        from_config({'cast': 'float'}).cast('456def')
コード例 #5
0
def test_invalid_casting_int():
    with pytest.raises(SpecException):
        from_config({'cast': 'int'}).cast('abc123')
コード例 #6
0
def test_valid_type_cast_forms(input_value, cast_type, expected_value):
    caster = from_config({'cast': cast_type})
    assert caster is not None
    assert caster.cast(input_value) == expected_value