def test_state_property_modifications_history(caplog): ################## # state properties # TODO LibraryState test for properties like mentioned in the notification-test but also general for add and remove # change name # change parent # change states # change outcomes # change transitions # change input_data_ports # change output_data_ports # change scoped_variables # change data_flows # change script # change script_text # change description # change active # set_start_state # change start_state_id # change child_execution testing_utils.dummy_gui(None) testing_utils.initialize_environment(gui_config={ 'AUTO_BACKUP_ENABLED': False, 'HISTORY_ENABLED': True }, gui_already_started=False) sm_model, state_dict = create_state_machine_m() state1 = ExecutionState('State1', state_id="STATE1") state1.add_input_data_port("input", "str", "zero") state1.add_output_data_port("output", "int") state1.add_output_data_port("count", "int") state2 = ExecutionState('State2') state2.add_input_data_port("par", "int", 0) state2.add_input_data_port("number", "int", 5) state2.add_output_data_port("res", "int") nested_state = state_dict['Nested'] nested_state.add_state(state1) nested_state.add_state(state2) state2_path = state2.get_path() nested_state.add_output_data_port("res", "int") state1.add_outcome("again") state1.add_outcome("counted") assert len(sm_model.history.modifications) == 6 state2.add_outcome("done") state2.add_outcome("best") state2.add_outcome("full") assert len(sm_model.history.modifications) == 9 nested_state.add_outcome("great") assert len(sm_model.history.modifications) == 10 ####################################### ######## Properties of State ########## # name(self, name) _, nested_state = perform_history_action(nested_state.__setattr__, "name", "nested") # TODO: The following commented operations are not correctly supported by the history! # input_data_ports(self, input_data_ports) None or dict # _, nested_state = perform_history_action(nested_state.__setattr__, "input_data_ports", {}) # _, nested_state = perform_history_action(nested_state.__setattr__, "output_data_ports", {}) # outcomes(self, outcomes) None or dict # _, nested_state = perform_history_action(nested_state.__setattr__, "outcomes", nested_state.outcomes) # _, nested_state = perform_history_action(nested_state.__setattr__, "outcomes", {}) script_text = '\ndef execute(self, inputs, outputs, gvm):\n\tself.logger.debug("Hello World")\n\treturn 0\n' script_text1 = '\ndef execute(self, inputs, outputs, gvm):\n\tself.logger.debug("Hello NERD")\n\treturn 0\n' # script(self, script) Script -> no script setter any more only script_text !!! nested2_state = state_dict['Nested2'] _, nested2_state = perform_history_action(nested2_state.__setattr__, "script_text", script_text) # script_text(self, script_text) _, nested2_state = perform_history_action(nested2_state.__setattr__, "script_text", script_text1) # description(self, description) str _, nested_state = perform_history_action(nested_state.__setattr__, "description", "awesome") ############################################ ###### Properties of ContainerState ######## # set_start_state(self, state) State or state_id _, nested_state = perform_history_action(nested_state.set_start_state, "STATE1") # set_start_state(self, start_state) state2 = sm_model.state_machine.get_state_by_path(state2_path) _, nested_state = perform_history_action(nested_state.set_start_state, state2, additional_operations=1) # transitions(self, transitions) None or dict _, nested_state = perform_history_action(nested_state.__setattr__, "transitions", {}) # data_flows(self, data_flows) None or dict _, nested_state = perform_history_action(nested_state.__setattr__, "data_flows", {}) # scoped_variables(self, scoped_variables) None or dict _, nested_state = perform_history_action(nested_state.__setattr__, "scoped_variables", {}) # states(self, states) None or dict _, nested_state = perform_history_action(nested_state.__setattr__, "states", {}) testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def do_check_for_state(state_name): sm_history.modifications.reset() # Note: The elements always need to be retrieved before performing an operation, as undo/redo operations replace # both core and model objects state_m = get_state_model_by_name(state_name, state_path_dict) ############# # outcome add & remove outcome_super, state = perform_history_action( state_m.state.add_outcome, "super") state = get_state_by_name(state_name, state_path_dict) _, state = perform_history_action(state_m.state.remove_outcome, outcome_super) ############# # add two states state4 = ExecutionState('State4', state_id='STATE4') state_path_dict['state4'] = state.get_path() + "/" + "STATE4" _, state = perform_history_action(state.add_state, state4) state5 = ExecutionState('State5', state_id='STATE5') state_path_dict['state5'] = state.get_path() + "/" + "STATE5" _, state = perform_history_action(state.add_state, state5) perform_multiple_undo_redo(2) state4 = get_state_by_name('state4', state_path_dict) outcome_state4 = state4.add_outcome('UsedHere') assert len(sm_history.modifications) == 6 state5 = get_state_by_name('state5', state_path_dict) outcome_state5 = state5.add_outcome('UsedHere') assert len(sm_history.modifications) == 7 ################ # add transition from_state_id, from_outcome, to_state_id=None, to_outcome=None, transition_id new_transition_id1, state = perform_history_action( state.add_transition, from_state_id=state4.state_id, from_outcome=outcome_state4, to_state_id=state5.state_id, to_outcome=None) _, state = perform_history_action(state.add_transition, from_state_id=state5.state_id, from_outcome=outcome_state5, to_state_id=state.state_id, to_outcome=-1) ################### # remove transition _, state = perform_history_action(state.remove_transition, new_transition_id1) ############# # remove state _, state = perform_history_action(state.remove_state, state5.state_id) ############# # add input_data_port state4 = get_state_by_name('state4', state_path_dict) input_state4_id, state4 = perform_history_action( state4.add_input_data_port, "input", "str", "zero") ############# # remove input_data_port _, state4 = perform_history_action(state4.remove_input_data_port, input_state4_id) ############# # add output_data_port output_state4_id, state4 = perform_history_action( state4.add_output_data_port, "output_" + state4.state_id, "int") ############# # remove output_data_port _, state4 = perform_history_action(state4.remove_output_data_port, output_state4_id) # prepare again state4 state4.add_output_data_port("output", "int") state4.add_input_data_port("input_new", "str", "zero") assert len(sm_history.modifications) == 17 output_state4_id = state4.add_output_data_port("output_new", "int") assert len(sm_history.modifications) == 18 state5 = ExecutionState('State5', 'STATE5') state = get_state_by_name(state_name, state_path_dict) state.add_state(state5) assert state_path_dict['state5'] == state5.get_path() assert len(sm_history.modifications) == 19 input_par_state5 = state5.add_input_data_port("par", "int", 0) assert len(sm_history.modifications) == 20 output_res_state5 = state5.add_output_data_port("res", "int") assert len(sm_history.modifications) == 21 ##################### # add scoped_variable scoped_buffer_nested, state = perform_history_action( state.add_scoped_variable, "buffer", "int") ##################### # remove scoped_variable _, state = perform_history_action(state.remove_scoped_variable, scoped_buffer_nested) ############# # add data_flow new_df_id, state = perform_history_action( state.add_data_flow, from_state_id=state4.state_id, from_data_port_id=output_state4_id, to_state_id=state5.state_id, to_data_port_id=input_par_state5) ################ # remove data_flow perform_history_action(state.remove_data_flow, new_df_id)