test_custom_plots.py 4.67 KB
Newer Older
1
2
"""Testing custom plots provided by Flint."""

Valentin Valls's avatar
Valentin Valls committed
3
import gevent
Valentin Valls's avatar
Valentin Valls committed
4
import numpy
5
from bliss.common import plot
Valentin Valls's avatar
Valentin Valls committed
6
from bliss.controllers.lima import roi as lima_roi
7
8


Valentin Valls's avatar
Valentin Valls committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def test_reuse_custom_plot__api_1_0(flint_session):
    """Test reuse of custom plot from an ID"""
    widget = plot.plot_curve(name="foo")
    cos_data = numpy.cos(numpy.linspace(0, 2 * numpy.pi, 10))
    widget.add_data({"cos": cos_data, "foo": cos_data})
    widget2 = plot.plot_curve(name="foo", existing_id=widget.plot_id)
    cos = widget2.get_data()["cos"]
    numpy.testing.assert_allclose(cos, cos_data)


def test_reuse_custom_plot__api_1_6(flint_session):
    """Test reuse of custom plot from a name"""
    widget = plot.plot_curve(name="foo", existing_id="myplot")
    cos_data = numpy.cos(numpy.linspace(0, 2 * numpy.pi, 10))
    widget.add_data({"cos": cos_data, "foo": cos_data})
    widget2 = plot.plot_curve(name="foo", existing_id="myplot")
    cos = widget2.get_data()["cos"]
    numpy.testing.assert_allclose(cos, cos_data)


29
30
31
def test_select_points(flint_session):
    flint = plot.get_flint()
    p = plot.plot()
Valentin Valls's avatar
Valentin Valls committed
32
    context = []
33

Valentin Valls's avatar
Valentin Valls committed
34
35
36
37
38
39
40
41
42
43
44
45
    def active_gui():
        result = p.select_points(1)
        context.append(result)

    def do_actions():
        gevent.sleep(1)
        flint.test_mouse(
            p.plot_id, mode="click", position=(0, 0), relative_to_center=True
        )

    gevent.joinall([gevent.spawn(f) for f in [active_gui, do_actions]])
    assert len(context) == 1
46

Valentin Valls's avatar
Valentin Valls committed
47
    result = context[0]
48
49
50
51
52
    assert len(result) == 1
    assert len(result[0]) == 2


def test_select_shape(flint_session):
Valentin Valls's avatar
Valentin Valls committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    flint = plot.get_flint()
    p = plot.plot()
    context = []

    def active_gui():
        result = p.select_shape(shape="line")
        context.append(result)

    def do_actions():
        gevent.sleep(1)
        flint.test_mouse(
            p.plot_id, mode="click", position=(0, 0), relative_to_center=True
        )
        flint.test_mouse(
            p.plot_id, mode="click", position=(5, 5), relative_to_center=True
        )

    gevent.joinall([gevent.spawn(f) for f in [active_gui, do_actions]])
    assert len(context) == 1
72

Valentin Valls's avatar
Valentin Valls committed
73
    result = context[0]
74
75
76
77
    assert len(result) == 2
    assert len(result[0]) == 2
    assert len(result[1]) == 2

Valentin Valls's avatar
Valentin Valls committed
78

Valentin Valls's avatar
Valentin Valls committed
79
def test_select_shapes__rect(flint_session):
80
81
    flint = plot.get_flint()
    p = plot.plot()
82
    context = []
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    def active_gui():
        result = p.select_shapes()
        context.append(result)

    def do_actions():
        gevent.sleep(1)
        flint.test_mouse(
            p.plot_id, mode="press", position=(-5, -5), relative_to_center=True
        )
        flint.test_mouse(
            p.plot_id, mode="release", position=(5, 5), relative_to_center=True
        )
        flint.test_active(p.plot_id, qaction="roi-apply-selection")

    gevent.joinall([gevent.spawn(f) for f in [active_gui, do_actions]])
    assert len(context) == 1

    result = context[0]
    assert len(result) == 1
    roi = result[0]
    assert isinstance(roi, dict)
    expected_keys = set(["origin", "size", "label", "kind"])
    assert len(expected_keys - roi.keys()) == 0
    assert roi["kind"] == "Rectangle"
Valentin Valls's avatar
Valentin Valls committed
108
109


Valentin Valls's avatar
Valentin Valls committed
110
111
112
113
114
115
def test_select_shapes__arc(flint_session):
    flint = plot.get_flint()
    p = plot.plot()
    context = []

    def active_gui():
116
        result = p.select_shapes(kinds=["lima-arc"])
Valentin Valls's avatar
Valentin Valls committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
        context.append(result)

    def do_actions():
        gevent.sleep(1)
        flint.test_mouse(
            p.plot_id, mode="press", position=(-5, -5), relative_to_center=True
        )
        flint.test_mouse(
            p.plot_id, mode="release", position=(5, 5), relative_to_center=True
        )
        flint.test_active(p.plot_id, qaction="roi-apply-selection")

    gevent.joinall([gevent.spawn(f) for f in [active_gui, do_actions]])
    assert len(context) == 1

    result = context[0]
    assert len(result) == 1
    roi = result[0]
Valentin Valls's avatar
Valentin Valls committed
135
    assert isinstance(roi, lima_roi.ArcRoi)
Valentin Valls's avatar
Valentin Valls committed
136
137


Valentin Valls's avatar
Valentin Valls committed
138
def test_select_shapes__rect_profile(flint_session):
Valentin Valls's avatar
Valentin Valls committed
139
140
141
142
143
    flint = plot.get_flint()
    p = plot.plot()
    context = []

    def active_gui():
144
        result = p.select_shapes(kinds=["lima-vertical-profile"])
Valentin Valls's avatar
Valentin Valls committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        context.append(result)

    def do_actions():
        gevent.sleep(1)
        flint.test_mouse(
            p.plot_id, mode="press", position=(-5, -5), relative_to_center=True
        )
        flint.test_mouse(
            p.plot_id, mode="release", position=(5, 5), relative_to_center=True
        )
        flint.test_active(p.plot_id, qaction="roi-apply-selection")

    gevent.joinall([gevent.spawn(f) for f in [active_gui, do_actions]])
    assert len(context) == 1

    result = context[0]
    assert len(result) == 1
    roi = result[0]
Valentin Valls's avatar
Valentin Valls committed
163
164
    assert isinstance(roi, lima_roi.RoiProfile)
    assert roi.mode == "vertical"