|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Licensed under the terms of the BSD 3-Clause |
| 4 | +# (see plotpy/LICENSE for details) |
| 5 | + |
| 6 | +"""Test PlotBuilder shape factory methods""" |
| 7 | + |
| 8 | +import numpy as np |
| 9 | +import pytest |
| 10 | + |
| 11 | +from plotpy.builder import make |
| 12 | +from plotpy.tests import get_path |
| 13 | +from plotpy.tests.unit.test_builder_curve import show_items_qtbot |
| 14 | + |
| 15 | +DEFAULT_ARGS = { |
| 16 | + make.segment: [0.0, 0.0, 1.0, 1.0], |
| 17 | + make.rectangle: [0.0, 0.0, 1.0, 1.0], |
| 18 | + make.circle: [0.0, 0.0, 1.0, 1.0], |
| 19 | + make.ellipse: [0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0], |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +def _make_standard_shape( |
| 24 | + method, |
| 25 | + title: str = None, |
| 26 | +): |
| 27 | + """Make annotation""" |
| 28 | + args = DEFAULT_ARGS[method] |
| 29 | + return method( |
| 30 | + *args, |
| 31 | + title=title, |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize( |
| 36 | + "method", |
| 37 | + [make.segment, make.rectangle, make.circle, make.ellipse], |
| 38 | +) |
| 39 | +def test_builder_standard_shape(qtbot, method): |
| 40 | + items = [] |
| 41 | + items.append(_make_standard_shape(method, title="title")) |
| 42 | + show_items_qtbot(qtbot, items) |
| 43 | + |
| 44 | + |
| 45 | +def test_builder_polygon(qtbot): |
| 46 | + items = [] |
| 47 | + x = np.linspace(0, 1, 10) |
| 48 | + y = x**2 |
| 49 | + for closed in [True, False]: |
| 50 | + items.append(make.polygon(x, y, closed=closed, title="title")) |
| 51 | + show_items_qtbot(qtbot, items) |
| 52 | + |
| 53 | + |
| 54 | +def test_builder_svgshape(qtbot): |
| 55 | + items = [] |
| 56 | + svg_path = get_path("svg_target.svg") |
| 57 | + with open(svg_path, "rb") as f: |
| 58 | + svg_data = f.read() |
| 59 | + x = np.linspace(0, 1, 10) |
| 60 | + y = x**2 |
| 61 | + for shape_str in ("circle", "rectangle", "square"): |
| 62 | + for data_or_path in (svg_data, svg_path): |
| 63 | + items.append( |
| 64 | + make.svg(shape_str, data_or_path, 0.0, 0.0, 1.0, 1.0, title="title") |
| 65 | + ) |
| 66 | + show_items_qtbot(qtbot, items) |
0 commit comments