Example #1
0
File: shapes.py Project: cplab/ceed
def assert_add_three_groups(
        shape_factory: CeedPaintCanvasBehavior = None,
        app: CeedTestApp = None, show_in_gui=False):
    shape, shape2, shape3 = assert_add_three_shapes(
        shape_factory, app, show_in_gui)
    assert not shape_factory.groups
    assert not shape_factory.shape_group_names

    group = shape_factory.add_group()
    group2 = shape_factory.add_group()
    group3 = shape_factory.add_group()

    group.add_shape(shape.shape)
    group.add_shape(shape2.shape)
    group2.add_shape(shape2.shape)
    group2.add_shape(shape3.shape)
    group3.add_shape(shape.shape)
    group3.add_shape(shape2.shape)
    group3.add_shape(shape3.shape)

    assert shape_factory.groups == [group, group2, group3]
    assert len(shape_factory.groups) == 3
    assert len(shape_factory.shape_group_names) == 3
    for g in (group, group2, group3):
        assert shape_factory.shape_group_names[g.name] is g

    assert group.shapes == [shape.shape, shape2.shape]
    assert group2.shapes == [shape2.shape, shape3.shape]
    assert group3.shapes == [shape.shape, shape2.shape, shape3.shape]

    return (group, group2, group3), (shape, shape2, shape3)
Example #2
0
def test_add_remove_group(shape_factory: CeedPaintCanvasBehavior):
    assert not shape_factory.groups
    assert not shape_factory.shape_group_names

    # first group
    shape_factory.test_changes_count = 0
    group = shape_factory.add_group()

    assert isinstance(group, CeedShapeGroup)
    assert len(shape_factory.groups) == 1
    assert len(shape_factory.shape_group_names) == 1
    assert group in shape_factory.groups
    assert group.name in shape_factory.shape_group_names
    assert group is shape_factory.shape_group_names[group.name]
    assert shape_factory.test_changes_count

    # add second group
    shape_factory.test_changes_count = 0
    group2 = shape_factory.add_group()

    assert shape_factory.groups == [group, group2]
    assert shape_factory.shape_group_names == {
        group.name: group,
        group2.name: group2
    }
    assert shape_factory.test_changes_count

    # remove first group
    shape_factory.test_changes_count = 0
    shape_factory.test_changes_remove_group_count = 0
    assert shape_factory.remove_group(group)

    assert shape_factory.test_changes_count
    assert shape_factory.test_changes_remove_group_count
    assert shape_factory.groups == [group2]
    assert shape_factory.shape_group_names == {group2.name: group2}

    # add back first group
    shape_factory.test_changes_count = 0
    assert shape_factory.add_group(group) is group

    assert shape_factory.groups == [group2, group]
    assert shape_factory.shape_group_names == {
        group.name: group,
        group2.name: group2
    }
    assert shape_factory.test_changes_count

    # remove all groups
    shape_factory.test_changes_count = 0
    shape_factory.test_changes_remove_group_count = 0
    shape_factory.remove_all_groups()

    assert shape_factory.test_changes_count
    assert shape_factory.test_changes_remove_group_count
    assert not shape_factory.groups
    assert not shape_factory.shape_group_names
Example #3
0
def test_group_name(shape_factory: CeedPaintCanvasBehavior):
    assert not shape_factory.groups
    assert not shape_factory.shape_group_names

    # first group
    shape_factory.test_changes_count = 0
    group = shape_factory.add_group()

    assert isinstance(group, CeedShapeGroup)
    assert len(shape_factory.groups) == 1
    assert len(shape_factory.shape_group_names) == 1
    assert group in shape_factory.groups
    assert group.name in shape_factory.shape_group_names
    assert group is shape_factory.shape_group_names[group.name]
    assert shape_factory.test_changes_count

    # add second group
    shape_factory.test_changes_count = 0
    group2 = shape_factory.add_group()

    assert len(shape_factory.groups) == 2
    assert len(shape_factory.shape_group_names) == 2
    assert group2 in shape_factory.groups
    assert shape_factory.test_changes_count

    assert group.name != group2.name
    assert group2.name in shape_factory.shape_group_names
    assert group2 is shape_factory.shape_group_names[group2.name]

    # try making a duplicate name
    shape_factory.test_changes_count = 0
    group2.name = group.name
    assert len(shape_factory.groups) == 2
    assert len(shape_factory.shape_group_names) == 2
    assert group2 in shape_factory.groups
    assert shape_factory.test_changes_count

    assert group.name != group2.name
    assert group2.name in shape_factory.shape_group_names
    assert group2 is shape_factory.shape_group_names[group2.name]

    # try setting name
    shape_factory.test_changes_count = 0
    group2.name = 'something random'
    assert len(shape_factory.groups) == 2
    assert len(shape_factory.shape_group_names) == 2
    assert group2 in shape_factory.groups
    assert shape_factory.test_changes_count

    assert group2.name == 'something random'
    assert group2.name in shape_factory.shape_group_names
    assert group2 is shape_factory.shape_group_names['something random']
Example #4
0
def test_remove_from_group(shape_factory: CeedPaintCanvasBehavior):
    shape, shape2, shape3 = assert_add_three_shapes(shape_factory)

    group = shape_factory.add_group()
    add_prop_watch(group, 'on_changed', 'test_changes_count')
    assert group.add_shape(shape.shape)
    assert group.add_shape(shape2.shape)
    assert group.shapes == [shape.shape, shape2.shape]

    # remove first shape
    group.test_changes_count = 0
    group.remove_shape(shape.shape)
    assert group.test_changes_count
    assert group.shapes == [shape2.shape]

    # removing again does nothing
    group.remove_shape(shape.shape)
    assert group.shapes == [shape2.shape]

    # remove last
    group.test_changes_count = 0
    group.remove_shape(shape2.shape)
    assert group.test_changes_count
    assert not group.shapes

    # removing again does nothing
    group.remove_shape(shape2.shape)
    assert not group.shapes
Example #5
0
def test_add_selection_to_group(shape_factory: CeedPaintCanvasBehavior):
    shape, shape2, shape3 = assert_add_three_shapes(shape_factory)
    # select first and second shape
    shape_factory.select_shape(shape.shape)
    shape_factory.select_shape(shape2.shape)

    group = shape_factory.add_group()
    add_prop_watch(group, 'on_changed', 'test_changes_count')

    # add first shape manually
    assert group.add_shape(shape.shape)
    assert group.shapes == [shape.shape]

    # add all selected shapes
    group.test_changes_count = 0
    shape_factory.add_selected_shapes_to_group(group)
    assert group.test_changes_count
    assert group.shapes == [shape.shape, shape2.shape]
Example #6
0
def test_add_to_group(shape_factory: CeedPaintCanvasBehavior):
    shape, shape2, shape3 = assert_add_three_shapes(shape_factory)

    group = shape_factory.add_group()
    add_prop_watch(group, 'on_changed', 'test_changes_count')
    group.test_changes_count = 0
    assert group.add_shape(shape.shape)
    assert group.test_changes_count
    assert group.shapes == [shape.shape]

    # can't add twice
    assert not group.add_shape(shape.shape)
    assert group.shapes == [shape.shape]

    # add second shape
    group.test_changes_count = 0
    assert group.add_shape(shape2.shape)
    assert group.test_changes_count
    assert group.shapes == [shape.shape, shape2.shape]

    # can't add twice
    assert not group.add_shape(shape.shape)
    assert not group.add_shape(shape2.shape)
    assert group.shapes == [shape.shape, shape2.shape]