Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield committed Nov 27, 2023
1 parent 770147f commit f376c90
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions tests/views/test_mdh_workspaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""UI tests for the MDH list tables"""
from functools import partial
import pytest
from qtpy.QtWidgets import QApplication, QMenu, QFileDialog, QLineEdit
from qtpy.QtCore import Qt, QTimer
from qtpy.QtGui import QContextMenuEvent
Expand All @@ -25,7 +26,7 @@ def test_mdh_workspaces_menu(qtbot):
mdh_table.show()

def mock_call(ws_name, ndims):
return f"full {ws_name}: {ndims}", {"min": None, "max": None}
return f"{ws_name}: {ndims}", {"min": None, "max": None}

mdh_table.get_display_name_and_intensity_limits = mock_call

Expand Down Expand Up @@ -127,9 +128,23 @@ def delete_callback(name):
qtbot.wait(100)


def test_mdh_plotting_1d(qtbot):
@pytest.mark.parametrize(
"user_conf_file",
[
"""
[main_tab.plot]
display_title = name_only
logarithmic_intensity = True
"""
],
indirect=True,
)
def test_mdh_plotting_1d(qtbot, user_conf_file, monkeypatch):
"""Tests the 1D plotting"""

# mock get_oncat_url, client_id and use_notes info
monkeypatch.setattr("shiver.configuration.CONFIG_PATH_FILE", user_conf_file)

# Create workspaces in mantid, needed for plots
CreateMDHistoWorkspace(
Dimensionality=4,
Expand All @@ -146,7 +161,7 @@ def test_mdh_plotting_1d(qtbot):
mdh_table = MDHList()

def mock_call(ws_name, ndims):
return f"full {ws_name}: {ndims}", {"min": None, "max": None}
return f"{ws_name}: {ndims}", {"min": None, "max": None}

mdh_table.get_display_name_and_intensity_limits = mock_call

Expand All @@ -173,6 +188,8 @@ def mock_call(ws_name, ndims):

assert len(figure.axes) == 1
assert len(figure.axes[0].lines) == 1
assert figure.axes[0].get_yscale() == "log"
assert figure.axes[0].get_title() == "Plot 1D: 1"

# Select "Overplot 1D"
QTimer.singleShot(100, partial(handle_menu, qtbot, mdh_table, 2))
Expand All @@ -183,6 +200,8 @@ def mock_call(ws_name, ndims):
qtbot.wait(500)

assert len(figure.axes[0].lines) == 2
assert figure.axes[0].get_yscale() == "log"
assert figure.axes[0].get_title() == "Plot 1D: 1"

qtbot.wait(100)

Expand All @@ -199,6 +218,8 @@ def mock_call(ws_name, ndims):

assert len(figure2.axes) == 1
assert len(figure2.axes[0].lines) == 1
assert figure.axes[0].get_yscale() == "log"
assert figure.axes[0].get_title() == "Plot 1D: 1"

# Select "Overplot 1D with Errors"
QTimer.singleShot(100, partial(handle_menu, qtbot, mdh_table, 4))
Expand All @@ -211,8 +232,22 @@ def mock_call(ws_name, ndims):
assert len(figure2.axes[0].lines) == 2


def test_mdh_plotting_2d(qtbot):
@pytest.mark.parametrize(
"user_conf_file",
[
"""
[main_tab.plot]
display_title = name_only
logarithmic_intensity = True
"""
],
indirect=True,
)
def test_mdh_plotting_2d(qtbot, user_conf_file, monkeypatch):
"""Tests the 2D plotting, colorfill plot or sliceviewer"""

# mock get_oncat_url, client_id and use_notes info
monkeypatch.setattr("shiver.configuration.CONFIG_PATH_FILE", user_conf_file)
CreateMDHistoWorkspace(
Dimensionality=4,
Extents="-10,10,-1,1,-1,1,-2,2",
Expand All @@ -228,7 +263,7 @@ def test_mdh_plotting_2d(qtbot):
mdh_table = MDHList()

def mock_call(ws_name, ndims):
return f"full {ws_name}: {ndims}", {"min": None, "max": None}
return f"{ws_name}: {ndims}", {"min": None, "max": None}

mdh_table.get_display_name_and_intensity_limits = mock_call

Expand All @@ -255,6 +290,8 @@ def mock_call(ws_name, ndims):
figure = plt.gcf()
assert len(figure.axes) == 2 # pcolormesh and colorbar
assert figure.axes[0].pcolormesh
assert figure.axes[0].get_title() == "Plot 2D: 2"
assert figure.axes[1].get_yscale() == "log"

# sliceviewer
QTimer.singleShot(100, partial(handle_menu, qtbot, mdh_table, 2))
Expand All @@ -268,6 +305,8 @@ def mock_call(ws_name, ndims):
slice_viewer = mdh_table.findChild(SliceViewerView)
assert slice_viewer is not None
assert slice_viewer.isVisible()
assert slice_viewer.data_view.colorbar.norm.currentText() == "Log"

slice_viewer.close()


Expand All @@ -289,7 +328,7 @@ def test_mdh_plotting_3d(qtbot):
mdh_table = MDHList()

def mock_call(ws_name, ndims):
return f"full {ws_name}: {ndims}", {"min": None, "max": None}
return f"{ws_name}: {ndims}", {"min": None, "max": None}

mdh_table.get_display_name_and_intensity_limits = mock_call

Expand Down

0 comments on commit f376c90

Please sign in to comment.