Skip to content

Commit

Permalink
Added test_builder_annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Oct 17, 2023
1 parent f2b1060 commit 523006c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 18 deletions.
88 changes: 88 additions & 0 deletions plotpy/tests/unit/test_builder_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see plotpy/LICENSE for details)

"""Test PlotBuilder annotations factory methods"""

import numpy as np
import pytest

from plotpy.builder import make
from plotpy.tests.unit.test_builder_curve import show_items_qtbot

DEFAULT_ARGS = {
make.annotated_point: [0.0, 0.0],
make.annotated_segment: [0.0, 0.0, 1.0, 1.0],
make.annotated_rectangle: [0.0, 0.0, 1.0, 1.0],
make.annotated_circle: [0.0, 0.0, 1.0, 1.0],
make.annotated_ellipse: [0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0],
}


def _make_annotation(
method,
title: str = None,
subtitle: str = None,
show_label: bool = None,
show_computations: bool = None,
show_subtitle: bool = None,
format: str = None,
uncertainty: float = None,
transform_matrix: np.ndarray = None,
readonly: bool = None,
private: bool = None,
):
"""Make annotation"""
args = DEFAULT_ARGS[method]
return method(
*args,
title=title,
subtitle=subtitle,
show_label=show_label,
show_computations=show_computations,
show_subtitle=show_subtitle,
format=format,
uncertainty=uncertainty,
transform_matrix=transform_matrix,
readonly=readonly,
private=private,
)


@pytest.mark.parametrize(
"method",
[
make.annotated_point,
make.annotated_segment,
make.annotated_rectangle,
make.annotated_circle,
make.annotated_ellipse,
],
)
def test_builder_annotation_params(qtbot, method):
items = []
for show_label in [True, False]:
items.append(
_make_annotation(
method,
title="title",
subtitle="subtitle",
show_label=show_label,
)
)
for show_computations in [True, False]:
items.append(_make_annotation(method, show_computations=show_computations))
for show_subtitle in [True, False]:
items.append(_make_annotation(method, show_subtitle=show_subtitle))
for format in ["%f", "%e"]:
items.append(_make_annotation(method, format=format))
for uncertainty in [0.0, 1.0]:
items.append(_make_annotation(method, uncertainty=uncertainty))
for transform_matrix in [None, np.identity(3)]:
items.append(_make_annotation(method, transform_matrix=transform_matrix))
for readonly in [True, False]:
items.append(_make_annotation(method, readonly=readonly))
for private in [True, False]:
items.append(_make_annotation(method, private=private))
show_items_qtbot(qtbot, items)
17 changes: 9 additions & 8 deletions plotpy/tests/unit/test_builder_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from plotpy.builder import make


def show_item(qtbot, item, type="curve"):
def show_items_qtbot(qtbot, items, type="curve"):
"""Plot curve in a dialog"""
win = make.dialog(type=type)
plot = win.manager.get_plot()
plot.add_item(item)
for item in items:
plot.add_item(item)
win.show()
qtbot.keyClick(win, Qt.Key_Enter)

Expand All @@ -43,7 +44,7 @@ def _make_curve_style(shade, curvestyle, baseline):
def test_builder_curve_curve_style(qtbot, shade, curvestyle, baseline):
"""Test curve parameters of curve() method"""
curve = _make_curve_style(shade, curvestyle, baseline)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")


@pytest.mark.parametrize("shade", [0, 0.4, 1.0])
Expand All @@ -52,7 +53,7 @@ def test_builder_curve_curve_style(qtbot, shade, curvestyle, baseline):
def test_builder_curve_curve_shade_baseline(qtbot, shade, curvestyle, baseline):
"""Test curve parameters of curve() method"""
curve = _make_curve_style(shade, curvestyle, baseline)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")


def _make_curve_linestyle(color, linestyle, linewidth):
Expand All @@ -76,7 +77,7 @@ def _make_curve_linestyle(color, linestyle, linewidth):
def test_builder_curve_line_style(qtbot, color, linestyle, linewidth):
"""Test line parameters of curve() method"""
curve = _make_curve_linestyle(color, linestyle, linewidth)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")


@pytest.mark.parametrize("color", ["red", "blue"])
Expand All @@ -85,7 +86,7 @@ def test_builder_curve_line_style(qtbot, color, linestyle, linewidth):
def test_builder_curve_line_color(qtbot, color, linestyle, linewidth):
"""Test line parameters of curve() method"""
curve = _make_curve_linestyle(color, linestyle, linewidth)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")


def _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor):
Expand Down Expand Up @@ -134,7 +135,7 @@ def test_builder_curve_marker_params_symbol(
):
"""Test marker parameters of curve() methodg"""
curve = _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")


@pytest.mark.parametrize("marker", ["Cross"])
Expand All @@ -146,4 +147,4 @@ def test_builder_curve_marker_size_color(
):
"""Test marker parameters of curve() methodg"""
curve = _make_curve_marker(marker, markersize, markerfacecolor, markeredgecolor)
show_item(qtbot, curve, "curve")
show_items_qtbot(qtbot, [curve], "curve")
20 changes: 10 additions & 10 deletions plotpy/tests/unit/test_builder_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from plotpy.builder import make
from plotpy.styles import LUTAlpha
from plotpy.tests.unit.test_builder_curve import show_item
from plotpy.tests.unit.test_builder_curve import show_items_qtbot


def _make_image(
Expand Down Expand Up @@ -61,54 +61,54 @@ def _make_image(
)
def test_builder_image_alpha_function(qtbot, alpha_function):
item = _make_image(alpha_function=alpha_function)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize(
"xdata,ydata", [[[None, None], [None, None]], [[-10, 10], [-10, 10]]]
)
def test_builder_image_xdata_ydata(qtbot, xdata, ydata):
item = _make_image(xdata=xdata, ydata=ydata)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("pixel_size", [None, 1.0, (1.0, 2.0)])
def test_builder_image_center_on(qtbot, pixel_size):
item = _make_image(pixel_size=pixel_size)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("center_on", [None, [1.0, 3.0]])
def test_builder_image_center_on(qtbot, center_on):
item = _make_image(center_on=center_on)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("interpolation", ["nearest", "linear", "antialiasing"])
def test_builder_image_interpolation(qtbot, interpolation):
item = _make_image(interpolation=interpolation)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("background_color", [None, "red"])
def test_builder_image_center_on(qtbot, background_color):
item = _make_image(background_color=background_color)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("eliminate_outliers", [None, 3.0])
def test_builder_image_center_on(qtbot, eliminate_outliers):
item = _make_image(eliminate_outliers=eliminate_outliers)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("lut_range", [None, [0.0, 100.0]])
def test_builder_image_center_on(qtbot, lut_range):
item = _make_image(lut_range=lut_range)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])


@pytest.mark.parametrize("lock_position", [None, True, False])
def test_builder_image_center_on(qtbot, lock_position):
item = _make_image(lock_position=lock_position)
show_item(qtbot, item)
show_items_qtbot(qtbot, [item])

0 comments on commit 523006c

Please sign in to comment.