def test_add_component():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    assert under_test.rowCount(QModelIndex()) == 0
    under_test.add_component(get_component())

    assert under_test.rowCount(QModelIndex()) == 1
def test_remove_component(nexus_wrapper):
    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    assert under_test.rowCount(QModelIndex()) == 1
    under_test.remove_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 0
def test_rowCount_gets_unknown_type():
    data_under_test = FakeInstrument()
    under_test = ComponentTreeModel(data_under_test)

    test_index = under_test.createIndex(0, 0, {})

    with pytest.raises(RuntimeError):
        under_test.rowCount(test_index)
def test_duplicate_component():
    data_under_test = Instrument(
        NexusWrapper("test_component_model_duplicate"), NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(data_under_test)

    assert under_test.rowCount(QModelIndex()) == 1  # Sample
    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.duplicate_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 3
def test_add_transformation_alt_1():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    transformation_list_index = under_test.index(1, 0, component_index)
    assert under_test.rowCount(transformation_list_index) == 0
    under_test.add_translation(transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
def test_remove_transformation(nexus_wrapper):
    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_rotation(component_index)
    transformation_list_index = under_test.index(1, 0, component_index)
    transformation_index = under_test.index(0, 0, transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    under_test.remove_node(transformation_index)
    assert under_test.rowCount(transformation_list_index) == 0
def test_remove_component_with_transformation(nexus_wrapper):
    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_rotation(component_index)
    assert under_test.rowCount(QModelIndex()) == 1
    under_test.remove_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 0, (
        "Expected component to be successfully deleted because it has "
        "a transformation that only has it as a dependent")
def test_add_link_alt_2():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    transformation_list_index = under_test.index(1, 0, component_index)
    assert under_test.rowCount(transformation_list_index) == 0
    under_test.add_link(transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    assert transformation_list_index.internalPointer().has_link
    assert len(transformation_list_index.internalPointer()) == 0
def test_add_translation():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    transformation_list_index = under_test.index(1, 0, component_index)
    assert under_test.rowCount(transformation_list_index) == 0
    under_test.add_translation(component_index)
    assert under_test.rowCount(transformation_list_index) == 1
    transform_index = under_test.index(0, 0, transformation_list_index)
    assert transform_index.internalPointer().type == "Translation"
Пример #10
0
def test_remove_link():
    wrapper = NexusWrapper("test_remove_link")
    instrument = Instrument(wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_link(component_index)
    transformation_list_index = under_test.index(1, 0, component_index)
    transformation_index = under_test.index(0, 0, transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    assert len(transformation_list_index.internalPointer()) == 0
    under_test.remove_node(transformation_index)
    assert under_test.rowCount(transformation_list_index) == 0
def test_component_has_2_rows():
    data_under_test = FakeInstrument([get_component()])
    under_test = ComponentTreeModel(data_under_test)

    test_index = under_test.createIndex(0, 0, data_under_test[0])

    assert under_test.rowCount(test_index) == 2
def test_number_of_components_2():
    data_under_test = FakeInstrument([get_component(), get_component()])
    under_test = ComponentTreeModel(data_under_test)

    test_index = QModelIndex()

    assert under_test.rowCount(test_index) == 2
def test_GIVEN_component_with_cylindrical_shape_information_WHEN_duplicating_component_THEN_shape_information_is_stored_in_nexus_file(
    nexus_wrapper, ):

    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)

    first_component_name = "component1"
    first_component_nx_class = "NXdetector"
    description = "desc"
    first_component = instrument.create_component(first_component_name,
                                                  first_component_nx_class,
                                                  description)

    axis_direction = QVector3D(1, 0, 0)
    height = 2
    radius = 3
    units = "cm"
    first_component.set_cylinder_shape(axis_direction=axis_direction,
                                       height=height,
                                       radius=radius,
                                       units=units)
    tree_model = ComponentTreeModel(instrument)

    first_component_index = tree_model.index(0, 0, QModelIndex())
    tree_model.duplicate_node(first_component_index)

    assert tree_model.rowCount(QModelIndex()) == 3
    second_component_index = tree_model.index(2, 0, QModelIndex())
    second_component = second_component_index.internalPointer()
    second_shape, _ = second_component.shape
    assert second_shape.axis_direction == axis_direction
    assert second_shape.height == height
    assert second_shape.units == units
def test_transformation_list_has_0_rows():
    data_under_test = FakeInstrument([get_component()])
    under_test = ComponentTreeModel(data_under_test)

    data_under_test[0].stored_transforms = data_under_test[0].transforms

    test_index = under_test.createIndex(0, 0,
                                        data_under_test[0].stored_transforms)

    assert under_test.rowCount(test_index) == 0
def test_transformation_link_has_0_rows():
    component = get_component()
    translation = component.add_translation(QVector3D(1.0, 0.0, 0.0))
    component.depends_on = translation
    data_under_test = FakeInstrument([component])
    component.stored_transforms = component.transforms
    under_test = ComponentTreeModel(data_under_test)

    test_index = under_test.createIndex(0, 0, component.stored_transforms[0])

    assert under_test.rowCount(test_index) == 0
Пример #16
0
def test_GIVEN_component_with_off_shape_information_WHEN_duplicating_component_THEN_shape_information_is_stored_in_nexus_file(
):
    wrapper = NexusWrapper("test_duplicate_off_shape")
    instrument = Instrument(wrapper, NX_CLASS_DEFINITIONS)

    first_component_name = "component1"
    first_component_nx_class = "NXdetector"
    description = "desc"
    first_component = instrument.create_component(first_component_name,
                                                  first_component_nx_class,
                                                  description)

    vertices = [
        QVector3D(-0.5, -0.5, 0.5),
        QVector3D(0.5, -0.5, 0.5),
        QVector3D(-0.5, 0.5, 0.5),
        QVector3D(0.5, 0.5, 0.5),
        QVector3D(-0.5, 0.5, -0.5),
        QVector3D(0.5, 0.5, -0.5),
        QVector3D(-0.5, -0.5, -0.5),
        QVector3D(0.5, -0.5, -0.5),
    ]

    faces = [
        [0, 1, 3, 2],
        [2, 3, 5, 4],
        [4, 5, 7, 6],
        [6, 7, 1, 0],
        [1, 7, 5, 3],
        [6, 0, 2, 4],
    ]

    first_component.set_off_shape(
        OFFGeometryNoNexus(vertices=vertices, faces=faces))

    tree_model = ComponentTreeModel(instrument)

    first_component_index = tree_model.index(0, 0, QModelIndex())
    tree_model.duplicate_node(first_component_index)

    assert tree_model.rowCount(QModelIndex()) == 3
    second_component_index = tree_model.index(2, 0, QModelIndex())
    second_component = second_component_index.internalPointer()
    second_shape, _ = second_component.shape

    assert second_shape.vertices == vertices
    assert second_shape.faces == faces