Exemple #1
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
Exemple #2
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