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)

    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)

    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_manager.active_state_machine_id)
Exemple #2
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)
Exemple #3
0
def test_window_positions(caplog):
    testing_utils.run_gui(core_config=None,
                          runtime_config={
                              'LEFT_BAR_WINDOW_SIZE': (800, 800),
                              'RIGHT_BAR_WINDOW_SIZE': (800, 800),
                              'CONSOLE_WINDOW_SIZE': (800, 800),
                              'LEFT_BAR_WINDOW_POS': (10, 10),
                              'RIGHT_BAR_WINDOW_POS': (10, 10),
                              'CONSOLE_WINDOW_POS': (10, 10),
                              'LEFT_BAR_WINDOW_UNDOCKED': False,
                              'RIGHT_BAR_WINDOW_UNDOCKED': False,
                              'CONSOLE_WINDOW_UNDOCKED': False
                          },
                          gui_config={
                              'HISTORY_ENABLED': False,
                              'AUTO_BACKUP_ENABLED': False
                          })
    from rafcon.gui.runtime_config import global_runtime_config
    original_runtime_config = global_runtime_config.as_dict()

    try:
        undock_sidebars()
    finally:
        for key, value in original_runtime_config.iteritems():
            call_gui_callback(global_runtime_config.set_config_value, key,
                              value)

        testing_utils.close_gui()
        testing_utils.shutdown_environment(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)
Exemple #5
0
def test_pane_positions(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    },
                          runtime_config={
                              'LEFT_BAR_DOCKED_POS': 500,
                              'RIGHT_BAR_DOCKED_POS': 950,
                              'CONSOLE_DOCKED_POS': 700,
                              'LEFT_BAR_WINDOW_UNDOCKED': False,
                              'RIGHT_BAR_WINDOW_UNDOCKED': False,
                              'CONSOLE_WINDOW_UNDOCKED': 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.iteritems():
            call_gui_callback(global_runtime_config.set_config_value, key,
                              value)

        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Exemple #6
0
 def check_scrollbar_adjustment_to_be_at_bottom():
     testing_utils.wait_for_gui()
     call_gui_callback(testing_utils.wait_for_gui)
     adj = logging_console_ctrl.view['scrollable'].get_vadjustment()
     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())))
Exemple #7
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)
Exemple #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)
Exemple #9
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)
Exemple #10
0
def test_backward_stepping_preemptive_state(caplog):
    testing_utils.run_gui(gui_config={'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False})
    call_gui_callback(initialize_global_variables)
    try:
        execute_preemptive_state_forwards_backwards()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
def test_backward_stepping_barrier_state(caplog):
    testing_utils.run_gui(gui_config={
        'HISTORY_ENABLED': False,
        'AUTO_BACKUP_ENABLED': False
    })
    call_gui_callback(initialize_global_variables)
    try:
        execute_barrier_state_forwards_backwards()
    except Exception, e:
        raise
Exemple #12
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)
Exemple #13
0
def create_and_resize_state():
    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)

    testing_utils.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 = sm_ctrls.tabs.items()[0][1]['page']
    sm_model = 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)

    # testing_utils.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
Exemple #14
0
    def test_bar(window, window_key):

        output_list = list()
        call_gui_callback(connect_window, window, 'configure-event',
                          notify_on_event, output_list)
        configure_handler_id = output_list[0]
        output_list = list()
        call_gui_callback(connect_window, window, 'hide', notify_on_event,
                          output_list)
        hide_handler_id = output_list[0]

        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 = getattr(undocked_window_view,
                                "top_tool_bar")['redock_button']
        call_gui_callback(redock_button.emit, "clicked")
        wait_for_event_notification()

        window.disconnect(configure_handler_id)
        window.disconnect(hide_handler_id)
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)
Exemple #16
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
Exemple #17
0
def test_backward_stepping_library_state(caplog):
    testing_utils.run_gui(gui_config={'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False},
                          libraries={'unit_test': os.path.join(testing_utils.TESTS_PATH, 'assets',
                                                               'unit_test_state_machines',
                                                               'backward_step_library_execution_test', 'test_library')
                                     }
                          )
    call_gui_callback(initialize_global_variables)
    try:
        execute_library_state_forwards_backwards()
    except Exception:
        raise
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Exemple #18
0
def patch_notifications():
    enable_debugging()
    # call_gui_callback(create_bigger_state_machine)
    # call_gui_callback(create_small_state_machine)
    from gui.widget.test_storage import create_models
    call_gui_callback(create_models)
    show_debug_graph()
    disable_debugging()

    from testing_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'))
Exemple #19
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
Exemple #20
0
def test_simple_state_size_resize(state_path, recursive, rel_size, caplog,
                                  monkeypatch):
    testing_utils.run_gui(gui_config={'HISTORY_ENABLED': True})

    try:
        from rafcon.gui.helpers.meta_data import check_gaphas_state_meta_data_consistency
        sm_m, canvas, view = open_test_state_machine()

        state_m = sm_m.get_state_model_by_path(state_path)
        state_v = canvas.get_view_for_model(state_m)

        orig_state_size = state_m.get_meta_data_editor()["size"]
        check_gaphas_state_meta_data_consistency(state_m,
                                                 canvas,
                                                 recursive=True)
        print "\ninitial:"
        print_state_sizes(state_m, canvas, ["C"])

        view_rel_size = transform_size_v2i(view, state_v, rel_size)
        resize_state(view, state_v, rel_size, 3, recursive, monkeypatch)
        new_state_size = add_vectors(orig_state_size, view_rel_size)
        print "\nfirst resize:"
        print_state_sizes(state_m, canvas, ["C"])
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    new_state_size, canvas)

        rel_size = (-rel_size[0], -rel_size[1])
        view_rel_size = transform_size_v2i(view, state_v, rel_size)
        resize_state(view, state_v, rel_size, 3, recursive, monkeypatch)
        print "\nsecond resize:"
        print_state_sizes(state_m, canvas, ["C"])
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    orig_state_size, canvas)

        call_gui_callback(sm_m.history.undo)
        print "\nfirst undo:"
        print_state_sizes(state_m, canvas, ["C"])
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    new_state_size, canvas)

        call_gui_callback(sm_m.history.undo)
        print "\nsecond undo:"
        print_state_sizes(state_m, canvas, ["C"])
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    orig_state_size, canvas)

        call_gui_callback(sm_m.history.redo)
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    new_state_size, canvas)

        call_gui_callback(sm_m.history.redo)
        assert_state_size_and_meta_data_consistency(state_m, state_v,
                                                    orig_state_size, canvas)

    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Exemple #21
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())))
Exemple #22
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)
    testing_utils.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_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()

    call_gui_callback(menubar_ctrl.on_start_activate, None, None)

    testing_utils.wait_for_gui()

    while not state_machine_execution_engine.finished_or_stopped():
        time.sleep(0.1)

    call_gui_callback(menubar_ctrl.on_stop_activate, None)
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")))
Exemple #25
0
def test_drag_and_drop_test(caplog):
    testing_utils.run_gui(
        gui_config={
            'AUTO_BACKUP_ENABLED': False,
            'HISTORY_ENABLED': False
        },
        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 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
Exemple #27
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()
Exemple #28
0
def resize_state(view, state_v, rel_size, num_motion_events, recursive, monkeypatch):
    from gi.repository import Gdk
    from rafcon.gui.mygaphas.tools import MoveHandleTool
    from rafcon.gui.utils.constants import RECURSIVE_RESIZE_MODIFIER
    from gaphas.item import SE, NW

    def get_resize_handle(x, y, distance=None):
        return state_v, state_v.handles()[SE]

    monkeypatch.setattr("rafcon.gui.mygaphas.aspect.StateHandleFinder.get_handle_at_point", get_resize_handle)
    monkeypatch.setattr("rafcon.gui.mygaphas.aspect.ItemHandleFinder.get_handle_at_point", get_resize_handle)
    # Deactivate guides (snapping)
    monkeypatch.setattr("rafcon.gui.mygaphas.guide.GuidedStateMixin.MARGIN", 0)

    resize_tool = call_gui_callback(MoveHandleTool, view)
    start_pos_handle = call_gui_callback(get_state_handle_pos, view, state_v, state_v.handles()[SE])

    # Start resize: Press button
    # Gtk TODO: Check if button can be set like this
    button_press_event = Gdk.Event.new(type=Gdk.EventType.BUTTON_PRESS)
    button_press_event.button = 1
    call_gui_callback(resize_tool.on_button_press, button_press_event)
    # Do resize: Move mouse
    motion_event = Gdk.Event.new(Gdk.EventType.MOTION_NOTIFY)
    motion_event.state = motion_event.get_state()[1] | Gdk.EventMask.BUTTON_PRESS_MASK
    if recursive:
        motion_event.state = motion_event.get_state()[1] | RECURSIVE_RESIZE_MODIFIER
    print("sent motion_event.state", motion_event.get_state())
    for i in range(num_motion_events):
        motion_event.x = start_pos_handle[0] + rel_size[0] * (float(i + 1) / num_motion_events)
        motion_event.y = start_pos_handle[1] + rel_size[1] * (float(i + 1) / num_motion_events)
        call_gui_callback(resize_tool.on_motion_notify, motion_event)

    # Stop resize: Release button
    # Gtk TODO: Check if button can be set like this
    button_release_event = Gdk.Event.new(type=Gdk.EventType.BUTTON_RELEASE)
    button_release_event.button = 1
    call_gui_callback(resize_tool.on_button_release, button_release_event)

    monkeypatch.undo()
    monkeypatch.undo()
    monkeypatch.undo()
Exemple #29
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)
Exemple #30
0
    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)