示例#1
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))
示例#2
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)
示例#3
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")
示例#4
0
def test_dialog_test(caplog):
    testing_utils.dummy_gui(None)

    testing_utils.initialize_environment(gui_already_started=False)

    logger.debug("Dialog test started.")

    thread = threading.Thread(target=trigger_dialog_tests)
    thread.start()
    testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0, expected_errors=0, unpatch_threading=False)
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)
示例#6
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")
    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)

    testing_utils.shutdown_environment(caplog=caplog, unpatch_threading=False)
示例#7
0
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")