Ejemplo n.º 1
0
def test_remove_from_middle():
    component1 = Component("component1", instrument)
    component2 = Component("component2", instrument)
    component3 = Component("component3", instrument)
    rot1 = component1.add_rotation(
        name="rotation1",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    rot2 = component2.add_rotation(
        name="rotation2",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    rot3 = component3.add_rotation(
        name="rotation3",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    component1.depends_on = rot1
    component2.depends_on = rot2
    component3.depends_on = rot3

    component1.transforms.link.linked_component = component2
    component2.transforms.link.linked_component = component3
    rot2.remove_from_dependee_chain()
    assert rot1.depends_on == rot3
    assert component1.transforms.link.linked_component == component3
    assert rot1 in rot3.dependents
    assert component3 in rot3.dependents
Ejemplo n.º 2
0
def test_end_of_depends_on_chain_of_component_is_linked_to_other_component():
    # GIVEN component has depends_on chain with multiple transformations
    component = Component(name="test_component")
    values = Dataset(parent_node=None, name="", type=ValueTypes.INT, values=[42])
    transforms_2 = component.add_translation(
        name="transform2",
        vector=QVector3D(0, 0, 1.0),  # default to beam direction
        values=values,
    )
    transform_1 = component.add_translation(
        name="transform1",
        vector=QVector3D(0, 0, 1.0),  # default to beam direction
        values=values,
        depends_on=transforms_2,
    )
    component.depends_on = transform_1

    # WHEN it is linked to another component
    another_component = Component(name="another_test_component")
    transform_3 = another_component.add_translation(
        name="transform3",
        vector=QVector3D(0, 0, 1.0),  # default to beam direction
        values=values,
    )
    another_component.depends_on = transform_3
    component.transforms.link.linked_component = another_component

    # THEN it is the last component of the depends_on chain which has its depends_on property updated
    assert transforms_2.depends_on == transform_3
Ejemplo n.º 3
0
def test_remove_from_beginning_3(instrument):
    component1 = Component("component1", instrument)
    component2 = Component("component2", instrument)
    rot1 = component1.add_rotation(
        name="rotation1",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    rot2 = component2.add_rotation(
        name="rotation2",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    component1.depends_on = rot1
    component2.depends_on = rot2
    rot1.depends_on = rot2
    assert len(rot2.dependents) == 2
    rot1.remove_from_dependee_chain()
    assert len(rot2.dependents) == 2
    assert component2 in rot2.dependents
    assert component1 in rot2.dependents
    assert component1.depends_on == rot2
    assert component1.transforms.link.linked_component == component2
Ejemplo n.º 4
0
def test_remove_from_end():
    component1 = Component("component1", instrument)
    rot1 = component1.add_rotation(
        name="rotation1",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    rot2 = component1.add_rotation(
        name="rotation2",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
        depends_on=rot1,
    )
    rot3 = component1.add_rotation(
        name="rotation3",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
        depends_on=rot2,
    )

    component1.depends_on = rot3

    rot1.remove_from_dependee_chain()

    assert rot1.depends_on is None
    assert not rot1.dependents

    assert component1.depends_on == rot3

    assert rot2.dependents[0] == rot3
    assert len(component1.transforms) == 2
Ejemplo n.º 5
0
def test_remove_from_beginning_1(instrument):
    component1 = Component("component1", instrument)
    rot = component1.add_rotation(
        name="rotation1",
        axis=QVector3D(1.0, 0.0, 0.0),
        angle=values.values,
        values=values,
    )
    component1.depends_on = rot
    assert len(rot.dependents) == 1
    rot.remove_from_dependee_chain()
    assert component1.depends_on is None
Ejemplo n.º 6
0
def component_with_transformation() -> Component:
    comp = Component(name="Component")
    transformation = comp.add_rotation(
        name="Transformation",
        angle=90,
        axis=QVector3D(1, 0, 0),
        depends_on=None,
        values=Dataset(
            parent_node=False, name="test", values=123, type=ValueTypes.DOUBLE
        ),
    )
    comp.depends_on = transformation
    return comp
Ejemplo n.º 7
0
def test_component_as_dict_contains_transformations():
    zeroth_transform_name = "test_transform_A"
    first_transform_name = "test_transform_B"
    test_component = Component(name="test_component")

    first_transform = test_component.add_translation(
        name=first_transform_name, vector=QVector3D(1, 0, 0)
    )
    zeroth_transform = test_component.add_translation(
        name=zeroth_transform_name,
        vector=QVector3D(0, 0, 1),
        depends_on=first_transform,
    )
    test_component.depends_on = zeroth_transform
    dictionary_output = test_component.as_dict([])

    assert dictionary_output["children"][0]["name"] == TRANSFORMS_GROUP_NAME
    child_names = [
        child["config"]["name"]
        for child in dictionary_output["children"][0]["children"]
    ]
    assert zeroth_transform_name in child_names
    assert first_transform_name in child_names