mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-10-26 15:51:28 +01:00
fix(plots): restore matplotlib export from the plot toolbar
This commit is contained in:
2 files changed
+36
No files matched your search
@@ -93,6 +93,7 @@ class PlotExportConnection(BundleConnection):
|
||||
if self.target_widget:
|
||||
try:
|
||||
import matplotlib as mpl
|
||||
from pyqtgraph.exporters import MatplotlibExporter
|
||||
|
||||
MatplotlibExporter(self.target_widget.plot_item).export()
|
||||
except ModuleNotFoundError:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from unittest import mock
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from bec_lib import messages
|
||||
@@ -792,3 +794,36 @@ def test_limits_accept_fractional_values(qtbot, mocked_client):
|
||||
pb.y_limits = (-1.75, 3.5)
|
||||
assert (pb.x_limits.x(), pb.x_limits.y()) == (0.5, 9.25)
|
||||
assert (pb.y_limits.x(), pb.y_limits.y()) == (-1.75, 3.5)
|
||||
|
||||
|
||||
def test_matplotlib_export_action_opens_exporter(qtbot, mocked_client):
|
||||
pb = create_widget(qtbot, PlotBase, client=mocked_client)
|
||||
matplotlib_action = pb.toolbar.components.get_action("matplotlib").action
|
||||
|
||||
with (
|
||||
mock.patch.dict("sys.modules", {"matplotlib": mock.MagicMock()}),
|
||||
mock.patch("pyqtgraph.exporters.MatplotlibExporter") as exporter,
|
||||
):
|
||||
matplotlib_action.trigger()
|
||||
|
||||
exporter.assert_called_once_with(pb.plot_item)
|
||||
exporter.return_value.export.assert_called_once()
|
||||
|
||||
|
||||
def test_matplotlib_export_action_warns_without_matplotlib(qtbot, mocked_client):
|
||||
pb = create_widget(qtbot, PlotBase, client=mocked_client)
|
||||
matplotlib_action = pb.toolbar.components.get_action("matplotlib").action
|
||||
|
||||
with (
|
||||
mock.patch.dict("sys.modules", {"matplotlib": None}),
|
||||
mock.patch(
|
||||
"bec_widgets.widgets.plots.toolbar_components.plot_export.WarningPopupUtility"
|
||||
) as warning_util,
|
||||
):
|
||||
matplotlib_action.trigger()
|
||||
|
||||
warning_util.return_value.show_warning.assert_called_once()
|
||||
assert (
|
||||
warning_util.return_value.show_warning.call_args.kwargs["title"]
|
||||
== "Matplotlib not installed"
|
||||
)
|
||||
Reference in new issue
Block a user