Ejemplo n.º 1
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 = list(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 = list(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
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)
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)
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)
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)
Ejemplo n.º 7
0
    def get_data_port_m(self, data_port_id):
        """Searches and returns the model of a data port of a given state

        The method searches a port with the given id in the data ports of the given state model. If the state model
        is a container state, not only the input and output data ports are looked at, but also the scoped variables.

        :param data_port_id: The data port id to be searched
        :return: The model of the data port or None if it is not found
        """

        for scoped_var_m in self.scoped_variables:
            if scoped_var_m.scoped_variable.data_port_id == data_port_id:
                return scoped_var_m

        return StateModel.get_data_port_m(self, data_port_id)
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"]