def test_StoreIO_validate_attrs__raises_TypeError(): """ _validate_attrs raises an error if supplied attribute is not the correct type """ abcd = namedtuple('abcd', ['a', 'b', 'c', 'd']) x = abcd(1.0, 2, 3, 4) S = StoreIO(**x._asdict()) with pytest.raises(TypeError): S._validate_attrs()
def test_StoreIO_validate_attrs__passes_with_full_correct_set(): """ _validate_attrs returns True when all valid args are of correct type matching self.valid_attrs_type which is default [int,int,int,int] """ abcd = namedtuple('abcd', ['a', 'b', 'c', 'd']) x = abcd(1, 2, 3, 4) S = StoreIO(**x._asdict()) assert S._validate_attrs()
def test_StoreIO_validate_attrs__passes_with_partial_correct_set(): """ _validate_attrs returns True when partial set of valid args are of correct type and the rest are None (i.e. left blank) """ abc = namedtuple('abcd', ['a', 'b', 'c']) x = abc(1, 2, 3) S = StoreIO(**x._asdict()) assert (S.d is None) assert S._validate_attrs()
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()
def test_StoreIO_init__with_no_args(): """ StoreIO can be created without any input arguments, all pre-specified attrs exist and are None """ S = StoreIO() assert S._validate_attrs() assert isinstance(S, StoreIO) assert list(vars(S).keys()) == [ 'name', 'valid_attrs', 'valid_attrs_type', 'a', 'b', 'c', 'd' ] assert S.a is None assert S.b is None assert S.c is None assert S.d is None
def test_StoreIO_extra_kwargs__does_not_interfere_with_validate_attrs(): """ set_attrs_with_kwargs() accepts dict and updates attributes and can add non-valid if validate_kwargs = False """ S = StoreIO() assert S.a is None assert S.b is None assert S.c is None assert S.d is None abcde = namedtuple('e', ['a', 'b', 'c', 'd', 'e']) x = abcde(1, 2, 3, 4, 5.0) S.set_attrs_with_kwargs(**x._asdict(), validate_kwargs=False) assert S._validate_attrs() assert isinstance(S.a, int) assert isinstance(S.b, int) assert isinstance(S.c, int) assert isinstance(S.d, int) assert isinstance(S.e, float)
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()