async def test_validate_attr_FLOAT_range_float_as_str(): attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(ranges=[[0.5, 9.5]]), attr_val='0.5', mode='create', ) assert attr_val == 0.5
async def test_validate_attr_FLOAT_None(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(), attr_val=None, mode='create', )
async def test_validate_attr_FLOAT_range_float_invalid(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(ranges=[[0.5, 9.5]]), attr_val=9.5, mode='create', )
async def test_validate_attr_FLOAT_int_as_str(): attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(), attr_val='1', mode='create', ) assert attr_val == 1
async def test_validate_attr_FLOAT_float(): attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(), attr_val=1.1, mode='create', ) assert attr_val == 1.1
async def test_validate_attr_FLOAT_None_allow_none(): attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=ATTR.FLOAT(), attr_val=None, mode='update', ) assert attr_val == None
def test_generate_attr_UNION(): attr_val1 = utils.generate_attr(attr_type=ATTR.UNION( union=[ATTR.STR(), ATTR.INT()])) attr_val2 = utils.generate_attr(attr_type=ATTR.UNION(union=[ ATTR.LIST(list=[ATTR.STR()], min=1), ATTR.TYPED_DICT(dict={'foo': ATTR.FLOAT()}) ])) assert type(attr_val1) in [str, int] assert (type(attr_val2) == list and type(attr_val2[0]) == str) or ( type(attr_val2) == dict and type(attr_val2['foo']) == float)
async def test_validate_attr_FLOAT_default_int_allow_none(): attr_type = ATTR.FLOAT() attr_type._default = 'test_validate_attr_FLOAT' attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=attr_type, attr_val='str', mode='update', ) assert attr_val == None
async def test_validate_attr_FLOAT_default_str(): attr_type = ATTR.FLOAT() attr_type._default = 'test_validate_attr_FLOAT' attr_val = await validate_attr( attr_name='test_validate_attr_FLOAT', attr_type=attr_type, attr_val='str', mode='create', ) assert attr_val == 'test_validate_attr_FLOAT'
def test_generate_attr_FLOAT_ranges(): attr_val = utils.generate_attr(attr_type=ATTR.FLOAT(ranges=[[0.5, 10.3]])) assert type(attr_val) == float assert attr_val >= 0 and attr_val < 10
def test_generate_attr_FLOAT_no_args(): attr_val = utils.generate_attr(attr_type=ATTR.FLOAT()) assert type(attr_val) == float