Exemplo n.º 1
0
Arquivo: shapes.py Projeto: cplab/ceed
def assert_add_three_shapes(
        shape_factory: CeedPaintCanvasBehavior = None,
        app: CeedTestApp = None, show_in_gui=False):
    assert not shape_factory.shapes
    assert not shape_factory.shape_names

    shape = EllipseShapeP1(
        app=app, painter=shape_factory, show_in_gui=show_in_gui)
    shape2 = PolygonShapeP1(
        app=app, painter=shape_factory, show_in_gui=show_in_gui)
    shape3 = CircleShapeP1(
        app=app, painter=shape_factory, show_in_gui=show_in_gui)

    if not show_in_gui:
        shape.make_shape()
        shape2.make_shape()
        shape3.make_shape()

        assert shape_factory.add_shape(shape.shape)
        assert shape_factory.add_shape(shape2.shape)
        assert shape_factory.add_shape(shape3.shape)

    assert shape_factory.shapes == [shape.shape, shape2.shape, shape3.shape]
    assert len(shape_factory.shapes) == 3
    assert len(shape_factory.shape_names) == 3
    for s in (shape, shape2, shape3):
        assert shape_factory.shape_names[s.name] is s.shape
    return shape, shape2, shape3
Exemplo n.º 2
0
def test_shape_add_remove(shape_factory: CeedPaintCanvasBehavior, shape_cls):
    assert not shape_factory.shapes
    assert not shape_factory.shape_names
    shape = shape_cls(app=None, painter=shape_factory, show_in_gui=False)
    shape.make_shape()

    # add shape
    shape_factory.test_changes_count = 0
    assert shape_factory.add_shape(shape.shape)
    assert shape.shape in shape_factory.shapes
    assert shape.name in shape_factory.shape_names
    assert shape.shape is shape_factory.shape_names[shape.name]
    assert shape_factory.test_changes_count

    # remove shape
    shape_factory.test_changes_remove_shape_count = 0
    shape_factory.test_changes_count = 0
    assert shape_factory.remove_shape(shape.shape)
    assert shape.shape not in shape_factory.shapes
    assert shape.name not in shape_factory.shape_names
    assert shape_factory.test_changes_remove_shape_count
    assert shape_factory.test_changes_count

    # remove same shape again
    shape_factory.test_changes_remove_shape_count = 0
    shape_factory.test_changes_count = 0
    assert not shape_factory.remove_shape(shape.shape)
    assert not shape_factory.test_changes_remove_shape_count
    assert not shape_factory.test_changes_count
Exemplo n.º 3
0
def test_area(shape_factory: CeedPaintCanvasBehavior):
    shape = CircleShapeP1(app=None, painter=shape_factory, show_in_gui=False)
    shape.make_shape()

    assert shape_factory.add_shape(shape.shape)
    assert math.isclose(shape.shape.area, shape.area)

    shape.shape.set_area(shape.shape.area / 4)
    assert math.isclose(shape.shape.radius, shape.radius / 2)
Exemplo n.º 4
0
def test_shape_name(shape_factory: CeedPaintCanvasBehavior):
    assert not shape_factory.shapes
    assert not shape_factory.shape_names
    shape = EllipseShapeP1(app=None, painter=shape_factory, show_in_gui=False)
    shape.make_shape()

    # add first shape
    shape_factory.test_changes_count = 0
    assert shape_factory.add_shape(shape.shape)
    assert len(shape_factory.shapes) == 1
    assert len(shape_factory.shape_names) == 1
    assert shape.shape in shape_factory.shapes
    assert shape.name in shape_factory.shape_names
    assert shape.shape is shape_factory.shape_names[shape.name]
    assert shape_factory.test_changes_count

    shape2 = EllipseShapeP1(app=None, painter=shape_factory, show_in_gui=False)
    shape2.make_shape()

    # add second shape
    shape_factory.test_changes_count = 0
    assert shape_factory.add_shape(shape2.shape)
    assert len(shape_factory.shapes) == 2
    assert len(shape_factory.shape_names) == 2
    assert shape2.shape in shape_factory.shapes
    assert shape_factory.test_changes_count

    assert shape2.name != shape2.shape.name
    assert shape.shape.name != shape2.shape.name
    assert shape2.shape.name in shape_factory.shape_names
    assert shape2.shape is shape_factory.shape_names[shape2.shape.name]

    # try making shape2 the same name as shape 1
    shape_factory.test_changes_count = 0
    shape2.shape.name = shape.shape.name
    assert len(shape_factory.shapes) == 2
    assert len(shape_factory.shape_names) == 2
    assert shape2.shape in shape_factory.shapes
    assert shape_factory.test_changes_count

    assert shape.shape.name != shape2.shape.name
    assert shape2.shape.name in shape_factory.shape_names
    assert shape2.shape is shape_factory.shape_names[shape2.shape.name]
Exemplo n.º 5
0
def test_center(shape_factory: CeedPaintCanvasBehavior):
    shape = CircleShapeP1(app=None, painter=shape_factory, show_in_gui=False)
    shape.make_shape()

    assert shape_factory.add_shape(shape.shape)
    assert shape.shape.centroid == tuple(shape.center)
Exemplo n.º 6
0
def test_bounding_box(shape_factory: CeedPaintCanvasBehavior):
    shape = CircleShapeP1(app=None, painter=shape_factory, show_in_gui=False)
    shape.make_shape()

    assert shape_factory.add_shape(shape.shape)
    assert shape.shape.bounding_box == shape.bounding_box