async def test_validate_doc_allow_update_kv_dict_typed_dict_time_dict_dot_notated(): attrs = { 'shift': ATTR.KV_DICT( key=ATTR.STR(pattern=r'[0-9]{2}'), val=ATTR.TYPED_DICT(dict={'start': ATTR.TIME(), 'end': ATTR.TIME()}), ) } doc = {'shift.01.start': '09:00'} await utils.validate_doc(doc=doc, attrs=attrs, mode='update') assert doc == {'shift.01.start': '09:00'}
async def test_validate_attr_TIME_None_allow_none(): attr_val = await validate_attr( attr_name='test_validate_attr_TIME', attr_type=ATTR.TIME(), attr_val=None, mode='update', ) assert attr_val == None
async def test_validate_attr_TIME_None(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_TIME', attr_type=ATTR.TIME(), attr_val=None, mode='create', )
async def test_validate_attr_TIME_datetime_iso(): attr_val = await validate_attr( attr_name='test_validate_attr_TIME', attr_type=ATTR.TIME(), attr_val='00:00:00.000000', mode='create', ) assert attr_val == '00:00:00.000000'
async def test_validate_attr_TIME_default_int(): attr_type = ATTR.TIME() attr_type._default = 'test_validate_attr_TIME' attr_val = await validate_attr( attr_name='test_validate_attr_TIME', attr_type=attr_type, attr_val=1, mode='create', ) assert attr_val == 'test_validate_attr_TIME'
def test_generate_attr_TIME_ranges_dynamic_start_end_negative(): attr_val = utils.generate_attr(attr_type=ATTR.TIME( ranges=[['-2h', '+5h']])) assert attr_val.split('.')[0] == ( datetime.datetime.utcnow() + datetime.timedelta(hours=-2)).isoformat().split('T')[1].split('.')[0]
def test_generate_attr_TIME_ranges_datetime_start(): attr_val = utils.generate_attr(attr_type=ATTR.TIME( ranges=[['18:00:00', '+2h']])) assert attr_val == '18:00:00'
def test_generate_attr_TIME_ranges_datetime_end(): attr_val = utils.generate_attr(attr_type=ATTR.TIME( ranges=[['+1h', '22:00:00']])) assert attr_val == '21:59:00'
def test_generate_attr_TIME_no_args(): attr_val = utils.generate_attr(attr_type=ATTR.TIME()) assert attr_val.split('.')[0] == datetime.datetime.utcnow().isoformat( ).split('T')[1].split('.')[0]