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)
Beispiel #2
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)
Beispiel #3
0
def save_state_machine(with_gui=True):
    import rafcon
    from rafcon.core.singleton import state_machine_execution_engine
    import rafcon.gui.singleton as gui_singleton
    from rafcon.core.storage import storage

    path = testing_utils.get_unique_temp_path()
    if with_gui:
        state_machine = call_gui_callback(create_models)
    else:
        state_machine = create_models()

    if with_gui:
        sm_model = rafcon.gui.singleton.state_machine_manager_model.state_machines[
            state_machine.state_machine_id]
        menubar_ctrl = gui_singleton.main_window_controller.get_controller(
            'menu_bar_controller')
        # sm_model.state_machine.base_path = path
        call_gui_callback(menubar_ctrl.on_save_as_activate, None, None, path)
        # call_gui_callback(menubar_ctrl.on_quit_activate, None)
        call_gui_callback(check_that_all_files_are_there,
                          state_machine,
                          with_print=False)
    else:
        storage.save_state_machine_to_path(state_machine,
                                           path,
                                           delete_old_state_machine=False)
        check_that_all_files_are_there(state_machine, with_print=False)
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 run_copy_test(sm_m, with_gui=False):
    """Run general test that """
    import rafcon.gui.singleton
    sm = sm_m.state_machine
    new_sm_m = copy.copy(sm_m)
    equal_check_state(sm_m.root_state.state, new_sm_m.root_state.state)
    equal_check_state_model(sm_m.root_state, new_sm_m.root_state)
    compare_references_to_sm_model_and_core(sm_m, new_sm_m)

    # storage copy tests
    if sm.file_system_path is None:
        tmp_sm_system_path = join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE,
                                  'copy_test_' + str(sm.state_machine_id))
    else:
        tmp_sm_system_path = join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE,
                                  'copy_test' + sm.file_system_path)

    new_sm_m.state_machine.root_state.name = "Copied Cont state"
    testing_utils.wait_for_gui()
    new_sm_m.destroy()
    if with_gui:
        main_window_controller = rafcon.gui.singleton.main_window_controller
        menubar_ctrl = main_window_controller.get_controller(
            'menu_bar_controller')
        testing_utils.call_gui_callback(sm_m.state_machine.__setattr__,
                                        "file_system_path", tmp_sm_system_path)
        testing_utils.call_gui_callback(menubar_ctrl.on_save_activate, None)
Beispiel #6
0
 def wait_for_sync_counter_change_and_wait_for_gui(current_sync_counter):
     assert current_sync_counter is not None
     print("##### before {0} #####".format(current_sync_counter))
     while current_sync_counter == state_machine_execution_engine.synchronization_counter:
         time.sleep(0.1)
         print("##### in wait {0} #####".format(state_machine_execution_engine.synchronization_counter))
     print("##### after {0} #####".format(state_machine_execution_engine.synchronization_counter))
     testing_utils.call_gui_callback(testing_utils.wait_for_gui)
Beispiel #7
0
def paste(state_machine_model, state_m, main_window_controller, menu_bar_ctrl,
          page):
    print("Pasting")
    call_gui_callback(state_machine_model.selection.set, [state_m])
    main_window_controller.view['main_window'].grab_focus()
    focus_graphical_editor_in_page(page)
    call_gui_callback(menu_bar_ctrl.on_paste_clipboard_activate, None, None)
    testing_utils.wait_for_gui()
Beispiel #8
0
def add_state_machine_to_manager_model(state_machine, profiling=False):
    def _add_state_machine_to_manager_model():
        from rafcon.gui.singleton import state_machine_manager
        if profiling:
            profiler.start("add_state_machine")
        state_machine_manager.add_state_machine(state_machine)
        testing_utils.wait_for_gui()
        if profiling:
            profiler.stop("add_state_machine")
    testing_utils.call_gui_callback(_add_state_machine_to_manager_model)
def run_state_machine(state_machine_path):
    import rafcon.core.config
    import rafcon.core.singleton as singletons
    import rafcon.gui.helpers.state_machine as gui_helper_statemachine

    gvm = rafcon.core.singleton.global_variable_manager
    execution_engine = singletons.state_machine_execution_engine
    state_machine_manager = singletons.state_machine_manager

    if not execution_engine.finished_or_stopped():
        raise RuntimeError("The execution engine is not stopped")

    print("Loading state machine from path: {}".format(state_machine_path))

    state_machine = call_gui_callback(
        gui_helper_statemachine.open_state_machine, state_machine_path)
    call_gui_callback(testing_utils.remove_all_gvm_variables)
    call_gui_callback(execution_engine.start, state_machine.state_machine_id)

    if not execution_engine.join(3):
        raise RuntimeError(
            "State machine did not finish within the given time")

    call_gui_callback(assert_correctness_of_execution)
    call_gui_callback(state_machine_manager.remove_state_machine,
                      state_machine.state_machine_id)
Beispiel #10
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)
def trigger_gui_signals_second_run(*args):
    import rafcon.gui.singleton
    main_window_controller = rafcon.gui.singleton.main_window_controller
    sm_manager_model = rafcon.gui.singleton.state_machine_manager_model
    open_state_machines = args[0]
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')
    import rafcon.gui.backup.session as backup_session
    if rafcon.gui.singleton.global_gui_config.get_config_value(
            "SESSION_RESTORE_ENABLED"):
        call_gui_callback(backup_session.restore_session_from_runtime_config)
    print("restore config",
          rafcon.gui.singleton.global_runtime_config.config_file_path)
    with open(rafcon.gui.singleton.global_runtime_config.config_file_path,
              'r') as f:
        found_flag = False
        print("\n" * 5, "#" * 20)
        for line in f:
            if "open_tabs" in line:
                found_flag = True
            if found_flag:
                print(line)
        print("#" * 20, "\n" * 5)
    call_gui_callback(testing_utils.wait_for_gui)
    call_gui_callback(prepare_tab_data_of_open_state_machines,
                      main_window_controller, sm_manager_model,
                      open_state_machines)
    call_gui_callback(backup_session.reset_session)
    def test_bar(window, window_key):

        configure_handler_id = connect_window(window, 'configure-event',
                                              notify_on_event)
        hide_handler_id = connect_window(window, 'hide', notify_on_event)

        print("undocking...")
        time.sleep(debug_sleep_time)
        ready.clear()
        call_gui_callback(
            main_window_controller.view["undock_{}_button".format(
                window_key.lower())].emit, "clicked")
        wait_for_event_notification()

        print("docking...")
        time.sleep(debug_sleep_time)
        ready.clear()
        attribute_name_of_undocked_window_view = window_key.lower() + "_window"
        undocked_window_view = getattr(main_window_controller.view,
                                       attribute_name_of_undocked_window_view)
        redock_button = undocked_window_view['redock_button']
        call_gui_callback(redock_button.emit, "clicked")
        wait_for_event_notification()

        time.sleep(debug_sleep_time)
        call_gui_callback(window.disconnect, configure_handler_id)
        call_gui_callback(window.disconnect, hide_handler_id)
Beispiel #13
0
def select_and_paste_state(state_machine_model, source_state_model,
                           target_state_model, menu_bar_ctrl, operation,
                           main_window_controller, page):
    """Select a particular state and perform an operation on it (Copy or Cut) and paste it somewhere else. At the end,
    verify that the operation was completed successfully.

    :param state_machine_model: The state machine model where the operation will be conducted
    :param source_state_model: The state model, on which the operation will be performed
    :param target_state_model: The state model, where the source state will be pasted
    :param menu_bar_ctrl: The menu_bar controller, through which copy, cut & paste actions are triggered
    :param operation: String indicating the operation to be performed (Copy or Cut)
    :param main_window_controller: The MainWindow Controller
    :param page: The notebook page of the corresponding state machine in the state machines editor
    :return: The target state model, and the child state count before pasting
    """
    print("\n\n %s \n\n" % source_state_model.state.name)
    call_gui_callback(state_machine_model.selection.set, [source_state_model])
    call_gui_callback(
        getattr(menu_bar_ctrl, 'on_{}_selection_activate'.format(operation)),
        None, None)
    print("\n\n %s \n\n" % target_state_model.state.name)
    call_gui_callback(state_machine_model.selection.set, [target_state_model])
    old_child_state_count = len(target_state_model.state.states)
    main_window_controller.view['main_window'].grab_focus()
    focus_graphical_editor_in_page(page)
    call_gui_callback(menu_bar_ctrl.on_paste_clipboard_activate, None, None)
    testing_utils.wait_for_gui()
    print(list(target_state_model.state.states.keys()))
    assert len(target_state_model.state.states) == old_child_state_count + 1
    return target_state_model, old_child_state_count
def create_and_resize_state():
    from gi.repository import Gtk
    from rafcon.gui.singleton import main_window_controller
    # gvm = rafcon.core.singleton.global_variable_manager
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')
    # from rafcon.gui.controllers.menu_bar import MenuBarController
    # assert isinstance(menubar_ctrl, MenuBarController)
    # execution_engine = singletons.state_machine_execution_engine
    # state_machine_manager = singletons.state_machine_manager

    call_gui_callback(menubar_ctrl.on_new_activate, None)
    # time.sleep(1.0)
    time.sleep(0.5)

    wait_for_gui()

    sm_ctrls = main_window_controller.get_controller('state_machines_editor_ctrl')
    graphical_editor_controller = sm_ctrls.get_controller(1)
    # get first state machine page in state machines notebook
    sm_page = list(sm_ctrls.tabs.items())[0][1]['page']
    sm_model = list(sm_ctrls.tabs.items())[0][1]['state_machine_m']

    state_view_for_root_state = graphical_editor_controller.canvas.get_view_for_model(sm_model.root_state)
    x, y = south_east_coordinates_of_model(state_view_for_root_state)

    # print x, y

    call_gui_callback(resize_state, sm_model, sm_page, graphical_editor_controller)

    # wait_for_gui()
    # graphical_editor_controller.canvas.update()

    new_x, new_y = south_east_coordinates_of_model(state_view_for_root_state)
    sleep_time = 0.01
    max_counter = 10.0 / 0.01
    counter = 0
    while new_x == x and new_y == y:
        new_x, new_y = south_east_coordinates_of_model(state_view_for_root_state)
        counter += 1
        if counter > max_counter:
            break
        time.sleep(sleep_time)

    # print new_x, new_y

    assert x < new_x
    assert y < new_y
Beispiel #15
0
def patch_notifications():
    enable_debugging()
    # call_gui_callback(create_bigger_state_machine)
    call_gui_callback(create_small_state_machine)
    # from rafcon.gui.widget.test_storage import create_models
    # call_gui_callback(create_models)
    testing_utils.wait_for_gui()
    call_gui_callback(show_debug_graph)
    disable_debugging()

    from tests.utils import RAFCON_TEMP_PATH_TEST_BASE_ONLY_USER_SAVE
    assert exists(
        join(RAFCON_TEMP_PATH_TEST_BASE_ONLY_USER_SAVE,
             'notification_output.gv'))
    assert exists(
        join(RAFCON_TEMP_PATH_TEST_BASE_ONLY_USER_SAVE,
             'notification_print_out.txt'))
Beispiel #16
0
def copy_and_paste_state_into_itself(sm_m, state_m_to_copy, page,
                                     menu_bar_ctrl):
    call_gui_callback(sm_m.selection.set, [state_m_to_copy])
    focus_graphical_editor_in_page(page)
    call_gui_callback(menu_bar_ctrl.on_copy_selection_activate, None, None)
    old_child_state_count = len(state_m_to_copy.state.states)
    call_gui_callback(sm_m.selection.set, [state_m_to_copy])
    focus_graphical_editor_in_page(page)
    call_gui_callback(menu_bar_ctrl.on_paste_clipboard_activate, None, None)
    assert len(state_m_to_copy.state.states) == old_child_state_count + 1
Beispiel #17
0
def open_test_state_machine():
    import rafcon.gui.singleton

    smm_m = rafcon.gui.singleton.state_machine_manager_model
    main_window_controller = rafcon.gui.singleton.main_window_controller
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')
    state_machines_ctrl = main_window_controller.get_controller("state_machines_editor_ctrl")

    call_gui_callback(menubar_ctrl.on_open_activate, None, None, sm_path_recursive_resize)
    time.sleep(0.5)
    call_gui_callback(wait_for_gui)  # Wait for gaphas view

    sm_m = smm_m.state_machines[smm_m.selected_state_machine_id]
    sm_id = sm_m.state_machine.state_machine_id
    sm_gaphas_ctrl = state_machines_ctrl.get_controller(sm_id)
    canvas = sm_gaphas_ctrl.canvas
    gaphas_view = sm_gaphas_ctrl.view.editor

    return sm_m, canvas, gaphas_view
def execute_preemption_of_all_state_machines_at_once():
    from rafcon.core.singleton import state_machine_execution_engine, state_machine_manager
    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",
                         "all_dialogs_parallel_preempted")))
    testing_utils.wait_for_gui()

    call_gui_callback(menubar_ctrl.on_start_activate, None, None)
    duration_waited = 0.
    period = 0.1
    while not state_machine_execution_engine.finished_or_stopped():
        time.sleep(period)
        duration_waited += period
        if duration_waited > 3.:
            call_gui_callback(menubar_ctrl.on_stop_activate, None, None)
            raise RuntimeError(
                "The state machine should finish in less then {0}".format(
                    duration_waited))
    print(
        "Run duration of execute_preemption_of_all_state_machines_at_once was: {0}"
        .format(duration_waited))
Beispiel #19
0
def trigger_baking_commands():
    # core elements
    import rafcon.core.id_generator
    from rafcon.core.singleton import state_machine_manager
    # gui elements
    import rafcon.gui.singleton as gui_singleton
    from rafcon.gui.helpers import state_machine as gui_helper_state_machine

    sm_id_0 = rafcon.core.id_generator.state_machine_id_counter

    menu_bar_controller = gui_singleton.main_window_controller.get_controller(
        "menu_bar_controller")

    call_gui_callback(
        menu_bar_controller.on_open_activate, None, None,
        testing_utils.get_test_sm_path(
            os.path.join("unit_test_state_machines", "bake_sm")))

    state_machine1 = state_machine_manager.state_machines[sm_id_0 + 1]
    print("#1 ", state_machine1)
    print("#2 ", call_gui_callback(state_machine1.mutable_hash).hexdigest())

    baking_path = os.path.join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE,
                               "baking")
    # baking_path = os.path.join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE_ONLY_USER_SAVE, "baking")

    call_gui_callback(gui_helper_state_machine.bake_selected_state_machine,
                      baking_path)

    call_gui_callback(menu_bar_controller.on_open_activate, None, None,
                      os.path.join(baking_path, "__generated__state_machine"))

    from rafcon.core.id_generator import generate_state_machine_id
    state_machine2 = state_machine_manager.state_machines[sm_id_0 + 4]
    print("#3 ", state_machine2)
    print("#4 ", call_gui_callback(state_machine1.mutable_hash).hexdigest())

    mutable_hash_sm1 = call_gui_callback(state_machine1.mutable_hash)
    mutable_hash_sm2 = call_gui_callback(state_machine2.mutable_hash)
    assert mutable_hash_sm1.hexdigest() == mutable_hash_sm2.hexdigest()
Beispiel #20
0
def run_create():
    """ By searching for the WT thread number can been seen, that
    """
    from rafcon.core.states.hierarchy_state import HierarchyState
    from rafcon.core.state_machine import StateMachine
    import rafcon.core.singleton
    import rafcon.gui.singleton

    print("WT_ident: ", threading.currentThread().ident)
    print("CORE_singleton_init_thread_ident: ",
          rafcon.core.singleton.thread_identifier)
    print("GUI_singleton_init_thread_ident: ",
          rafcon.gui.singleton.thread_identifier)
    main_window_controller = rafcon.gui.singleton.main_window_controller
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')
    call_gui_callback(menubar_ctrl.on_new_activate, None)
    # negative test
    # menubar_ctrl.on_new_activate(None)
    print("\n" * 3, "WT generated object", "\n" * 3)
    call_gui_callback(
        rafcon.core.singleton.state_machine_manager.add_state_machine,
        StateMachine(HierarchyState("new root state")))
def execute_dynamic_state_insertion(state_machine_name="dynamic_library_insertion"):
    from rafcon.core.singleton import state_machine_execution_engine, state_machine_manager
    import rafcon.gui.singleton as gui_singleton

    menubar_ctrl = gui_singleton.main_window_controller.get_controller('menu_bar_controller')

    sm = call_gui_callback(
        menubar_ctrl.on_open_activate, None, None,
        testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", state_machine_name))
    )
    testing_utils.wait_for_gui()  # TODO check -> without call_gui_callback wait_for_gui should be without effect

    call_gui_callback(menubar_ctrl.on_start_activate, None, None)
    current_state_machine_id = gui_singleton.state_machine_manager.active_state_machine_id
    state_machines_editor_tab_status_check(current_state_machine_id, active=True)  # execution start is synchronous

    testing_utils.wait_for_gui()  # TODO check -> without call_gui_callback wait_for_gui should be without effect

    while not state_machine_execution_engine.finished_or_stopped():
        time.sleep(0.1)
    # stop or finished are asynchronous but the call_gui_callback makes the check synchronous
    call_gui_callback(state_machines_editor_tab_status_check, current_state_machine_id, False)
def test_all_generic_libraries_in_a_row(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    },
                          libraries={
                              'generic':
                              os.path.join(testing_utils.LIBRARY_SM_PATH,
                                           'generic')
                          })
    call_gui_callback(initialize_global_variables)
    try:
        with pytest.warns(
                log.RAFCONDeprecationWarning) as deprecations_warnings:
            execute_all_generic_libraries_with_keyboard_only()
        assert len([
            record for record in deprecations_warnings
            if record.category is log.RAFCONDeprecationWarning
        ]) == 4
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog, expected_warnings=0)
Beispiel #23
0
 def add_two_states_to_root_state_of_selected_state_machine():
     sm_m = sm_manager_model.get_selected_state_machine_model()
     current_number_states = len(sm_m.root_state.states)
     call_gui_callback(sm_m.selection.set, sm_m.root_state)
     call_gui_callback(menubar_ctrl.on_add_state_activate, None)
     call_gui_callback(menubar_ctrl.on_add_state_activate, None)
     assert len(sm_m.root_state.states) == current_number_states + 2
     assert sm_manager_model.get_selected_state_machine_model().state_machine.marked_dirty
Beispiel #24
0
    def check_scrollbar_adjustment_to_be_at_bottom():
        testing_utils.wait_for_gui()
        call_gui_callback(testing_utils.wait_for_gui)
        # waiting for the gui is not sufficient
        # calling show(), show_now(), show_all(), realize() or reset_style() on the scrollbar does not work either
        scrolled_down = False
        counter = 0
        while (not scrolled_down) and counter < 10:
            adj = logging_console_ctrl.view['scrollable'].get_vadjustment()
            if not int(adj.get_value()) == int(adj.get_upper() -
                                               adj.get_page_size()):
                testing_utils.wait_for_gui()
                time.sleep(0.1)
            else:
                scrolled_down = False
            counter += 1

        if not int(
                adj.get_value()) == int(adj.get_upper() - adj.get_page_size()):
            logger.warning(
                'The scroller seems not to be at the end of the page {0} == {1}'
                ''.format(int(adj.get_value()),
                          int(adj.get_upper() - adj.get_page_size())))
Beispiel #25
0
def shutdown_gui(duration_wait_for_gui):
    # wait for menu bar and main window controller
    menubar_ctrl = None
    time.sleep(2)
    while menubar_ctrl is None:
        time.sleep(duration_wait_for_gui)
        menubar_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('menu_bar_controller') if \
            rafcon.gui.singleton.main_window_controller else None

    # quit rafcon by menu bar
    testing_utils.call_gui_callback(menubar_ctrl.on_save_as_activate, None,
                                    None, testing_utils.get_unique_temp_path())
    testing_utils.call_gui_callback(menubar_ctrl.on_stop_activate, None)
    testing_utils.call_gui_callback(menubar_ctrl.on_quit_activate, None)
def execute_all_generic_libraries_with_keyboard_only():
    from rafcon.core.singleton import state_machine_execution_engine, state_machine_manager
    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", "all_generic_libraries")))
    testing_utils.wait_for_gui()

    call_gui_callback(menubar_ctrl.on_start_activate, None, None)
    import time
    from pykeyboard import PyKeyboard
    time.sleep(0.5)
    k = PyKeyboard()
    k.tap_key('Return', 7, 0.5)
    k.tap_key('Tab', 2, 0.5)
    k.tap_key('Return', 5, 0.5)
    call_gui_callback(menubar_ctrl.on_stop_activate, None, None)
Beispiel #27
0
def trigger_gvm_signals():
    # core elements
    import rafcon.core.singleton
    import rafcon.gui.singleton
    call_gui_callback(testing_utils.remove_all_gvm_variables)
    gvm = rafcon.core.singleton.global_variable_manager
    gvm_controller = rafcon.gui.singleton.main_window_controller.get_controller(
        'global_variable_manager_ctrl')

    view = gvm_controller.view['global_variable_tree_view']
    call_gui_callback(view.grab_focus)

    call_gui_callback(gvm.set_variable, 'new_0', 0)

    # use gui callback to wait for gv row generation
    call_gui_callback(gvm_controller.apply_new_global_variable_value, 0, '2')

    def run_gvm_method0(method, return_list):
        return_list.append(method())

    def run_gvm_method1(method, gv_arg1, return_list):
        return_list.append(method(gv_arg1))

    def run_gvm_method2(method, gv_arg1, gv_arg2, return_list):
        return_list.append(method(gv_arg1, gv_arg2))

    return_list = list()
    call_gui_callback(run_gvm_method1, gvm.get_variable, 'new_0', return_list)
    assert return_list[-1] == 2

    call_gui_callback(gvm_controller.apply_new_global_variable_name, 0,
                      'changed_global_0')
    call_gui_callback(run_gvm_method1, gvm.get_variable, 'changed_global_0',
                      return_list)
    assert return_list[-1]

    call_gui_callback(gvm_controller.apply_new_global_variable_type, 0,
                      'float')
    call_gui_callback(run_gvm_method1, gvm.get_data_type, 'changed_global_0',
                      return_list)
    assert return_list[-1] is float

    call_gui_callback(run_gvm_method1, gvm.lock_variable, 'changed_global_0',
                      return_list)
    access_key = return_list[-1]
    assert not gvm_controller.global_variable_is_editable(
        'changed_global_0', 'testing...')

    call_gui_callback(run_gvm_method2, gvm.unlock_variable, 'changed_global_0',
                      access_key, return_list)

    call_gui_callback(gvm_controller.on_add, view)
    call_gui_callback(run_gvm_method0, gvm.get_all_keys, return_list)
    assert len(return_list[-1]) is 2

    call_gui_callback(gvm_controller.remove_core_element, 'changed_global_0')
    call_gui_callback(run_gvm_method0, gvm.get_all_keys, return_list)
    assert len(return_list[-1]) is 1
def trigger_drag_and_drop_tests(*args):

    # TODO test should use real SelectionData objects and motion to provide selection
    # -> currently very limited test scenario

    class StructHelper:
        """Used to imitate a SelectionData Class"""
        def __init__(self, x, y, text):
            self.x = x
            self.y = y
            self.text = text

        def set_text(self, text, length):
            self.text = text

        def get_text(self):
            return self.text

    # TODO test needs check on position -> is the state drawn where it was dropped?
    sm_manager_model = args[0]
    main_window_controller = args[1]

    states_machines_editor_controller = main_window_controller.get_controller(
        'state_machines_editor_ctrl')
    library_tree_controller = main_window_controller.get_controller(
        'library_controller')
    state_icon_controller = main_window_controller.get_controller(
        'state_icon_controller')
    graphical_editor_controller = states_machines_editor_controller.get_child_controllers(
    )[0]

    # the view is required here; as it is created asynchronously we explicitly wait for its creation
    while not graphical_editor_controller.view:
        testing_utils.wait_for_gui()

    # wait for root state to be focused
    time.sleep(.5)

    call_gui_callback(library_tree_controller.view.expand_all)
    # generic and unit_test_state_machines in library tree index 1 is unit_test_state_machines
    call_gui_callback(library_tree_controller.view.get_selection().select_path,
                      (1, 0))

    selection_data = StructHelper(0, 0, None)
    state_machine_m = sm_manager_model.get_selected_state_machine_model()

    # insert state in root_state
    print("insert state in root_state")
    call_gui_callback(graphical_editor_controller.on_drag_motion, None, None,
                      200, 200, None)
    # Override selection
    state_m = state_machine_m.root_state
    call_gui_callback(state_machine_m.selection.set, [state_m])
    call_gui_callback(library_tree_controller.on_drag_data_get,
                      library_tree_controller.view, None, selection_data, 0,
                      None)
    call_gui_callback(graphical_editor_controller.on_drag_data_received, None,
                      None, 200, 200, selection_data, None, None)
    assert len(sm_manager_model.get_selected_state_machine_model().root_state.
               state.states) == 2

    # insert state from IconView
    print("insert state from IconView")
    call_gui_callback(graphical_editor_controller.on_drag_motion, None, None,
                      300, 300, None)
    # Override selection
    state_m = state_machine_m.root_state
    call_gui_callback(state_machine_m.selection.set, [state_m])
    call_gui_callback(state_icon_controller.on_mouse_motion, None,
                      StructHelper(30, 15, None))
    call_gui_callback(state_icon_controller.on_drag_data_get, None, None,
                      selection_data, None, None)
    call_gui_callback(graphical_editor_controller.on_drag_data_received, None,
                      None, 300, 300, selection_data, None, None)
    assert len(sm_manager_model.get_selected_state_machine_model().root_state.
               state.states) == 3

    # insert state next to root state
    print("insert state next to root state")
    # Position (0, 0) in left above the root state
    call_gui_callback(graphical_editor_controller.on_drag_motion, None, None,
                      0, 0, None)
    call_gui_callback(state_icon_controller.on_mouse_motion, None,
                      StructHelper(30, 15, None))
    call_gui_callback(state_icon_controller.on_drag_data_get, None, None,
                      selection_data, None, None)

    # insert state in state1
    print("insert state in state1")
    state_m = state_machine_m.root_state.states['State1']
    call_gui_callback(state_machine_m.selection.set, [state_m])
    # Selecting a state using the drag_motion event is too unreliable, as the exact position depends on the size of
    # the editor. Therefore, it is now selected using the selection object directly
    # if isinstance(graphical_editor_controller, GraphicalEditorGaphasController):
    #     call_gui_callback(graphical_editor_controller.on_drag_motion, None, None, 100, 100, None)
    # else:
    #     call_gui_callback(graphical_editor_controller.on_drag_motion, None, None, 150, 150, None)
    call_gui_callback(library_tree_controller.on_drag_data_get,
                      library_tree_controller.view, None, selection_data, 0,
                      None)
    call_gui_callback(graphical_editor_controller.on_drag_data_received, None,
                      None, 20, 20, selection_data, None, None)
    assert len(sm_manager_model.get_selected_state_machine_model().root_state.
               state.states['State1'].states) == 1
def trigger_ungroup_signals():
    import rafcon.core.singleton
    import rafcon.gui.singleton as gui_singleton
    import rafcon.gui.helpers.state as gui_helper_state
    import rafcon.gui.helpers.state_machine as gui_helper_state_machine

    sm_manager_model = rafcon.gui.singleton.state_machine_manager_model
    main_window_controller = gui_singleton.main_window_controller
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')

    state_machine = create_state_machine()
    first_sm_id = state_machine.state_machine_id
    call_gui_callback(
        rafcon.core.singleton.state_machine_manager.add_state_machine,
        state_machine)

    call_gui_callback(main_window_controller.view['main_window'].grab_focus)
    call_gui_callback(sm_manager_model.__setattr__,
                      "selected_state_machine_id", first_sm_id)

    state_machines_ctrl = main_window_controller.get_controller(
        'state_machines_editor_ctrl')
    page_id = state_machines_ctrl.get_page_num(first_sm_id)
    page = state_machines_ctrl.view.notebook.get_nth_page(page_id)
    call_gui_callback(focus_graphical_editor_in_page, page)
    sm_m = sm_manager_model.get_selected_state_machine_model()
    assert sm_m
    call_gui_callback(gui_helper_state.change_state_type,
                      sm_m.get_state_model_by_path("ROOTSTATE/STATE3"),
                      gui_helper_state.BarrierConcurrencyState)

    call_gui_callback(sm_m.selection.set,
                      sm_m.get_state_model_by_path("ROOTSTATE/STATE3"))
    call_gui_callback(gui_helper_state_machine.ungroup_selected_state)

    call_gui_callback(menubar_ctrl.on_save_as_activate, None, None,
                      testing_utils.get_unique_temp_path())
    call_gui_callback(menubar_ctrl.on_stop_activate, None)
def trigger_issue_586_reproduction_sequence():
    from os.path import join
    import rafcon.gui.singleton
    sm_manager_model = rafcon.gui.singleton.state_machine_manager_model
    main_window_controller = rafcon.gui.singleton.main_window_controller
    menubar_ctrl = main_window_controller.get_controller('menu_bar_controller')
    current_sm_length = len(sm_manager_model.state_machines)
    assert current_sm_length == 0

    # backward step barrier test is chosen to work on an existing test state machine including equal child state ids
    call_gui_callback(
        menubar_ctrl.on_open_activate, None, None,
        join(testing_utils.TEST_ASSETS_PATH, "unit_test_state_machines",
             "backward_step_barrier_test"))
    sm_m = list(sm_manager_model.state_machines.values())[0]
    assert sm_m.state_machine_id == sm_manager_model.selected_state_machine_id
    concurrent_decimate_state_m = sm_m.get_state_model_by_path("GLSUJY/OOECFM")

    # check start conditions overlapping ids -> all states have four states and those have the same ids
    import rafcon.core.constants
    state_ids = list(concurrent_decimate_state_m.states.keys())
    state_ids.remove(rafcon.core.constants.UNIQUE_DECIDER_STATE_ID)

    state_ids_set = set()
    for state_id in state_ids:
        for child_state_id in concurrent_decimate_state_m.states[
                state_id].states.keys():
            state_ids_set.add(child_state_id)
        assert len(state_ids_set) == 4

    call_gui_callback(sm_m.selection.set, concurrent_decimate_state_m)
    call_gui_callback(menubar_ctrl.on_ungroup_state_activate, None, None)
    testing_utils.wait_for_gui()

    # ungroup all three child states which all have the same state ids as there child states plus data flows
    for state_id in state_ids:
        print("ungroup state:", state_id)
        assert state_id in sm_m.root_state.states
        child_state_m = sm_m.get_state_model_by_path("GLSUJY/" + state_id)
        call_gui_callback(sm_m.selection.set, child_state_m)
        call_gui_callback(menubar_ctrl.on_ungroup_state_activate, None, None)

    # store and refresh selected
    call_gui_callback(menubar_ctrl.on_save_as_activate, None, None,
                      testing_utils.get_unique_temp_path())
    call_gui_callback(menubar_ctrl.on_refresh_selected_activate, None, None)