Skip to content

Commit 2ed3663

Browse files
committed
added figuremanager tests
1 parent 3dd3af2 commit 2ed3663

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

qt/applications/workbench/workbench/plotting/test/test_figuremanager.py

+59
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,65 @@ def test_window_title(self, mock_qappthread):
5252
fig_mgr = FigureManagerWorkbench(canvas, 1)
5353
self.assertEqual(fig_mgr.get_window_title(), "Figure 1")
5454

55+
@patch("workbench.plotting.figuremanager.QAppThreadCall")
56+
def test_ax_callback_set_up(self, mock_qappthread):
57+
mock_qappthread.return_value = mock_qappthread
58+
fig = MagicMock()
59+
fig.bbox.max = [1, 1]
60+
canvas = MantidFigureCanvas(fig)
61+
fig_mgr = FigureManagerWorkbench(canvas, 1)
62+
with (
63+
patch("workbench.plotting.figuremanager.FigureManagerWorkbench._axes_that_are_not_colour_bars") as plot_axes_mock,
64+
patch("workbench.plotting.figuremanager.FigureManagerWorkbench._axes_title_changed_callback") as callback_mock,
65+
):
66+
ax = MagicMock()
67+
plot_axes_mock.return_value = [ax]
68+
fig_mgr.show()
69+
ax.title.add_callback.assert_called_once_with(callback_mock)
70+
71+
@patch("workbench.plotting.figuremanager.QAppThreadCall")
72+
def test_ax_callback_will_set_window_title_with_new_title(self, mock_qappthread):
73+
mock_qappthread.return_value = mock_qappthread
74+
fig = MagicMock()
75+
fig.bbox.max = [1, 1]
76+
canvas = MantidFigureCanvas(fig)
77+
fig_mgr = FigureManagerWorkbench(canvas, 1)
78+
mock_title_artist = MagicMock()
79+
mock_title_artist.get_text.return_value = "new title"
80+
with patch("workbench.plotting.figuremanager.FigureManagerWorkbench.set_window_title") as set_window_title_mock:
81+
fig_mgr._axes_title_changed_callback(mock_title_artist)
82+
set_window_title_mock.assert_called_once_with("new title")
83+
84+
@patch("workbench.plotting.figuremanager.QAppThreadCall")
85+
def test_ax_callback_will_not_set_window_title_with_current_title(self, mock_qappthread):
86+
mock_qappthread.return_value = mock_qappthread
87+
fig = MagicMock()
88+
fig.bbox.max = [1, 1]
89+
canvas = MantidFigureCanvas(fig)
90+
fig_mgr = FigureManagerWorkbench(canvas, 1)
91+
mock_title_artist = MagicMock()
92+
mock_title_artist.get_text.return_value = "Figure 1"
93+
with patch("workbench.plotting.figuremanager.FigureManagerWorkbench.set_window_title") as set_window_title_mock:
94+
fig_mgr._axes_title_changed_callback(mock_title_artist)
95+
set_window_title_mock.assert_not_called()
96+
97+
@patch("workbench.plotting.figuremanager.QAppThreadCall")
98+
def test_ax_callback_will_not_set_window_title_with_current_title_without_number(self, mock_qappthread):
99+
mock_qappthread.return_value = mock_qappthread
100+
fig = MagicMock()
101+
fig.bbox.max = [1, 1]
102+
canvas = MantidFigureCanvas(fig)
103+
fig_mgr = FigureManagerWorkbench(canvas, 1)
104+
mock_title_artist = MagicMock()
105+
mock_title_artist.get_text.return_value = "EMU00000"
106+
with (
107+
patch("workbench.plotting.figuremanager.FigureManagerWorkbench.set_window_title") as set_window_title_mock,
108+
patch("workbench.plotting.figuremanager.FigureManagerWorkbench.get_window_title") as get_window_title_mock,
109+
):
110+
get_window_title_mock.return_value = "EMU00000-1"
111+
fig_mgr._axes_title_changed_callback(mock_title_artist)
112+
set_window_title_mock.assert_not_called()
113+
55114
def test_reverse_axes_lines(self):
56115
fig, ax = plt.subplots(subplot_kw={"projection": "mantid"})
57116
spec2 = ax.plot(self.ws2d_histo, "rs", specNum=2, linewidth=6)

0 commit comments

Comments
 (0)