def gui(request, caplog): parameters = {} if not hasattr(request, "param") else request.param with_gui = parameters.get("with_gui", True) config = { parameter_name: parameters.get(parameter_name) for parameter_name in ["core_config", "gui_config", "runtime_config", "libraries"] } utils.dummy_gui(caplog) if with_gui: utils.run_gui(**deepcopy(config)) else: utils.initialize_environment(gui_already_started=False, **deepcopy(config)) gui_tester = GUITester(with_gui, config) yield gui_tester try: if with_gui: utils.close_gui() finally: utils.shutdown_environment( caplog=caplog, unpatch_threading=with_gui, expected_warnings=gui_tester.expected_warnings, expected_errors=gui_tester.expected_errors) gui_tester.post_test and gui_tester.post_test()
def test_simple(caplog): """Do all copy strategies possible in RAFCON and check if all Objects have different memory location to secure reference free assignments from origin to new state. :param caplog: :return: """ testing_utils.dummy_gui(None) print("start test simple") # create testbed testing_utils.initialize_environment( gui_already_started=False, gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, ) [state, sm_model, state_dict] = create_models() run_copy_test(sm_model) run_copy_performance_test_and_check_storage_copy(sm_model) # currently destroy doesn't do anything if auto_backup is disabled sm_model.destroy() import rafcon rafcon.core.singleton.state_machine_manager.delete_all_state_machines() [state, sm_model, state_dict] = create_models_concurrency() run_copy_test(sm_model) run_copy_performance_test_and_check_storage_copy(sm_model) # currently destroy doesn't do anything if auto_backup is disabled sm_model.destroy() rafcon.core.singleton.state_machine_manager.delete_all_state_machines() # wait until state machine model is destroyed testing_utils.wait_for_gui() testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False) print("test simple finished")
def test_simple_undo_redo(caplog): testing_utils.dummy_gui(None) testing_utils.initialize_environment(gui_config={ 'AUTO_BACKUP_ENABLED': False, 'HISTORY_ENABLED': True }, gui_already_started=False) state_machine_m, state_dict = create_state_machine_m() state1 = ExecutionState('state1', state_id='STATE1') state2 = ExecutionState('state2', state_id='STATE2') state3 = ExecutionState('state2', state_id='STATE2') state4 = ExecutionState('state2', state_id='STATE2') state_machine_m.root_state.state.add_state(state1) state_machine_m.root_state.state.add_state(state2) state_machine_m.root_state.state.add_state(state3) state_machine_m.root_state.state.add_state(state4) assert len(state_machine_m.history.modifications) == 5 perform_multiple_undo(2) perform_multiple_redo(1) perform_multiple_redo(1) assert len(state_machine_m.history.modifications) == 5 testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False, expected_errors=0)
def test_on_clean_storing_with_name_in_path(caplog): testing_utils.dummy_gui(None) testing_utils.initialize_environment(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, gui_already_started=False) path_old_format = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "id_to_name_plus_id_storage_format_test_do_not_update")) path_new_format = os.path.join( testing_utils.get_unique_temp_path(), "id_to_name_plus_id_storage_format_test_do_not_update") # gui imports better after initialization from rafcon.gui.models.state_machine import StateMachineModel shutil.copytree(path_old_format, path_new_format) from rafcon.core.storage import storage sm = storage.load_state_machine_from_path(path_new_format) check_state_recursively_if_state_scripts_are_valid(sm.root_state) sm.base_path = path_new_format sm_m = StateMachineModel(sm) try: on_save_activate(sm_m, logger) check_that_all_files_are_there(sm, with_print=False) check_id_and_name_plus_id_format(path_old_format, path_new_format, sm_m) finally: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_outcome_property_modifications_history(caplog): ################## # outcome properties # change name 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() #################################################### # modify outcome and generate in previous a observer for state_name in ["Nested", "Nested2"]: state_path = state_dict[state_name].get_path() outcome_ids = list(state_dict[state_name].outcomes.keys()) for outcome_id in outcome_ids: state = sm_model.state_machine.get_state_by_path(state_path) if outcome_id >= 0: outcome = state.outcomes[outcome_id] _, _ = perform_history_action(outcome.__setattr__, "name", "new_name_" + str(outcome_id)) testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_storage_with_gui(with_gui, caplog): print("test storage with gui", with_gui) testing_utils.dummy_gui(None) if with_gui: testing_utils.run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }) else: testing_utils.initialize_environment(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, gui_already_started=False) e = None try: save_state_machine(with_gui) except Exception as e: pass finally: if with_gui: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog) else: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False) if e: raise e print("test storage with gui {0} finished".format(with_gui))
def test_unchanged_storage_format(caplog): """This test ensures that the state machine storage format does not change in patch releases""" from rafcon.core.storage import storage from rafcon.gui.models.state_machine import StateMachineModel import rafcon path = get_backward_compatibility_state_machines_path() if not os.path.exists(path): logger.info( "test_unchanged_storage_format: the current python interpreter version is not supported" ) return testing_utils.initialize_environment( gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ 'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines") }, gui_already_started=False) try: current_rafcon_version = StrictVersion(rafcon.__version__).version current_minor = "{}.{}".format(current_rafcon_version[0], current_rafcon_version[1]) for filename in os.listdir(path): if filename.startswith(current_minor): old_state_machine_path = os.path.join(path, filename) break else: assert False, "There is no state machine for the current RAFCON minor version {}".format( current_minor) state_machine = storage.load_state_machine_from_path( old_state_machine_path) state_machine_m = StateMachineModel(state_machine) new_state_machine_path = testing_utils.get_unique_temp_path() storage.save_state_machine_to_path(state_machine, new_state_machine_path, True, True) state_machine_m.store_meta_data(copy_path=new_state_machine_path) old_state_machine_hash = calculate_state_machine_hash( old_state_machine_path) new_state_machine_hash = calculate_state_machine_hash( new_state_machine_path) assert old_state_machine_hash.digest( ) == new_state_machine_hash.digest() except Exception: raise finally: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_output_port_modify(caplog): ################## # output_data_port properties # change name # change data_type # change default_value # change datatype # create testbed 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() nested_state = state_dict['Nested2'] new_output_data_port_id, nested_state = perform_history_action( nested_state.add_output_data_port, name='new_output', data_type='str') ################################ # check for modification of name _, nested_state = perform_history_action( nested_state.output_data_ports[new_output_data_port_id].__setattr__, "name", "changed_new_output_name") ##################################### # check for modification of data_type _, nested_state = perform_history_action( nested_state.output_data_ports[new_output_data_port_id].__setattr__, "data_type", "int") ######################################### # check for modification of default_value _, nested_state = perform_history_action( nested_state.output_data_ports[new_output_data_port_id].__setattr__, "default_value", 5) ########################################### # check for modification of change_datatype _, nested_state = perform_history_action( nested_state.output_data_ports[new_output_data_port_id]. change_data_type, data_type='str', default_value='awesome_tool') testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_relocate_library(caplog): testing_utils.initialize_environment(gui_already_started=False, libraries={ "tutorials": testing_utils.TUTORIAL_PATH, }) try: from rafcon.gui.helpers.state_machine import relocate_library assert os.path.exists(LIBRARY_OS_PATH) assert not os.path.exists(NEW_LIBRARY_OS_PATH) state_machine = storage.load_state_machine_from_path( STATE_MACHINE_OS_PATH) library = list(state_machine.root_state.states.values())[0] assert library.library_path == LIBRARY_PATH assert library.library_name == LIBRARY_NAME relocate_library(LIBRARY_OS_PATH, LIBRARY_PATH, LIBRARY_NAME, NEW_DIRECTORY) assert not os.path.exists(LIBRARY_OS_PATH) assert os.path.exists(NEW_LIBRARY_OS_PATH) state_machine = storage.load_state_machine_from_path( STATE_MACHINE_OS_PATH) library = list(state_machine.root_state.states.values())[0] assert library.library_path == NEW_LIBRARY_PATH assert library.library_name == LIBRARY_NAME relocate_library(NEW_LIBRARY_OS_PATH, NEW_LIBRARY_PATH, LIBRARY_NAME, testing_utils.TUTORIAL_PATH) assert os.path.exists(LIBRARY_OS_PATH) assert not os.path.exists(NEW_LIBRARY_OS_PATH) state_machine = storage.load_state_machine_from_path( STATE_MACHINE_OS_PATH) library = list(state_machine.root_state.states.values())[0] assert library.library_path == LIBRARY_PATH assert library.library_name == LIBRARY_NAME finally: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_resave(caplog): testing_utils.initialize_environment(gui_already_started=False) folder_to_convert = testing_utils.TUTORIAL_PATH target_folder = os.path.join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE, "resave_test") config_path = os.path.join(testing_utils.TESTS_PATH, "assets", "configs", "valid_config") gui_config_path = testing_utils.RAFCON_TEMP_PATH_CONFIGS print("folder to convert: " + folder_to_convert) print("config path: " + config_path) import rafcon.gui.resave_state_machines as resave resave.convert_libraries_in_path(config_path, folder_to_convert, target_folder, gui_config_path) testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_rename_library_root(caplog): testing_utils.initialize_environment(gui_already_started=False, libraries={}) try: from rafcon.gui.helpers.state_machine import rename_library_root from rafcon.gui.singleton import global_config state_machine_path = os.path.abspath( os.path.join(testing_utils.TEST_STATE_MACHINES_PATH, STATE_MACHINE_NAME)) rename_library_root(CURRENT_LIBRARY_ROOT_NAME, NEW_LIBRARY_ROOT_NAME) library_manager.clean_loaded_libraries() library_manager.refresh_libraries() testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False) testing_utils.initialize_environment( gui_already_started=False, libraries={"new_generic": testing_utils.GENERIC_PATH}) library = storage.load_state_machine_from_path(state_machine_path) assert library is not None library_paths = global_config.get_config_value('LIBRARY_PATHS') del library_paths[CURRENT_LIBRARY_ROOT_NAME] global_config.save_configuration() rename_library_root(NEW_LIBRARY_ROOT_NAME, CURRENT_LIBRARY_ROOT_NAME) library_manager.clean_loaded_libraries() library_manager.refresh_libraries() library = storage.load_state_machine_from_path(state_machine_path) assert library is not None finally: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_rename_library_missing_states(caplog): testing_utils.initialize_environment(gui_already_started=False, libraries={ "tutorials": testing_utils.TUTORIAL_PATH, "ros": testing_utils.ROS_PATH, "turtle_libraries": testing_utils.TURTLE_PATH, }) try: from rafcon.gui.helpers.state_machine import rename_library current_library_path = os.path.abspath( os.path.join(testing_utils.DEEP_LIBRARIES_PATH, CURRENT_LIBRARY_NAME2)) new_library_path = os.path.abspath( os.path.join(testing_utils.DEEP_LIBRARIES_PATH, NEW_LIBRARY_NAME2)) state_machine_path = os.path.abspath( os.path.join(testing_utils.DEEP_LIBRARIES_PATH, STATE_MACHINE_NAME2)) library = storage.load_state_machine_from_path(current_library_path) assert library.file_system_path == current_library_path state_machine = storage.load_state_machine_from_path( state_machine_path) assert CURRENT_LIBRARY_NAME2 in [ state.name for state in state_machine.root_state.states.values() ] rename_library(current_library_path, new_library_path, 'unit_test_state_machines/deep_libraries', CURRENT_LIBRARY_NAME2, NEW_LIBRARY_NAME2) library = storage.load_state_machine_from_path(new_library_path) assert library.file_system_path == new_library_path assert library.root_state.name == NEW_LIBRARY_NAME2 state_machine = storage.load_state_machine_from_path( state_machine_path) assert NEW_LIBRARY_NAME2 in [ state.name for state in state_machine.root_state.states.values() ] rename_library(new_library_path, current_library_path, 'unit_test_state_machines/deep_libraries', NEW_LIBRARY_NAME2, CURRENT_LIBRARY_NAME2) library = storage.load_state_machine_from_path(current_library_path) assert library.file_system_path == current_library_path assert library.root_state.name == CURRENT_LIBRARY_NAME2 state_machine = storage.load_state_machine_from_path( state_machine_path) assert CURRENT_LIBRARY_NAME2 in [ state.name for state in state_machine.root_state.states.values() ] finally: testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_complex(caplog): """Do all copy strategies possible in RAFCON and check if all Objects have different memory location to secure reference free assignments from origin to new state. :param caplog: :return: """ testing_utils.dummy_gui(None) with_gui = True if with_gui: print("test_complex with gui") try: testing_utils.run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ "unit_test_state_machines": os.path.join( testing_utils.TEST_ASSETS_PATH, "unit_test_state_machines") }) output_list = list() testing_utils.call_gui_callback(create_models_lib, output_list) sm_model = output_list[0] testing_utils.call_gui_callback(run_copy_test, sm_model, with_gui=True) testing_utils.call_gui_callback( run_copy_performance_test_and_check_storage_copy, sm_model) except: raise finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog) print("finish test_complex with gui") # import threading # print "&" * 50 # print "end of copy method" # print threading.currentThread().ident # print threading.currentThread() # print "&" * 50 else: print("test_complex without gui") testing_utils.initialize_environment( gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ "unit_test_state_machines": os.path.join(testing_utils.TEST_ASSETS_PATH, "unit_test_state_machines") }, gui_already_started=False) output_list = list() create_models_lib(output_list) sm_model = output_list[0] run_copy_test(sm_model) run_copy_performance_test_and_check_storage_copy(sm_model) sm_model.destroy() import rafcon.core.singleton rafcon.core.singleton.state_machine_manager.delete_all_state_machines() testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False) print("after test_complex without gui")
if __name__ == '__main__': # this snippet shows how to run a unit test without pytest from tests import utils from copy import deepcopy from tests.gui.conftest import GUITester parameters = {} with_gui = parameters.get("with_gui", True) config = {parameter_name: parameters.get(parameter_name) for parameter_name in ["core_config", "gui_config", "runtime_config", "libraries"]} utils.dummy_gui(None) if with_gui: utils.run_gui(**deepcopy(config)) else: utils.initialize_environment(gui_already_started=False, **deepcopy(config)) gui_tester = GUITester(with_gui, config) test_dynamic_state_insertion(gui_tester, "dynamic_library_insertion_and_deletion", 0) try: if with_gui: utils.close_gui() finally: utils.shutdown_environment(caplog=None, unpatch_threading=with_gui, expected_warnings=gui_tester.expected_warnings, expected_errors=gui_tester.expected_errors) gui_tester.post_test and gui_tester.post_test()
def test_add_remove_history(caplog): testing_utils.dummy_gui(None) ################## # Root_state elements # add state # - change state # remove state # add outcome # - change outcome # remove outcome # add transition # - change transition # remove transition # add input_data_port # - change input_data_port # remove input_data_port # add output_data_port # - change output_data_port # remove output_data_port # add scoped_variable # - change scoped_variable # remove scoped_variable # add data_flow # - change data_flow # remove data_flow testing_utils.dummy_gui(None) testing_utils.initialize_environment(gui_config={ 'AUTO_BACKUP_ENABLED': False, 'HISTORY_ENABLED': True }, gui_already_started=False) state_machine_m, state_dict = create_state_machine_m() state_machine_path = TEST_PATH + '_test_add_remove' save_state_machine(state_machine_m, state_machine_path + '_before', logger, with_gui=False, menubar_ctrl=None) sm_history = state_machine_m.history state1 = HierarchyState('state1', state_id='STATE1') state2 = ExecutionState('state2', state_id='STATE2') state_dict['Nested'].add_state(state1) state_dict['Nested'].add_state(state2) state_dict['state1'] = state1 state_dict['state2'] = state2 state_path_dict = {} for key in state_dict: state_path_dict[key] = state_dict[key].get_path() 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) do_check_for_state(state_name='Nested') do_check_for_state(state_name='Container') testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
def test_data_flow_property_modifications(caplog): ################## # data_flow properties # change modify_origin # change from_key # change modify_target # change to_key # modify_transition_from_state # modify_transition_from_key # modify_transition_to_key # modify_transition_to_state 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() nested_state = state_dict['Nested'] state1 = ExecutionState('State1') output_state1 = state1.add_output_data_port("output", "int") state1.add_input_data_port("input", "str", "zero") state2 = ExecutionState('State2') input_par_state2 = state2.add_input_data_port("par", "int", 0) output_res_state2 = state2.add_output_data_port("res", "int") nested_state.add_state(state1) nested_state.add_state(state2) output_res_nested = nested_state.add_output_data_port("res", "int") output_count_state1 = state1.add_output_data_port("count", "int") input_number_state2 = state2.add_input_data_port("number", "int", 5) new_df_id, nested_state = perform_history_action( nested_state.add_data_flow, from_state_id=state2.state_id, from_data_port_id=output_res_state2, to_state_id=nested_state.state_id, to_data_port_id=output_res_nested) ##### modify from data_flow ####### # modify_origin(self, from_state, from_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].modify_origin, from_state=state1.state_id, from_key=output_state1) # from_key(self, from_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].__setattr__, "from_key", output_count_state1) # modify_target(self, to_state, to_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].modify_target, to_state=state2.state_id, to_key=input_par_state2) # to_key(self, to_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].__setattr__, "to_key", input_number_state2) # reset observer and testbed _, nested_state = perform_history_action(nested_state.remove_data_flow, new_df_id) new_df_id, nested_state = perform_history_action( nested_state.add_data_flow, from_state_id=state2.state_id, from_data_port_id=output_res_state2, to_state_id=nested_state.state_id, to_data_port_id=output_res_nested) ##### modify from parent state ####### _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].modify_origin, state1.state_id, output_state1) # modify_data_flow_from_key(self, data_flow_id, from_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].__setattr__, "from_key", output_count_state1) # modify_data_flow_to_state(self, data_flow_id, to_state, to_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].modify_target, state2.state_id, input_par_state2) # modify_data_flow_to_key(self, data_flow_id, to_key) _, nested_state = perform_history_action( nested_state.data_flows[new_df_id].__setattr__, "to_key", input_number_state2) testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
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 test_transition_property_modifications_history(caplog): ################## # transition properties # change modify_origin # change from_outcome # change to_state # change to_outcome # modify_transition_from_state # modify_transition_from_outcome # modify_transition_to_outcome # modify_transition_to_state 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') outcome_again_state1 = state1.add_outcome("again") state2 = ExecutionState('State2') oc_done_state2 = state2.add_outcome("done") state2.add_outcome("best") nested_state = state_dict['Nested'] nested_state.add_state(state1) nested_state.add_state(state2) nested_state.add_outcome("great") state1.add_outcome("counted") oc_full_state2 = state2.add_outcome("full") new_trans_id, nested_state = perform_history_action( nested_state.add_transition, from_state_id=state1.state_id, from_outcome=outcome_again_state1, to_state_id=state1.state_id, to_outcome=None) # modify_origin(self, from_state, from_outcome) _, nested_state = perform_history_action( nested_state.transitions[new_trans_id].modify_origin, from_state=state2.state_id, from_outcome=oc_full_state2) # from_outcome(self, from_outcome) _, nested_state = perform_history_action( nested_state.transitions[new_trans_id].__setattr__, "from_outcome", oc_done_state2) # to_state(self, to_state) _, nested_state = perform_history_action( nested_state.transitions[new_trans_id].__setattr__, "to_state", state2.state_id) # reset observer and testbed _, nested_state = perform_history_action(nested_state.remove_transition, new_trans_id) new_df_id, nested_state = perform_history_action( nested_state.add_transition, from_state_id=state1.state_id, from_outcome=outcome_again_state1, to_state_id=state1.state_id, to_outcome=None) _, nested_state = perform_history_action( nested_state.transitions[new_df_id].modify_origin, state2.state_id, oc_full_state2) # modify_transition_from_outcome(self, transition_id, from_outcome) _, nested_state = perform_history_action( nested_state.transitions[new_df_id].__setattr__, "from_outcome", oc_done_state2) # modify_transition_to_state(self, transition_id, to_state, to_outcome) _, nested_state = perform_history_action( nested_state.transitions[new_df_id].__setattr__, "to_state", state1.state_id) testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)