def test_get_field_by_attribute(self): """ tests the fields can also be obtained by the attributes that are set to True. get_field_by_attribute function """ _state = State(read=read, update=update, save=save) _state.add_field(Field('test', isdatafile=True)) for field in _state.get_field_by_attribute('read'): assert field.name in read for field in _state.get_field_by_attribute('update'): assert field.name in update for field in _state.get_field_by_attribute('save'): assert field.name in save for field in _state.get_field_by_attribute('isdatafile'): assert field.name in ['test']
def test_get_field_by_attribute(): """ tests the fields can also be obtained by the attributes that are set to True. get_field_by_attribute function """ state = State(read=read, update=update, create=create) state.add_field(Field("test", isdatafile=True)) for field in state.get_field_by_attribute("read"): assert field.name in read for field in state.get_field_by_attribute("update"): assert field.name in update for field in state.get_field_by_attribute("create"): assert field.name in create for field in state.get_field_by_attribute("isdatafile"): assert field.name in ["test"]
def test_state_add_field(): """ Tests the add_field functionality to add a field to state object. This can also be a list of field objects. """ state = State() state.add_field(Field("test")) assert len(state.fields) == 1 f = [] f.append(Field("filename", create=True, isdatafile=True)) f.append(Field("topology_file", create=True, isdatafile=True)) state.add_field(f) assert len(state.fields) == 3 for field in state.fields: assert field.name in ["test", "filename", "topology_file"] if field.name == "filename" or field.name == "topology_file": assert field.isdatafile assert field.create assert not field.update assert not field.read else: assert not field.isdatafile assert not field.create assert not field.update assert not field.read with pytest.raises(ValueError): state.add_field(Field("test")) with pytest.raises(ValueError): state.add_field([Field("test1"), Field("test1")])