def test_backward_compatibility_storage(caplog): """This test ensures that old state machines storage formats can still be opened with the current RAFCON version""" path = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "backward_compatibility")) run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ 'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines") }) try: run_backward_compatibility_state_machines(path) except Exception: raise finally: # two warning per minor version lower than the current RAFCON version state_machines = len([ filename for filename in os.listdir(path) if os.path.isdir(os.path.join(path, filename)) ]) testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0)
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 = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "backward_compatibility")) 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_start_script_valid_rmpm_env(): """Tests the execution of rafcon_start in an environment created by RMPM """ # TODO: replace rafcon_start with rafcon_core after the next release testing_utils.dummy_gui(None) import distutils.spawn rmpm_env = os.environ.copy() rmpm_env[ "PATH"] = "/volume/software/common/packages/rmpm/latest/bin/{}:".format( os.getenv("DLRRM_HOST_PLATFORM", "osl42-x86_64")) + rmpm_env["PATH"] if not distutils.spawn.find_executable("rmpm_do"): print "Could not find rmpm_do, skipping test" start_path = testing_utils.get_test_sm_path( join("unit_test_state_machines", "start_script_test")) config = join(testing_utils.TESTS_PATH, "assets", "configs", "valid_config", "config.yaml") cmd = "eval `rmpm_do env --env-format=embed_sh sw.common.rafcon` && rafcon_start -o {0} -c {1}" \ "".format(start_path, config) print "\ntest_start_script_valid_config: \n", cmd rafcon_process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, env=rmpm_env) rafcon_process.wait() output = rafcon_process.communicate()[0] print "LOG: \n", output assert rafcon_process.returncode == 0
def test_run_to_selected_state(caplog): testing_utils.initialize_environment_core() sm_path = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "run_to_selected_state_test")) sm = storage.load_state_machine_from_path(sm_path) # select state machine for this purpose rafcon.core.singleton.state_machine_manager.add_state_machine(sm) rafcon.core.singleton.state_machine_manager.active_state_machine_id = sm.state_machine_id rafcon.core.singleton.state_machine_execution_engine.run_to_selected_state( "VVBPOY/AOZXRY", sm.state_machine_id) # run the statemachine to the state before AOYXRY, this is an asynchronous task timeout = time.time() while not sm.get_state_by_path( "VVBPOY/ABNQFK" ).state_execution_status is StateExecutionStatus.WAIT_FOR_NEXT_STATE: time.sleep(.05) if time.time() - timeout > 2: raise RuntimeError( "execution_state ABNQFK not reached --> timeout") # wait until the statemachine is executed until ABNQFK the state before AOZXRY, so it doesnt check for the file # before its even written with open(os.path.join(RAFCON_TEMP_PATH_BASE, 'test_file'), 'r') as test_file: lines = test_file.readlines() # the state machines waits at ABNQFK with state WAIT_FOR_NEXT_STATE, so it needs to be stopped manually rafcon.core.singleton.state_machine_execution_engine.stop() rafcon.core.singleton.state_machine_execution_engine.join() try: assert len(lines) < 3 finally: testing_utils.shutdown_environment_only_core(caplog=caplog)
def test_drag_and_drop_test(caplog): testing_utils.run_gui( gui_config={ 'AUTO_BACKUP_ENABLED': False, 'HISTORY_ENABLED': False }, runtime_config={ 'MAIN_WINDOW_MAXIMIZED': False, 'MAIN_WINDOW_SIZE': (1500, 800), 'MAIN_WINDOW_POS': (0, 0), 'LEFT_BAR_WINDOW_UNDOCKED': False, 'RIGHT_BAR_WINDOW_UNDOCKED': False, 'CONSOLE_WINDOW_UNDOCKED': False, 'LEFT_BAR_HIDDEN': True, 'RIGHT_BAR_HIDDEN': True, 'CONSOLE_HIDDEN': True, }, libraries={ "unit_test_state_machines": testing_utils.get_test_sm_path("unit_test_state_machines") }) import rafcon.core.singleton call_gui_callback(create_models) try: trigger_drag_and_drop_tests( rafcon.gui.singleton.state_machine_manager_model, rafcon.gui.singleton.main_window_controller) finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog, expected_warnings=1, expected_errors=0)
def test_on_clean_storing_with_name_in_path(caplog): print("test_on_clean_storing_with_name_in_path") 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 get_backward_compatibility_state_machines_path(): python_version = "python" + str(sys.version_info.major) + "." + str( sys.version_info.minor) path = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "backward_compatibility", python_version)) return path
def test_preemption_behaviour_during_stop(caplog): testing_utils.initialize_environment_core() path = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "preemption_behaviour_during_stop")) state_machine = storage.load_state_machine_from_path(path) rafcon.core.singleton.state_machine_manager.add_state_machine( state_machine) thread = threading.Thread( target=trigger_stop, args=[ state_machine, rafcon.core.singleton.state_machine_execution_engine ]) thread.start() rafcon.core.singleton.state_machine_execution_engine.start( state_machine.state_machine_id) rafcon.core.singleton.state_machine_execution_engine.join() rafcon.core.singleton.state_machine_manager.remove_state_machine( state_machine.state_machine_id) try: assert global_variable_manager.get_variable("s1") == 1 assert global_variable_manager.get_variable("s2") == 1 assert not global_variable_manager.variable_exist("s3") finally: testing_utils.shutdown_environment_only_core(caplog=caplog)
def test_library_relocation(caplog): testing_utils.initialize_environment_core( libraries={"test_scripts": testing_utils.TEST_ASSETS_PATH}) interface.open_folder_func = open_folder interface.show_notice_func = show_notice state_machine = storage.load_state_machine_from_path( testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "library_relocation_test"))) rafcon.core.singleton.state_machine_manager.add_state_machine( state_machine) rafcon.core.singleton.state_machine_manager.active_state_machine_id = state_machine.state_machine_id rafcon.core.singleton.state_machine_execution_engine.start() rafcon.core.singleton.state_machine_execution_engine.join() rafcon.core.singleton.state_machine_execution_engine.stop() try: assert state_machine.root_state.output_data["output_0"] == 27 finally: testing_utils.shutdown_environment_only_core(caplog=caplog, expected_warnings=0, expected_errors=1) logger.info("State machine execution finished!")
def test_backward_compatibility_storage(caplog): """This test ensures that old state machines storage formats can still be opened with the current RAFCON version""" path = get_backward_compatibility_state_machines_path() if not os.path.exists(path): logger.info( "test_backward_compatibility_storage: the current python interpreter version is not supported" ) return run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ 'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines") }) try: logger.info("Run backward compatibility state machine for own version") run_backward_compatibility_state_machines(path) logger.info( "Run backward compatibility state machine for other versions") all_versions_path = testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "backward_compatibility")) for python_version_folder in os.listdir(all_versions_path): full_python_version_path = os.path.join(all_versions_path, python_version_folder) if os.path.isdir(full_python_version_path): if full_python_version_path == path: pass else: run_backward_compatibility_state_machines( full_python_version_path) except Exception: raise finally: # two warning per minor version lower than the current RAFCON version state_machines = len([ filename for filename in os.listdir(path) if os.path.isdir(os.path.join(path, filename)) ]) testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0)
def open_folder(query): if "library2_for_relocation_test" in query: return None # the first relocation has to be aborted else: return testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "library_relocation_test_source", "library1_for_relocation_test_relocated"))
def test_custom_entry_point(caplog): testing_utils.initialize_environment_core() state_machine = storage.load_state_machine_from_path( testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "stepping_test"))) rafcon.core.singleton.state_machine_manager.add_state_machine( state_machine) rafcon.core.singleton.state_machine_manager.active_state_machine_id = state_machine.state_machine_id rafcon.core.singleton.state_machine_execution_engine.step_mode() time.sleep(0.2) # let the state machine start properly # sm structure # GLSUJY # GLSUJY/PXTKIH # GLSUJY/NDIVLD # GLSUJY/SFZGMH # GLSUJY/SMCOIB # GLSUJY/SMCOIB/YSBJGK # GLSUJY/SMCOIB/OUWQUJ # GLSUJY/SMCOIB/UGGFFI rafcon.core.singleton.state_machine_execution_engine.step_over() wait_and_join(state_machine, "GLSUJY/PXTKIH") rafcon.core.singleton.state_machine_execution_engine.step_over() wait_and_join(state_machine, "GLSUJY/NDIVLD") rafcon.core.singleton.state_machine_execution_engine.step_over() wait_and_join(state_machine, "GLSUJY/SFZGMH") rafcon.core.singleton.state_machine_execution_engine.step_over() wait_and_join(state_machine, "GLSUJY/SMCOIB") rafcon.core.singleton.state_machine_execution_engine.step_into() wait_and_join(state_machine, "GLSUJY/PXTKIH") rafcon.core.singleton.state_machine_execution_engine.step_into() wait_and_join(state_machine, "GLSUJY/NDIVLD") rafcon.core.singleton.state_machine_execution_engine.step_into() wait_and_join(state_machine, "GLSUJY/SFZGMH") rafcon.core.singleton.state_machine_execution_engine.step_into( ) # step into hierarchy state GLSUJY/SMCOIB rafcon.core.singleton.state_machine_execution_engine.step_into() wait_and_join(state_machine, "GLSUJY/SMCOIB/YSBJGK") rafcon.core.singleton.state_machine_execution_engine.step_out() wait_and_join(state_machine, "GLSUJY/SMCOIB") rafcon.core.singleton.state_machine_execution_engine.stop() rafcon.core.singleton.state_machine_execution_engine.join() try: assert rafcon.core.singleton.global_variable_manager.get_variable( "bottles") == 95 finally: testing_utils.shutdown_environment_only_core(caplog=caplog)
def setup_class(cls): # This methods runs on class creation and creates the state machine testing_utils.test_multithreading_lock.acquire() state_machine = global_storage.load_state_machine_from_path( testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "action_block_execution_test"))) cls.state_machine = state_machine state_machine_manager.add_state_machine(state_machine)
def test_plugins_example(caplog): os.environ['RAFCON_PLUGIN_PATH'] = os.path.join( testing_utils.EXAMPLES_PATH, 'plugins', 'templates') print os.environ.get('RAFCON_PLUGIN_PATH') path_of_sm_to_run = testing_utils.get_test_sm_path( join("unit_test_state_machines", "99_bottles_of_beer_monitoring")) # testing_utils.initialize_environment() testing_utils.test_multithreading_lock.acquire() try: cmd = join(testing_utils.RAFCON_PATH, 'gui', 'start.py') + ' -o ' + path_of_sm_to_run + " -ss" start_time = time.time() rafcon_gui_process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # See https://stackoverflow.com/a/36477512 for details # Note: This (select and poll) only works on POSIX systems, not on Windows! poller = select.poll() poller.register(rafcon_gui_process.stdout, select.POLLIN) plugin_loaded = False while True: if poller.poll(0.1): line = rafcon_gui_process.stdout.readline().rstrip() print "process:", line if "Successfully loaded plugin 'templates'" in line: print "=> plugin loaded" plugin_loaded = True if "rafcon.gui.controllers.main_window" in line and "Ready" in line: print "=> ready" assert plugin_loaded time.sleep(0.5) # safety margin... print "=> RAFCON is now terminated" rafcon_gui_process.terminate() stdout, _ = rafcon_gui_process.communicate() exception_count = 0 for line in stdout.rstrip().split("\n"): print "process:", line if "Exception" in line: exception_count += 1 assert exception_count == 0 assert rafcon_gui_process.returncode == 0 break else: # kill process after 10 seconds and return with a failure if time.time() - start_time > 10: rafcon_gui_process.kill() rafcon_gui_process.communicate() assert False, "RAFCON did not start in time" finally: testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0, expected_errors=0, unpatch_threading=False)
def test_runtime_values(caplog): state_machine_manager.delete_all_state_machines() sm = state_machine_execution_engine.execute_state_machine_from_path( path=testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "library_runtime_value_test"))) state_machine_manager.remove_state_machine(sm.state_machine_id) assert sm.root_state.output_data["data_output_port1"] == 114 testing_utils.assert_logger_warnings_and_errors(caplog)
def setup_module(module=None): # set the test_libraries path temporarily to the correct value testing_utils.test_multithreading_lock.acquire() testing_utils.rewind_and_set_libraries({ "unit_test_state_machines": testing_utils.get_test_sm_path("unit_test_state_machines") }) logger.debug( rafcon.core.config.global_config.get_config_value("LIBRARY_PATHS") ["unit_test_state_machines"])
def test_preemption_behaviour_in_preemption_state(caplog): testing_utils.initialize_environment_core() sm = state_machine_execution_engine.execute_state_machine_from_path( path=testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", "preemption_behaviour_test_sm"))) rafcon.core.singleton.state_machine_manager.remove_state_machine(sm.state_machine_id) from rafcon.core.singleton import global_variable_manager try: assert global_variable_manager.get_variable("s2") == 1.0 assert not global_variable_manager.variable_exist("s3") finally: testing_utils.shutdown_environment_only_core(caplog=caplog)
def test_dynamic_state_insertion(caplog): testing_utils.run_gui( gui_config={'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False}, libraries={'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines")} ) try: execute_dynamic_state_insertion() except Exception: raise finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog)
def test_state_machine_baking(caplog): testing_utils.dummy_gui(caplog) testing_utils.run_gui( gui_config={'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False}, libraries={'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines")} ) try: trigger_baking_commands() finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog)
def test_repetitive_ungroup_state_and_group_states(caplog): """Check if repetitive group and ungroup works""" libraries = {"unit_test_state_machines": testing_utils.get_test_sm_path("unit_test_state_machines")} testing_utils.run_gui(gui_config={'HISTORY_ENABLED': True}, libraries=libraries) try: trigger_repetitive_group_ungroup() except Exception: raise finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0, expected_errors=1) pass
def test_user_input_gaphas(caplog): run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ 'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines") }) try: create_and_resize_state() except Exception, e: raise
def execute_preemptive_state_forwards_backwards(): from rafcon.core.singleton import state_machine_execution_engine import rafcon.gui.singleton as gui_singleton menubar_ctrl = gui_singleton.main_window_controller.get_controller( 'menu_bar_controller') call_gui_callback( menubar_ctrl.on_open_activate, None, None, testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "backward_step_preemtive_test"))) testing_utils.wait_for_gui() # reset the synchronization counter; although the tests run in different processes they share their memory # as the import statements are at the top of the file and not inside the parallel called functions state_machine_execution_engine.synchronization_lock.acquire() state_machine_execution_engine.synchronization_counter = 0 state_machine_execution_engine.synchronization_lock.release() call_gui_callback(menubar_ctrl.on_step_mode_activate, None, None) wait_for_execution_engine_sync_counter(1, logger) # forward for i in range(3): call_gui_callback(menubar_ctrl.on_step_into_activate, None, None) wait_for_execution_engine_sync_counter(2, logger) for i in range(2): call_gui_callback(menubar_ctrl.on_step_into_activate, None, None) wait_for_execution_engine_sync_counter(1, logger) # "take turn" state reached # backward for i in range(1): call_gui_callback(menubar_ctrl.on_backward_step_activate, None, None) wait_for_execution_engine_sync_counter(1, logger) for i in range(3): call_gui_callback(menubar_ctrl.on_backward_step_activate, None, None) wait_for_execution_engine_sync_counter(2, logger) call_gui_callback(menubar_ctrl.on_backward_step_activate, None, None) while not state_machine_execution_engine.finished_or_stopped(): time.sleep(0.1) call_gui_callback(verify_execute_preemptive_state_forwards_backwards) call_gui_callback(menubar_ctrl.on_stop_activate, None)
def test_error_propagation(caplog): testing_utils.initialize_environment_core() sm = state_machine_execution_engine.execute_state_machine_from_path( path=testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "error_propagation_test"))) state_machine_manager.remove_state_machine(sm.state_machine_id) try: assert sm.root_state.output_data["error_check"] == "successfull" finally: testing_utils.shutdown_environment_only_core(caplog=caplog, expected_warnings=0, expected_errors=2)
def test_user_input_gaphas(caplog): run_gui(gui_config={ 'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False }, libraries={ 'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines") }) try: create_and_resize_state() except Exception as e: raise finally: testing_utils.close_gui() testing_utils.shutdown_environment(caplog=caplog)
def test_last_wins_value_collection_for_data_ports(caplog): sm_path = testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", "last_data_wins_test")) sm_loaded = storage.load_state_machine_from_path(sm_path) root_state = sm_loaded.root_state state_machine = StateMachine(root_state) testing_utils.test_multithreading_lock.acquire() rafcon.core.singleton.state_machine_manager.add_state_machine(state_machine) rafcon.core.singleton.state_machine_manager.active_state_machine_id = state_machine.state_machine_id rafcon.core.singleton.state_machine_execution_engine.start() rafcon.core.singleton.state_machine_execution_engine.join() rafcon.core.singleton.state_machine_manager.remove_state_machine(state_machine.state_machine_id) testing_utils.shutdown_environment_only_core(caplog=caplog)
def test_multi_events(caplog): testing_utils.initialize_environment_core() execution_trigger_thread = threading.Thread(target=trigger_exectuion_engine, args=[global_variable_manager, state_machine_execution_engine]) execution_trigger_thread.start() sm = state_machine_execution_engine.execute_state_machine_from_path( path=testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", "multi_events_test"))) execution_trigger_thread.join() state_machine_manager.remove_state_machine(sm.state_machine_id) try: assert global_variable_manager.get_variable("sm_status") == 2 finally: testing_utils.shutdown_environment_only_core(caplog=caplog, expected_warnings=0, expected_errors=0)
def test_custom_entry_point(caplog): testing_utils.initialize_environment_core() start_state_id = "RWUZOP/ZDWBKU/HADSLI" sm = rafcon.core.singleton.state_machine_execution_engine.execute_state_machine_from_path( path=testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "test_custom_entry_point")), start_state_path=start_state_id) rafcon.core.singleton.state_machine_manager.remove_state_machine( sm.state_machine_id) try: assert not rafcon.core.singleton.global_variable_manager.variable_exist( "start_id21") finally: testing_utils.shutdown_environment_only_core(caplog=caplog)
def test_execute_script_returns_none(caplog): testing_utils.initialize_environment_core() state_machine_path = testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", "return_none_test_sm")) state_machine = storage.load_state_machine_from_path(state_machine_path) rafcon.core.singleton.state_machine_manager.add_state_machine(state_machine) assert state_machine.file_system_path == state_machine_path rafcon.core.singleton.state_machine_execution_engine.start(state_machine.state_machine_id) rafcon.core.singleton.state_machine_execution_engine.join() try: assert state_machine.root_state.final_outcome.outcome_id == 0 finally: testing_utils.shutdown_environment_only_core(caplog=caplog, expected_warnings=0, expected_errors=1)
def test_start_script_open(): """ Test core.start.py script run on console which open a state machine, run it and final checks the output file on consistency. """ testing_utils.dummy_gui(None) script = join(testing_utils.RAFCON_PATH, "core", "start.py") start_path = testing_utils.get_test_sm_path( join("unit_test_state_machines", "start_script_test")) cmd = "%s -o %s" % (script, start_path) print "\ntest_start_script_open: \n", cmd cmd_res = subprocess.call(cmd, shell=True) assert cmd_res == 0 tmp_file = open(FILE_MODIFIED_BY_STATE_MACHINE, "r") res = tmp_file.read() tmp_file.close() assert (res == "start, state, "), "start script failed" os.remove(FILE_MODIFIED_BY_STATE_MACHINE)
def test_start_script_state(): """ Test core.start.py script run by python call which open a state machine, run from a specific state and final checks the output file on consistency. """ testing_utils.dummy_gui(None) script = join(testing_utils.RAFCON_PATH, "core", "start.py") start_path = testing_utils.get_test_sm_path( join("unit_test_state_machines", "start_script_test")) state_path = "UTUOSC/AHWBOG" print start_path cmd = sys.executable + " %s -o %s -s %s" % (script, start_path, state_path) print "\ntest_start_script_state: \n", cmd cmd_res = subprocess.call(cmd, shell=True) assert cmd_res == 0 tmp_file = open(FILE_MODIFIED_BY_STATE_MACHINE, "r") res = tmp_file.read() tmp_file.close() assert (res == "state, "), "start from state failed" os.remove(FILE_MODIFIED_BY_STATE_MACHINE)