예제 #1
0
def test_StoreIO_coerce__raises_custom_ValueError_if_coercion_is_impossible():
    abcd = namedtuple('abcd', ['a', 'b', 'c', 'd'])
    x = abcd('A', 'B', 'C', 'D')
    S = StoreIO(**x._asdict())
    with pytest.raises(ValueError) as excinfo:
        S._coerce_attrs()
    assert str(excinfo.value) == "Cannot coerce StoreIO.a to <class 'int'>"
예제 #2
0
def test_StoreIO_coerce__raises_custom_ValueError_to_prevent_float_to_int_coercion(
):
    abcd = namedtuple('abcd', ['a', 'b', 'c', 'd'])
    x = abcd("1", 1.5, "2", '3')
    S = StoreIO(**x._asdict())
    #with pytest.raises(ValueError) as excinfo:
    with pytest.raises(ValueError):
        S._coerce_attrs()
예제 #3
0
def test_StoreIO_coerce_attrs_then_validate_attrs__with_partial_set():
    abc = namedtuple('abc', ['a', 'b', 'c'])
    x = abc('1', '2', '3')
    S = StoreIO(**x._asdict())
    assert isinstance(S.a, str)
    assert isinstance(S.c, str)
    S._coerce_attrs()
    assert isinstance(S.a, int)
    assert isinstance(S.c, int)
    assert S._validate_attrs()
예제 #4
0
def test_StoreIO_coerce_attrs_then_validate_attrs():
    abcd = namedtuple('abcd', ['a', 'b', 'c', 'd'])
    x = abcd('1', '2', '3', '4')
    S = StoreIO(**x._asdict())
    S._coerce_attrs()
    assert S._validate_attrs()