def test_state_add(self): """ Tests add function of State. The add function has the same arguments as init function, so _state can also be initialized as follows: >>> _state = State(read=read, update=update, save=save) """ _state = State() _state.add(read=read, update=update, save=save) all_fields = [] all_fields.extend(save) all_fields.extend(update) all_fields.extend(read) all_fields = list(set(all_fields)) assert len(_state.fields) == len(all_fields) for field in _state.fields: if field.name in update: assert field.update if field.name in read: assert field.read if field.name in save: assert field.save assert not field.isdatafile
def test_init_exceptions(): _state = State() with pytest.raises(ValueError): _state.add(create='c_test', update='c_update', read='c_read') with pytest.raises(TypeError): _state.add(test=['test']) # 'test' is not a keyword with pytest.raises(AttributeError): # read and read/write props must be disjoint _state.add(update=['test'], read=['test']) s = State(update=['update'], read=['read'], create=['create']) with pytest.raises(AttributeError): # test is not a valid attribute of Field outside what get_names expects s.get_names('test') with pytest.raises(ValueError): _state.add(read=read, update=update, create=create) _state.add(create=['read']) # already exists
def test_init_exceptions(): state = State() with pytest.raises(ValueError): state.add(create="c_test", update="c_update", read="c_read") with pytest.raises(TypeError): state.add(test=["test"]) # 'test' is not a keyword with pytest.raises(AttributeError): # read and read/write props must be disjoint state.add(update=["test"], read=["test"]) s = State(update=["update"], read=["read"], create=["create"]) with pytest.raises(AttributeError): # test is not a valid attribute of Field outside what get_names expects s.get_names("test") with pytest.raises(ValueError): # no Field object with this name s.remove("xyz") with pytest.raises(ValueError): state.add(read=read, update=update, create=create) state.add(create=["read"]) # already exists
def test_init_exceptions(): _state = State() with pytest.raises(TypeError): _state.add(test=['test']) # 'test' is not a keyword with pytest.raises(AttributeError): # read and read/write props must be disjoint _state.add(update=['test'], read=['test']) s = State(update=['update'], read=['read'], save=['save']) with pytest.raises(AttributeError): # test is not a valid attribute of Field outside what get_names expects s.get_names('test') with pytest.raises(ValueError): _state.add(read=read, update=update, save=save) _state.add(save=['read']) # already exists
def test_init(save_, update_, read_): 'test various ways to initialize' _state = State() _state.add(save=save_, update=update_, read=read_) assert True