Ejemplo n.º 1
0
def test_gui(caplog):
    from os.path import join

    change_in_gui_config = {
        'AUTO_BACKUP_ENABLED': False,
        'HISTORY_ENABLED': False
    }

    libraries = {
        "ros":
        join(testing_utils.EXAMPLES_PATH, "libraries", "ros_libraries"),
        "turtle_libraries":
        join(testing_utils.EXAMPLES_PATH, "libraries", "turtle_libraries"),
        "generic":
        join(testing_utils.LIBRARY_SM_PATH, "generic")
    }
    testing_utils.run_gui(gui_config=change_in_gui_config, libraries=libraries)

    try:
        trigger_gui_signals()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=1)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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")
Ejemplo n.º 7
0
def test_api_example(caplog):

    path_of_api_examples = os.path.join(testing_utils.EXAMPLES_PATH, 'api',
                                        'generate_state_machine')
    sys.path.insert(0, path_of_api_examples)

    testing_utils.test_multithreading_lock.acquire()
    try:
        import basic_turtle_state_machine
        # TODO maybe extend example to run ros processes to check functionality of state machine too
        duration_wait_for_gui = 0.1
        timed_thread = threading.Timer(5 * duration_wait_for_gui,
                                       shutdown_gui,
                                       args=[
                                           duration_wait_for_gui,
                                       ])
        timed_thread.daemon = True
        timed_thread.start()

        basic_turtle_state_machine.run_turtle_demo()
        logger.debug("after gtk main")
        timed_thread.join()
    finally:
        sys.path.remove(path_of_api_examples)
        testing_utils.shutdown_environment(caplog=caplog,
                                           unpatch_threading=False)
Ejemplo n.º 8
0
def test_pane_positions(caplog):
    testing_utils.run_gui(core_config=None,
                          gui_config={
                              'HISTORY_ENABLED': False,
                              'AUTO_BACKUP_ENABLED': False
                          },
                          runtime_config={
                              'MAIN_WINDOW_MAXIMIZED': False,
                              'MAIN_WINDOW_SIZE': (1500, 800),
                              'MAIN_WINDOW_POS': (0, 0),
                              'LEFT_BAR_DOCKED_POS': 400,
                              'RIGHT_BAR_DOCKED_POS': 800,
                              'CONSOLE_DOCKED_POS': 600,
                              'LEFT_BAR_WINDOW_UNDOCKED': False,
                              'RIGHT_BAR_WINDOW_UNDOCKED': False,
                              'CONSOLE_WINDOW_UNDOCKED': False,
                              'LEFT_BAR_HIDDEN': False,
                              'RIGHT_BAR_HIDDEN': False,
                              'CONSOLE_HIDDEN': False,
                          })
    from rafcon.gui.runtime_config import global_runtime_config
    original_runtime_config = global_runtime_config.as_dict()

    try:
        check_pane_positions()
    finally:
        for key, value in original_runtime_config.items():
            call_gui_callback(global_runtime_config.set_config_value, key,
                              value)

        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 9
0
def test_recent_opened_state_machine_list(caplog):
    change_in_gui_config = {
        'AUTO_BACKUP_ENABLED': True,
        'HISTORY_ENABLED': False
    }

    libraries = {
        "ros":
        join(testing_utils.EXAMPLES_PATH, "libraries", "ros_libraries"),
        "turtle_libraries":
        join(testing_utils.EXAMPLES_PATH, "libraries", "turtle_libraries"),
        "generic":
        join(testing_utils.LIBRARY_SM_PATH, "generic")
    }
    testing_utils.run_gui(gui_config=change_in_gui_config,
                          libraries=libraries)  # , patch_threading=False)
    call_gui_callback(patch_backup_threading)
    try:
        trigger_gui_signals()
    except:
        raise
    finally:
        call_gui_callback(unpatch_backup_threading)
        testing_utils.close_gui()
        testing_utils.shutdown_environment(
            caplog=caplog, expected_warnings=0,
            expected_errors=1)  # , unpatch_threading=False)
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
def test_logging_view_widget(caplog):
    from os.path import join

    change_in_gui_config = {
        'AUTO_BACKUP_ENABLED': False,
        'HISTORY_ENABLED': False,
        "CONSOLE_FOLLOW_LOGGING": False,
        "LOGGING_SHOW_VERBOSE": True,
        "LOGGING_SHOW_DEBUG": True,
        "LOGGING_SHOW_WARNING": True,
        "LOGGING_SHOW_ERROR": True
    }

    libraries = {
        "ros":
        join(testing_utils.EXAMPLES_PATH, "libraries", "ros_libraries"),
        "turtle_libraries":
        join(testing_utils.EXAMPLES_PATH, "libraries", "turtle_libraries"),
        "generic":
        join(testing_utils.LIBRARY_SM_PATH, "generic")
    }

    testing_utils.run_gui(gui_config=change_in_gui_config, libraries=libraries)

    try:
        trigger_logging_view_gui_signals()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=0)
Ejemplo n.º 12
0
def test_gui(caplog):
    testing_utils.run_gui(
        gui_config={
            'AUTO_BACKUP_ENABLED': False,
            'CHECK_PYTHON_FILES_WITH_PYLINT': False,
            'PREFER_EXTERNAL_EDITOR': False
        })

    # queue = Queue.Queue() # TODO think about to use this to get call_back methods return value by a generic scheme
    # thread = threading.Thread(target=lambda q, arg1: q.put(trigger_source_editor_signals(arg1)), args=(queue, main_window_controller))
    errors = 1
    try:
        result = trigger_source_editor_signals()

        if not result:
            logger.error(
                "!The editor required in this test was not found on this machine. Test was aborted!"
            )
            errors = 2
    except:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=errors)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
def test_semantic_data(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    try:
        change_semantic_data_values()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def test_state_type_change_test(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    try:
        trigger_state_type_change_tests(with_gui=True)
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 17
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 = 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)
Ejemplo n.º 18
0
def test_bug_issue_586(caplog):
    testing_utils.run_gui(gui_config={
        'AUTO_BACKUP_ENABLED': False,
        'HISTORY_ENABLED': True
    },
                          libraries={})

    try:
        trigger_issue_586_reproduction_sequence()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 19
0
def test_notification_debugging_example(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    try:
        patch_notifications()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=0)
def test_dynamic_state_insertion_and_deletion_inside_library(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("dynamic_state_deletion_inside_library")
    except Exception:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog, expected_warnings=23)
Ejemplo n.º 21
0
def test_execution_modes(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    call_gui_callback(initialize_global_variables)
    try:
        iter_execution_modes()
    except Exception as e:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog, expected_warnings=1)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
def test_functionality_example(caplog):
    """Test for now only tests:
    - if the state machine can be open
    - if test can be run and stopped
    - and everything can be closed again
    """
    import rafcon.core.singleton
    from rafcon.core.storage import storage

    # The test maybe should also test if functionality are correct depicted.
    # TODO check if this is done in the common tests already

    for name in [
            'backward_step_barrier', 'backward_step_hierarchy',
            'backward_step_preemption', 'decider_statemachine',
            'hierarchy_abortion_handling'
    ]:
        sm_path = join(testing_utils.EXAMPLES_PATH, 'functionality_examples',
                       name)
        print(sm_path)
        state_machine = storage.load_state_machine_from_path(sm_path)
        rafcon.core.singleton.state_machine_manager.add_state_machine(
            state_machine)

    testing_utils.test_multithreading_lock.acquire()
    try:
        # main_window_controller = rafcon.gui.singleton.main_window_controller
        for state_machine_id in list(
                rafcon.core.singleton.state_machine_manager.state_machines.
                keys()):
            rafcon.core.singleton.state_machine_execution_engine.start(
                state_machine_id)
            max_time = 3
            current_time = 0.0
            sleep_time = 0.2
            while not rafcon.core.singleton.state_machine_execution_engine.finished_or_stopped(
            ):
                time.sleep(sleep_time)
                current_time += sleep_time
                if current_time >= max_time:
                    break
            rafcon.core.singleton.state_machine_execution_engine.stop()
            rafcon.core.singleton.state_machine_execution_engine.join()
    finally:
        testing_utils.wait_for_gui(
        )  # to avoid execution and model notification clinches
        testing_utils.shutdown_environment(gui_config=False,
                                           caplog=caplog,
                                           expected_warnings=2,
                                           expected_errors=4,
                                           unpatch_threading=False)
Ejemplo n.º 24
0
def test_copy_delete_bug(caplog):
    from os.path import join

    libraries = {"ros": join(testing_utils.EXAMPLES_PATH, "libraries", "ros_libraries"),
                 "turtle_libraries": join(testing_utils.EXAMPLES_PATH, "libraries", "turtle_libraries"),
                 "generic": join(testing_utils.LIBRARY_SM_PATH, "generic")}
    change_in_gui_config = {'AUTO_BACKUP_ENABLED': False, 'HISTORY_ENABLED': False}
    testing_utils.run_gui(gui_config=change_in_gui_config, libraries=libraries,)

    try:
        trigger_copy_delete_bug_signals()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 25
0
def test_gui_tests(monkeypatch, caplog):
    # let the gui thread create the gui singletons by opening and closing an empty gui
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })

    try:
        pass
    except:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
def test_dialog_test(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    logger.debug("Dialog test started.")
    try:
        trigger_dialog_tests()
    except Exception:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=0)
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
def test_gui(caplog):

    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    try:
        trigger_gvm_signals()
    except:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog,
                                           expected_warnings=0,
                                           expected_errors=1)
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)