コード例 #1
0
def test_drawing_invokes_canvas_line_to(data: List[Polygon]):

    canvas = PolygonAnnotationCanvas()

    with patch.object(ipycanvas.Canvas, "line_to") as mock_line_to:
        canvas.data = [poly.data for poly in data]

    for polygon in data:
        if len(polygon.points) > 1:
            for point in polygon.points[1:]:
                mock_line_to.assert_any_call(*point)
コード例 #2
0
def test_reading_and_setting_data(data: List[Polygon]):

    c = PolygonAnnotationCanvas()

    serialised_data = [polygon.data for polygon in data]

    with patch.object(c, "re_draw") as mock_draw:
        c.data = serialised_data
        mock_draw.assert_called()

    assert all(p1 == p2 for p1, p2 in zip(c.polygons, data))

    print(c.data)
    print("type" in serialised_data)
    assert c.data == serialised_data
コード例 #3
0
def test_drawing_invokes_canvas_fill_arc_in_edit_mode(data: List[Polygon]):

    assume(len(data) > 1)
    canvas = PolygonAnnotationCanvas()
    canvas.load_image(IMAGE)
    print(canvas.image_extent)
    canvas.editing = True

    with patch.object(ipycanvas.Canvas, "fill_arcs") as mock_fill_arcs:
        canvas.data = [poly.data for poly in data]

    for polygon in data:
        for point in polygon.points:
            assert canvas.image_to_canvas_coordinates(point) == point

        if len(polygon.points) > 1:
            mock_fill_arcs.assert_any_call(
                polygon.xy_lists[0],
                polygon.xy_lists[1],
                canvas.point_size,
                0,
                2 * pi,
            )