Commit 37df64ed authored by Valentin Valls's avatar Valentin Valls
Browse files

Rework the tests

- Remove dedicated constant created in flint test session
parent e50c1d1b
"""Testing the BLISS bliss.common.plot API."""
import pytest
import numpy
from bliss.common import plot
def test_empty_plot(flint_session):
p = plot.plot(name="Foo")
pid = plot.get_flint()._pid
assert "flint_pid={}".format(pid) in repr(p)
assert p.name == "Foo"
p = plot.plot(name="Some name")
assert "flint_pid={}".format(pid) in repr(p)
assert p.name == "Some name"
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)
def test_simple_plot(flint_session):
sin = flint_session.env_dict["sin_data"]
p = plot.plot(sin)
assert "Plot1D" in repr(p)
data = p.get_data()
assert data == {
"default": pytest.approx(sin),
"x": pytest.approx(list(range(len(sin)))),
}
def test_plot_curve_with_x(flint_session):
sin = flint_session.env_dict["sin_data"]
cos = flint_session.env_dict["cos_data"]
p = plot.plot({"sin": sin, "cos": cos}, x="sin")
assert "Plot1D" in repr(p)
data = p.get_data()
assert data == {"sin": pytest.approx(sin), "cos": pytest.approx(cos)}
def test_image_plot(flint_session):
grey_image = flint_session.env_dict["grey_image"]
p = plot.plot(grey_image)
assert "Plot2D" in repr(p)
data = p.get_data()
assert data == {"default": pytest.approx(grey_image)}
colored_image = flint_session.env_dict["colored_image"]
p = plot.plot(colored_image)
assert "Plot2D" in repr(p)
data = p.get_data()
assert data == {"default": pytest.approx(colored_image)}
def test_curve_plot(flint_session):
dct = flint_session.env_dict["sin_cos_dict"]
struct = flint_session.env_dict["sin_cos_struct"]
scan = flint_session.env_dict["sin_cos_scan"]
for sin_cos in (dct, struct, scan):
p = plot.plot(sin_cos)
assert "Plot1D" in repr(p)
data = p.get_data()
assert data == {
"x": pytest.approx(sin_cos["x"]),
"sin": pytest.approx(sin_cos["sin"]),
"cos": pytest.approx(sin_cos["cos"]),
}
......@@ -7,20 +7,55 @@ from bliss.common import plot
from bliss.controllers.lima import roi as lima_roi
def test_empty_plot(flint_session):
flint = plot.get_flint()
p = flint.get_plot(plot_class="curve", name="foo-empty")
assert flint.is_plot_exists("foo-empty") is False
assert p is not None
def test_plot__create_2_plot(flint_session):
"""Create 2 plots
Make sure it exists 2 plots
"""
p = plot.plot(name="Foo")
pid = plot.get_flint()._pid
assert "flint_pid={}".format(pid) in repr(p)
assert p.name == "Foo"
p = plot.plot(name="Some name")
assert "flint_pid={}".format(pid) in repr(p)
assert p.name == "Some name"
def test_plot__reuse_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_remove_custom_plot(flint_session):
def test_plot__reuse_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)
def test_plot__remove_plot(flint_session):
flint = plot.get_flint()
p = flint.get_plot(plot_class="curve", name="foo-rm")
p = flint.get_plot(plot_class="curve", name="foo-rm", unique_name="foo-rm")
flint.remove_plot(p.plot_id)
assert flint.is_plot_exists("foo-rm") is False
def test_curveplot__create_empty(flint_session):
flint = plot.get_flint()
p = flint.get_plot(plot_class="curve", name="foo-empty", unique_name="foo-empty")
assert flint.is_plot_exists("foo-empty")
assert p is not None
def test_curveplot__bliss_1_8(flint_session):
"""Check custom plot curve API from BLISS <= 1.8"""
flint = plot.get_flint()
......@@ -50,7 +85,7 @@ def test_curveplot__bliss_1_8(flint_session):
assert data == []
def test_reuse_custom_plot(flint_session):
def test_curveplot__reuse_plot(flint_session):
flint = plot.get_flint()
p = flint.get_plot(plot_class="curve", unique_name="foo-reuse")
cos_data = numpy.cos(numpy.linspace(0, 2 * numpy.pi, 10))
......
- class: Session
name: flint
setup-file: ./test_flint.py
config-objects:
- simu1
- roby
......
# Imports
import numpy
import scipy.misc
# Test data
colored_image = scipy.misc.face()[:10, :10, :]
grey_image = colored_image[:, :, 0]
image_stack = [colored_image[:, :, i] for i in range(3)]
x_data = numpy.linspace(0, 10, 100)
cos_data = numpy.cos(x_data)
sin_data = numpy.sin(x_data)
sin_cos_dict = {"x": x_data, "sin": sin_data, "cos": cos_data}
sin_cos_struct = numpy.array(
(x_data, sin_data, cos_data),
dtype=[
("x", float, x_data.shape),
("sin", float, sin_data.shape),
("cos", float, cos_data.shape),
],
)
sin_cos_scan = numpy.array(
list(zip(x_data, sin_data, cos_data)),
dtype=[("x", float), ("sin", float), ("cos", float)],
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment