Esempio n. 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))
Esempio n. 2
0
def test_core_create_folder(monkeypatch):
    """Tests `create_folder_cmd_line` function from `rafcon.core.interface`"""
    testing_utils.dummy_gui(None)
    print("execute test_core_create_folder")
    import rafcon.core.interface as core_interface
    # replaces raw_input by an expression that returns RAFCON_TEMP_PATH_TEST_BASE
    monkeypatch.setattr(core_interface, 'input',
                        lambda _: RAFCON_TEMP_PATH_TEST_BASE)

    # Return user input
    assert core_interface.create_folder_cmd_line(
        "query") == RAFCON_TEMP_PATH_TEST_BASE
    # Return user input despite default path given
    assert core_interface.create_folder_cmd_line(
        "query", "/home") == RAFCON_TEMP_PATH_TEST_BASE
    assert core_interface.create_folder_cmd_line(
        "query", "new", "/home") == RAFCON_TEMP_PATH_TEST_BASE

    # replaces raw_input by an expression that returns ""
    monkeypatch.setattr(core_interface, 'input', lambda _: "")

    # Return None if no user input and no default path
    assert core_interface.create_folder_cmd_line("query") is None
    # Return default path if no user input is given
    assert core_interface.create_folder_cmd_line(
        "query", "new_folder",
        RAFCON_TEMP_PATH_TEST_BASE) == os.path.join(RAFCON_TEMP_PATH_TEST_BASE,
                                                    "new_folder")
    # Return None if no user input and default path cannot be created (without root permissions)
    assert core_interface.create_folder_cmd_line("query", "new_folder",
                                                 "/root/not/writable") is None
    # Return None if no user input and insufficient path information given
    assert core_interface.create_folder_cmd_line("query", "new_folder") is None
Esempio n. 3
0
def test_focus():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.selection import Selection

    selection = Selection()
    focus_signal_observer = SignalCounter(selection, "focus_signal")
    selection_signal_observer = SignalCounter(selection, "selection_changed_signal")
    states_m, outcomes_e_m, outcomes_h_m = get_models()
    root_state_m, execution_state_m, hierarchy_state_m, child_state_m = states_m

    assert len(selection) == 0

    # Set focus
    selection.focus = execution_state_m
    assert selection.focus is execution_state_m
    assert len(selection) == 1
    assert len(selection.states) == 1
    assert focus_signal_observer.count == 1
    assert selection_signal_observer.count == 1

    # Set focus to same element
    selection.focus = execution_state_m
    assert selection.focus is execution_state_m
    assert len(selection) == 1
    assert len(selection.states) == 1
    assert focus_signal_observer.count == 2
    assert selection_signal_observer.count == 1

    # Clear selection => causes focus to me removed
    selection.clear()
    assert selection.focus is None
    assert len(selection) == 0
    assert len(selection.states) == 0
    assert focus_signal_observer.count == 3
    assert selection_signal_observer.count == 2
Esempio n. 4
0
def test_gui_open_folder(monkeypatch):
    """Tests `open_folder` function from `rafcon.core.interface`"""
    testing_utils.dummy_gui(None)
    print "execute test_gui_open_folder"
    import rafcon.gui.interface as gui_interface
    # prepare FileChooserDialog for monkey-patching
    monkeypatch.setattr(gtk, "FileChooserDialog", PatchedFileChooserDialog)
    # replaces run by an expression that returns gtk.RESPONSE_OK
    monkeypatch.setattr(gtk.FileChooserDialog, 'run',
                        lambda _: gtk.RESPONSE_OK)
    # replaces get_filename by an expression that returns "/tmp"
    monkeypatch.setattr(gtk.FileChooserDialog, 'get_filename',
                        lambda _: "/tmp")

    # Return user input
    assert gui_interface.open_folder("query") == "/tmp"
    # Return user input despite default path given
    assert gui_interface.open_folder("query", "/home") == "/tmp"

    # replaces run by an expression that returns gtk.RESPONSE_CANCEL
    monkeypatch.setattr(gtk.FileChooserDialog, 'run',
                        lambda _: gtk.RESPONSE_CANCEL)

    # Return None if no user input and no default path
    assert gui_interface.open_folder("query") is None
    # Return default path if no user input is given
    assert gui_interface.open_folder("query", "/tmp") == "/tmp"
    # Return None if no user input and default path does not exist
    assert gui_interface.open_folder("query", "/non/existing/path") is None
Esempio n. 5
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")
Esempio n. 6
0
def test_value_retrieval():

    testing_utils.dummy_gui(None)

    from rafcon.gui.mygaphas.utils.cache.value_cache import ValueCache
    cache = ValueCache()

    cache.store_value("a", 1, {})
    assert 1 == cache.get_value("a", {})
    assert None is cache.get_value("a", {"par": 2})

    cache.store_value("b", 2, {"x": 1, "y": 2})
    assert 2 == cache.get_value("b", {"x": 1, "y": 2})
    assert None is cache.get_value("b", {})
    assert None is cache.get_value("b", {"par": 2})
    assert None is cache.get_value("b", {"x": 2, "y": 2})
    assert None is cache.get_value("b", {"x": 1, "y": 2, "z": 3})
    assert None is cache.get_value("b", {"x": 1})

    cache.store_value("b", 3, {"x": 1, "y": 2})
    assert 3 == cache.get_value("b", {"x": 1, "y": 2})
    cache.store_value("b", 4, {"x": 2, "y": 1})
    assert 4 == cache.get_value("b", {"x": 2, "y": 1})
    assert 3 is cache.get_value("b", {"x": 1, "y": 2})

    cache.empty()
    assert None is cache.get_value("a", {})
    assert None is cache.get_value("b", {"x": 2, "y": 1})
    assert None is cache.get_value("b", {"x": 1, "y": 2})
Esempio n. 7
0
def test_multiple_future_element():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.hierarchy_state import HierarchyState
    from rafcon.core.states.execution_state import ExecutionState
    from rafcon.gui.models.state import StateModel
    from rafcon.gui.models.container_state import ContainerStateModel
    parent_state = HierarchyState()
    parent_state_m = ContainerStateModel(parent_state)

    child_state_a = ExecutionState("A")
    child_state_a_m = StateModel(child_state_a)
    child_state_b = ExecutionState("B")
    child_state_b_m = StateModel(child_state_b)

    parent_state_m.expected_future_models.add(child_state_a_m)
    parent_state_m.expected_future_models.add(child_state_b_m)

    parent_state.add_state(child_state_a)

    assert len(parent_state_m.states) == 1
    new_child_state_a_m = parent_state_m.states.values()[0]
    assert new_child_state_a_m is child_state_a_m
    assert new_child_state_a_m.core_element is child_state_a
    assert len(parent_state_m.expected_future_models) == 1

    parent_state.add_state(child_state_b)

    assert len(parent_state_m.states) == 2
    new_child_states_m = parent_state_m.states.values()
    assert new_child_states_m[0] is child_state_b_m or new_child_states_m[
        1] is child_state_b_m
    assert new_child_states_m[
        0].core_element is child_state_b or new_child_states_m[
            1].core_element is child_state_b
    assert len(parent_state_m.expected_future_models) == 0
Esempio n. 8
0
def test_start_script_valid_rmpm_env():
    """Tests the execution of rafcon_start in an environment created by RMPM
    """
    # TODO: replace rafcon_start with rafcon_core after the next release
    testing_utils.dummy_gui(None)
    import distutils.spawn
    rmpm_env = os.environ.copy()
    rmpm_env[
        "PATH"] = "/volume/software/common/packages/rmpm/latest/bin/{}:".format(
            os.getenv("DLRRM_HOST_PLATFORM",
                      "osl42-x86_64")) + rmpm_env["PATH"]
    if not distutils.spawn.find_executable("rmpm_do"):
        print "Could not find rmpm_do, skipping test"
    start_path = testing_utils.get_test_sm_path(
        join("unit_test_state_machines", "start_script_test"))
    config = join(testing_utils.TESTS_PATH, "assets", "configs",
                  "valid_config", "config.yaml")
    cmd = "eval `rmpm_do env --env-format=embed_sh sw.common.rafcon` && rafcon_start -o {0} -c {1}" \
          "".format(start_path, config)
    print "\ntest_start_script_valid_config: \n", cmd
    rafcon_process = subprocess.Popen(cmd,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      env=rmpm_env)
    rafcon_process.wait()
    output = rafcon_process.communicate()[0]
    print "LOG: \n", output
    assert rafcon_process.returncode == 0
Esempio n. 9
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)
Esempio n. 10
0
def test_meta_list_modification():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_data = meta_m.set_meta_data_editor("list", [1, 2, 3])
    assert meta_data["list"] == [1, 2, 3]
    meta_data = meta_m.set_meta_data_editor("list.0", 4)
    assert meta_data["list"] == [4, 2, 3]
Esempio n. 11
0
def test_all_models():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.core.state_elements.data_port import InputDataPort, OutputDataPort
    from rafcon.core.state_elements.scope import ScopedVariable
    from rafcon.core.state_elements.outcome import Outcome
    from rafcon.core.state_elements.transition import Transition
    from rafcon.core.state_elements.data_flow import DataFlow

    from rafcon.gui.models.selection import Selection
    from rafcon.gui.models.data_port import DataPortModel
    from rafcon.gui.models.scoped_variable import ScopedVariableModel
    from rafcon.gui.models.transition import TransitionModel
    from rafcon.gui.models.data_flow import DataFlowModel

    selection = Selection()
    states_m, outcomes_e_m, outcomes_h_m = get_models()

    input_data_port = InputDataPort("i")
    input_data_port_m = DataPortModel(input_data_port, parent=None)
    output_data_port = OutputDataPort("o")
    output_data_port_m = DataPortModel(output_data_port, parent=None)
    scoped_variable = ScopedVariable("sv")
    scoped_variable_m = ScopedVariableModel(scoped_variable, parent=None)

    transition = Transition("0", 0, "1", 0, 0)
    transition_m = TransitionModel(transition, parent=None)
    data_flow = DataFlow("0", 0, "1", 0, 0)
    data_flow_m = DataFlowModel(data_flow, parent=None)

    selection.add(states_m[3])  # child_state_m
    selection.add(outcomes_e_m)
    selection.add(outcomes_h_m)
    selection.add((input_data_port_m, output_data_port_m, scoped_variable_m))
    selection.add(transition_m)
    selection.add(data_flow_m)

    assert len(selection) == 10
    assert len(selection.states) == 1
    assert len(selection.outcomes) == 4
    assert len(selection.input_data_ports) == 1
    assert len(selection.output_data_ports) == 1
    assert len(selection.scoped_variables) == 1
    assert len(selection.data_flows) == 1
    assert len(selection.transitions) == 1
    assert selection.states == selection.get_selected_elements_of_core_class(State)
    assert selection.outcomes == selection.get_selected_elements_of_core_class(Outcome)
    assert selection.input_data_ports == selection.get_selected_elements_of_core_class(InputDataPort)
    assert selection.output_data_ports == selection.get_selected_elements_of_core_class(OutputDataPort)
    assert selection.scoped_variables == selection.get_selected_elements_of_core_class(ScopedVariable)
    assert selection.data_flows == selection.get_selected_elements_of_core_class(DataFlow)
    assert selection.transitions == selection.get_selected_elements_of_core_class(Transition)

    selection.clear()

    assert 0 == len(selection) == len(selection.states) == len(selection.outcomes) == len(selection.input_data_ports)\
             == len(selection.output_data_ports) == len(selection.scoped_variables) == len(selection.data_flows)\
             == len(selection.transitions)
def test_income():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_opengl"]["size"] = (50, 50)
    meta_data = state_m.get_meta_data_editor(for_gaphas=True)
    assert meta_data["income"]["rel_pos"] == (0, 25)
Esempio n. 13
0
def test_meta_initialization():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel(meta={"1": 2, "2": 1})
    assert meta_m.meta == {"1": 2, "2": 1}

    meta_m = MetaModel(meta={'gui': {'editor_gaphas': {"1": 2, "2": 1}}})
    meta_data = meta_m.get_meta_data_editor()
    assert meta_data == {"1": 2, "2": 1}
Esempio n. 14
0
def test_meta_setter_return_value():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_data = meta_m.set_meta_data_editor("key", "value")
    assert meta_data["key"] == "value"

    meta_data = meta_m.set_meta_data_editor("key2", "value2")
    assert meta_data["key"] == "value"
    assert meta_data["key2"] == "value2"
def test_state_rel_pos(use_gaphas):
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_opengl" if use_gaphas else "editor_gaphas"][
        "rel_pos"] = (1, 2)
    meta_data = state_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["rel_pos"] == (1, -2)
Esempio n. 16
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)
Esempio n. 17
0
def test_slim_observer(caplog):
    testing_utils.dummy_gui(None)
    test_observer = ObserverTest()
    test_observer.test_observable.first_var = 20.0
    assert test_observer.test_value == 20

    test_observer.test_observable.complex_method(1, 3, "Hello world")
    assert test_observer.test_observable.observable_test_var == 4
    assert test_observer.test_value2 == 4
    assert test_observer.test_value3 == 30

    testing_utils.assert_logger_warnings_and_errors(caplog)
def test_transition_waypoints(use_gaphas):
    testing_utils.dummy_gui(None)
    from rafcon.core.state_elements.transition import Transition
    from rafcon.gui.models.transition import TransitionModel
    transition = Transition(None, 0, None, 0, None)
    transition_m = TransitionModel(transition, parent=None)
    transition_m.meta["gui"][
        "editor_opengl" if use_gaphas else "editor_gaphas"]["waypoints"] = [
            (1, 2), (-1, 3)
        ]
    meta_data = transition_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["waypoints"] == [(1, -2), (-1, -3)]
Esempio n. 19
0
def test_state_machine_baking(caplog):
    testing_utils.dummy_gui(caplog)

    testing_utils.run_gui(
        gui_config={'HISTORY_ENABLED': False, 'AUTO_BACKUP_ENABLED': False},
        libraries={'unit_test_state_machines': testing_utils.get_test_sm_path("unit_test_state_machines")}
    )
    try:
        trigger_baking_commands()
    finally:
        testing_utils.close_gui()
        testing_utils.shutdown_environment(caplog=caplog)
Esempio n. 20
0
def test_editor_setter_getter_conversion(use_gaphas):
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_m.meta["gui"]["editor_opengl" if use_gaphas else "editor_gaphas"][
        "test"] = (1, 2)
    meta_data = meta_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["test"] == (1, 2)

    assert_single_editor_meta_data(meta_m, gaphas=use_gaphas)
    assert meta_m.meta["gui"][
        "editor_gaphas" if use_gaphas else "editor_opengl"]["test"] == (1, 2)
def test_scoped_variable_opengl2gaphas():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.hierarchy_state import HierarchyState
    from rafcon.gui.models.container_state import ContainerStateModel
    state = HierarchyState()
    state.add_scoped_variable("sv", int, 0)
    state_m = ContainerStateModel(state, parent=None)
    state_m.meta["gui"]["editor_opengl"]["size"] = (100, 100)
    state_m.get_meta_data_editor(for_gaphas=True)
    scoped_var_m = state_m.scoped_variables[0]
    scoped_var_m.meta["gui"]["editor_opengl"]["inner_rel_pos"] = (70, 30)
    rel_pos = scoped_var_m.get_meta_data_editor(for_gaphas=True)["rel_pos"]
    assert rel_pos == (70, 0)
def test_output_gaphas2opengl():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state.add_output_data_port("out", int, 0)
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_gaphas"]["size"] = (100, 100)
    state_m.get_meta_data_editor(for_gaphas=False)
    output_m = state_m.output_data_ports[0]
    output_m.meta["gui"]["editor_gaphas"]["rel_pos"] = (100, 50)
    rel_pos = output_m.get_meta_data_editor(for_gaphas=False)["inner_rel_pos"]
    assert rel_pos == (100, -50)
def test_input_opengl2gaphas():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state.add_input_data_port("in", int, 0)
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_opengl"]["size"] = (100, 100)
    state_m.get_meta_data_editor(for_gaphas=True)
    input_m = state_m.input_data_ports[0]
    input_m.meta["gui"]["editor_opengl"]["inner_rel_pos"] = (20, -30)
    rel_pos = input_m.get_meta_data_editor(for_gaphas=True)["rel_pos"]
    assert rel_pos == (0, 30)
Esempio n. 24
0
def test_gui_create_folder(monkeypatch):
    """Tests `create_folder` function from `rafcon.core.interface`"""
    testing_utils.dummy_gui(None)
    print("execute test_gui_create_folder")
    import rafcon.gui.interface as gui_interface
    import gi
    gi.require_version('Gtk', '3.0')
    from gi.repository import Gtk

    class PatchedFileChooserDialog(Gtk.FileChooserDialog):
        """Subclass for FileChooserDialog

        FileChooserDialog cannot be monkey-patched directly. It must first be replaced by a subclass, which is this one.
        """
        pass

    # prepare FileChooserDialog for monkey-patching
    monkeypatch.setattr(Gtk, "FileChooserDialog", PatchedFileChooserDialog)
    # replaces run by an expression that returns Gtk.ResponseType.OK
    monkeypatch.setattr(Gtk.FileChooserDialog, 'run',
                        lambda _: Gtk.ResponseType.OK)
    # replaces get_filename by an expression that returns "/tmp"
    monkeypatch.setattr(Gtk.FileChooserDialog, 'get_filename',
                        lambda _: RAFCON_TEMP_PATH_TEST_BASE)

    # Return user input
    assert gui_interface.create_folder("query") == RAFCON_TEMP_PATH_TEST_BASE
    # Return user input despite default path given
    assert gui_interface.create_folder("query",
                                       "/home") == RAFCON_TEMP_PATH_TEST_BASE
    assert gui_interface.create_folder("query", "new",
                                       "/home") == RAFCON_TEMP_PATH_TEST_BASE

    # replaces run by an expression that returns Gtk.ResponseType.CANCEL
    monkeypatch.setattr(Gtk.FileChooserDialog, 'run',
                        lambda _: Gtk.ResponseType.CANCEL)

    # Return None if no user input and no default path
    assert gui_interface.create_folder("query") is None
    # Return default path if no user input is given
    assert gui_interface.create_folder(
        "query", "new_folder",
        RAFCON_TEMP_PATH_TEST_BASE) == os.path.join(RAFCON_TEMP_PATH_TEST_BASE,
                                                    "new_folder")
    # Return None if no user input and default path cannot be created (without root permissions)
    assert gui_interface.create_folder("query", "new_folder",
                                       "/root/not/writable") is None
    # Return None if no user input and insufficient path information given
    assert gui_interface.create_folder("query", "new_folder") is None
Esempio n. 25
0
def test_start_script_print_help_with_gui():
    """ Test rafcon_start_gui console call which run a RAFCON instance and let it print the helper message and checks
    if the process terminates correctly.
    """
    testing_utils.dummy_gui(None)
    script = join(testing_utils.RAFCON_PATH, "gui", "start.py")
    # start_path = testing_utils.get_test_sm_path(join("unit_test_state_machines", "start_script_test"))
    # cmd = "%s -o %s" % (script, start_path)
    cmd = script + " -h"
    print "\ntest_start_script_open_with_gui: ", cmd
    rafcon_gui_process = subprocess.Popen(cmd, shell=True)
    print "process PID: ", rafcon_gui_process.pid
    # rafcon_gui_process.terminate()
    rafcon_gui_process.wait()
    assert rafcon_gui_process.returncode == 0
Esempio n. 26
0
def test_default():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.hierarchy_state import HierarchyState
    from rafcon.core.states.execution_state import ExecutionState
    from rafcon.gui.models.container_state import ContainerStateModel
    parent_state = HierarchyState()
    parent_state_m = ContainerStateModel(parent_state)

    child_state_a = ExecutionState("A")

    parent_state.add_state(child_state_a)

    assert len(parent_state_m.states) == 1
    child_state_a_m = parent_state_m.states.values()[0]
    assert child_state_a_m.core_element is child_state_a
def test_state_property_deletion():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_gaphas"]["income"]["rel_pos"] = (0, 50)
    state_m.meta["gui"]["editor_gaphas"]["name"]["rel_pos"] = (10, 10)
    state_m.meta["gui"]["editor_gaphas"]["name"]["size"] = (200, 100)
    meta_data = state_m.get_meta_data_editor(for_gaphas=False)
    assert "income" not in meta_data
    assert "income" not in state_m.meta["gui"]["editor_gaphas"]
    assert "income" not in state_m.meta["gui"]["editor_opengl"]
    assert "name" not in meta_data
    assert "name" not in state_m.meta["gui"]["editor_gaphas"]
    assert "name" not in state_m.meta["gui"]["editor_opengl"]
def test_3_outcomes():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.state import StateModel
    state = State()
    state_m = StateModel(state, parent=None)
    state_m.meta["gui"]["editor_opengl"]["size"] = (60, 60)
    state_m.get_meta_data_editor(for_gaphas=True)

    for outcome_m in state_m.outcomes:
        outcome = outcome_m.outcome
        outcome_pos = outcome_m.get_meta_data_editor()["rel_pos"]
        if outcome.outcome_id == -1:
            assert outcome_pos == (54, 0)
        elif outcome.outcome_id == -2:
            assert outcome_pos == (42, 0)
        else:
            assert outcome_pos == (60, 30)
Esempio n. 29
0
def test_start_script_open():
    """ Test core.start.py script run on console which open a state machine, run it and final checks the output file on
    consistency.
    """
    testing_utils.dummy_gui(None)

    script = join(testing_utils.RAFCON_PATH, "core", "start.py")
    start_path = testing_utils.get_test_sm_path(
        join("unit_test_state_machines", "start_script_test"))
    cmd = "%s -o %s" % (script, start_path)
    print "\ntest_start_script_open: \n", cmd
    cmd_res = subprocess.call(cmd, shell=True)
    assert cmd_res == 0
    tmp_file = open(FILE_MODIFIED_BY_STATE_MACHINE, "r")
    res = tmp_file.read()
    tmp_file.close()
    assert (res == "start, state, "), "start script failed"
    os.remove(FILE_MODIFIED_BY_STATE_MACHINE)
Esempio n. 30
0
def test_start_script_state():
    """ Test core.start.py script run by python call which open a state machine, run from a specific state and  final
    checks the output file on consistency.
    """
    testing_utils.dummy_gui(None)
    script = join(testing_utils.RAFCON_PATH, "core", "start.py")
    start_path = testing_utils.get_test_sm_path(
        join("unit_test_state_machines", "start_script_test"))
    state_path = "UTUOSC/AHWBOG"
    print start_path
    cmd = sys.executable + " %s -o %s -s %s" % (script, start_path, state_path)
    print "\ntest_start_script_state: \n", cmd
    cmd_res = subprocess.call(cmd, shell=True)
    assert cmd_res == 0
    tmp_file = open(FILE_MODIFIED_BY_STATE_MACHINE, "r")
    res = tmp_file.read()
    tmp_file.close()
    assert (res == "state, "), "start from state failed"
    os.remove(FILE_MODIFIED_BY_STATE_MACHINE)