Beispiel #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
Beispiel #2
0
def test_hex_cast_value_error():
    caster = from_config({'cast': 'hex'})
    with pytest.raises(SpecException):
        caster.cast('abc123')
Beispiel #3
0
def test_none_is_none():
    caster = from_config({'cast': None})
    assert caster is None
Beispiel #4
0
def test_invalid_casting_float():
    with pytest.raises(SpecException):
        from_config({'cast': 'float'}).cast('456def')
Beispiel #5
0
def test_invalid_casting_int():
    with pytest.raises(SpecException):
        from_config({'cast': 'int'}).cast('abc123')
Beispiel #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