summaryrefslogtreecommitdiff
path: root/src/silx/gui/plot/tools/test/testProfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/silx/gui/plot/tools/test/testProfile.py')
-rw-r--r--src/silx/gui/plot/tools/test/testProfile.py155
1 files changed, 53 insertions, 102 deletions
diff --git a/src/silx/gui/plot/tools/test/testProfile.py b/src/silx/gui/plot/tools/test/testProfile.py
index ad40e67..61b95a6 100644
--- a/src/silx/gui/plot/tools/test/testProfile.py
+++ b/src/silx/gui/plot/tools/test/testProfile.py
@@ -1,6 +1,6 @@
# /*##########################################################################
#
-# Copyright (c) 2018-2021 European Synchrotron Radiation Facility
+# Copyright (c) 2018-2023 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -26,14 +26,11 @@ __license__ = "MIT"
__date__ = "28/06/2018"
-import unittest
import contextlib
import numpy
import logging
from silx.gui import qt
-from silx.utils import deprecation
-from silx.utils import testutils
from silx.gui.utils.testutils import TestCaseQt
from silx.utils.testutils import ParametricTestCase
@@ -49,7 +46,6 @@ _logger = logging.getLogger(__name__)
class TestRois(TestCaseQt):
-
def test_init(self):
"""Check that the constructor is not called twice"""
roi = rois.ProfileImageVerticalLineROI()
@@ -59,7 +55,6 @@ class TestRois(TestCaseQt):
class TestInteractions(TestCaseQt):
-
@contextlib.contextmanager
def defaultPlot(self):
try:
@@ -168,7 +163,7 @@ class TestInteractions(TestCaseQt):
self.assertEqual(len(profileRois), 3)
else:
self.assertEqual(len(profileRois), 1)
- # The first one should be the expected one
+ # The first one should be the expected one
roi = profileRois[0]
# Test that something was displayed
@@ -227,14 +222,14 @@ class TestInteractions(TestCaseQt):
if isinstance(editor, editors._NoProfileRoiEditor):
pass
elif isinstance(editor, editors._DefaultImageStackProfileRoiEditor):
- # GUI to ROI
+ # GUI to ROI
editor._lineWidth.setValue(2)
self.assertEqual(roi.getProfileLineWidth(), 2)
editor._methodsButton.setMethod("sum")
self.assertEqual(roi.getProfileMethod(), "sum")
editor._profileDim.setDimension(1)
self.assertEqual(roi.getProfileType(), "1D")
- # ROI to GUI
+ # ROI to GUI
roi.setProfileLineWidth(3)
self.assertEqual(editor._lineWidth.value(), 3)
roi.setProfileMethod("mean")
@@ -242,21 +237,21 @@ class TestInteractions(TestCaseQt):
roi.setProfileType("2D")
self.assertEqual(editor._profileDim.getDimension(), 2)
elif isinstance(editor, editors._DefaultImageProfileRoiEditor):
- # GUI to ROI
+ # GUI to ROI
editor._lineWidth.setValue(2)
self.assertEqual(roi.getProfileLineWidth(), 2)
editor._methodsButton.setMethod("sum")
self.assertEqual(roi.getProfileMethod(), "sum")
- # ROI to GUI
+ # ROI to GUI
roi.setProfileLineWidth(3)
self.assertEqual(editor._lineWidth.value(), 3)
roi.setProfileMethod("mean")
self.assertEqual(editor._methodsButton.getMethod(), "mean")
elif isinstance(editor, editors._DefaultScatterProfileRoiEditor):
- # GUI to ROI
+ # GUI to ROI
editor._nPoints.setValue(100)
self.assertEqual(roi.getNPoints(), 100)
- # ROI to GUI
+ # ROI to GUI
roi.setNPoints(200)
self.assertEqual(editor._nPoints.value(), 200)
else:
@@ -268,17 +263,32 @@ class TestInteractions(TestCaseQt):
(rois.ProfileImageVerticalLineROI, editors._DefaultImageProfileRoiEditor),
(rois.ProfileImageLineROI, editors._DefaultImageProfileRoiEditor),
(rois.ProfileImageCrossROI, editors._DefaultImageProfileRoiEditor),
- (rois.ProfileScatterHorizontalLineROI, editors._DefaultScatterProfileRoiEditor),
- (rois.ProfileScatterVerticalLineROI, editors._DefaultScatterProfileRoiEditor),
+ (
+ rois.ProfileScatterHorizontalLineROI,
+ editors._DefaultScatterProfileRoiEditor,
+ ),
+ (
+ rois.ProfileScatterVerticalLineROI,
+ editors._DefaultScatterProfileRoiEditor,
+ ),
(rois.ProfileScatterLineROI, editors._DefaultScatterProfileRoiEditor),
(rois.ProfileScatterCrossROI, editors._DefaultScatterProfileRoiEditor),
(rois.ProfileScatterHorizontalSliceROI, editors._NoProfileRoiEditor),
(rois.ProfileScatterVerticalSliceROI, editors._NoProfileRoiEditor),
(rois.ProfileScatterCrossSliceROI, editors._NoProfileRoiEditor),
- (rois.ProfileImageStackHorizontalLineROI, editors._DefaultImageStackProfileRoiEditor),
- (rois.ProfileImageStackVerticalLineROI, editors._DefaultImageStackProfileRoiEditor),
+ (
+ rois.ProfileImageStackHorizontalLineROI,
+ editors._DefaultImageStackProfileRoiEditor,
+ ),
+ (
+ rois.ProfileImageStackVerticalLineROI,
+ editors._DefaultImageStackProfileRoiEditor,
+ ),
(rois.ProfileImageStackLineROI, editors._DefaultImageStackProfileRoiEditor),
- (rois.ProfileImageStackCrossROI, editors._DefaultImageStackProfileRoiEditor),
+ (
+ rois.ProfileImageStackCrossROI,
+ editors._DefaultImageStackProfileRoiEditor,
+ ),
]
with self.defaultPlot() as plot:
profileManager = manager.ProfileManager(plot, plot)
@@ -288,7 +298,7 @@ class TestInteractions(TestCaseQt):
roi = roiClass()
roi._setProfileManager(profileManager)
try:
- # Force widget creation
+ # Force widget creation
menu = qt.QMenu(plot)
menu.addAction(editorAction)
widgets = editorAction.createdWidgets()
@@ -319,10 +329,8 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
self.mouseMove(self.plot) # Move to center
self.qapp.processEvents()
- deprecation.FORCE = True
def tearDown(self):
- deprecation.FORCE = False
self.qapp.processEvents()
profileManager = self.toolBar.getProfileManager()
profileManager.clearProfile()
@@ -338,7 +346,7 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
"""Test horizontal and vertical profile, without and with image"""
# Use Plot backend widget to submit mouse events
widget = self.plot.getWidgetHandle()
- for method in ('sum', 'mean'):
+ for method in ("sum", "mean"):
with self.subTest(method=method):
# 2 positions to use for mouse events
pos1 = widget.width() * 0.4, widget.height() * 0.4
@@ -353,8 +361,7 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)
# with image
- self.plot.addImage(
- numpy.arange(100 * 100).reshape(100, -1))
+ self.plot.addImage(numpy.arange(100 * 100).reshape(100, -1))
self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
self.mouseMove(widget, pos=pos2)
self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)
@@ -368,16 +375,14 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
if not manager.hasPendingOperations():
break
- @testutils.validate_logging(deprecation.depreclog.name, warning=4)
def testDiagonalProfile(self):
"""Test diagonal profile, without and with image"""
# Use Plot backend widget to submit mouse events
widget = self.plot.getWidgetHandle()
- self.plot.addImage(
- numpy.arange(100 * 100).reshape(100, -1))
+ self.plot.addImage(numpy.arange(100 * 100).reshape(100, -1))
- for method in ('sum', 'mean'):
+ for method in ("sum", "mean"):
with self.subTest(method=method):
# 2 positions to use for mouse events
pos1 = widget.width() * 0.4, widget.height() * 0.4
@@ -414,10 +419,12 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
if not manager.hasPendingOperations():
break
- curveItem = self.toolBar.getProfilePlot().getAllCurves()[0]
- if method == 'sum':
+ curveItem = (
+ roi.getProfileWindow().getCurrentPlotWidget().getAllCurves()[0]
+ )
+ if method == "sum":
self.assertTrue(curveItem.getData()[1].max() > 10000)
- elif method == 'mean':
+ elif method == "mean":
self.assertTrue(curveItem.getData()[1].max() < 10000)
# Remove the ROI so the profile window is also removed
@@ -426,77 +433,26 @@ class TestProfileToolBar(TestCaseQt, ParametricTestCase):
self.qWait(100)
-class TestDeprecatedProfileToolBar(TestCaseQt):
- """Tests old features of the ProfileToolBar widget."""
-
- def setUp(self):
- self.plot = None
- super(TestDeprecatedProfileToolBar, self).setUp()
-
- def tearDown(self):
- if self.plot is not None:
- self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
- self.plot.close()
- self.plot = None
- self.qWait()
-
- super(TestDeprecatedProfileToolBar, self).tearDown()
-
- @testutils.validate_logging(deprecation.depreclog.name, warning=2)
- def testCustomProfileWindow(self):
- from silx.gui.plot import ProfileMainWindow
-
- self.plot = PlotWindow()
- profileWindow = ProfileMainWindow.ProfileMainWindow(self.plot)
- toolBar = Profile.ProfileToolBar(parent=self.plot,
- plot=self.plot,
- profileWindow=profileWindow)
-
- self.plot.show()
- self.qWaitForWindowExposed(self.plot)
- profileWindow.show()
- self.qWaitForWindowExposed(profileWindow)
- self.qapp.processEvents()
-
- self.plot.addImage(numpy.arange(10 * 10).reshape(10, -1))
- profile = rois.ProfileImageHorizontalLineROI()
- profile.setPosition(5)
- toolBar.getProfileManager().getRoiManager().addRoi(profile)
- toolBar.getProfileManager().getRoiManager().setCurrentRoi(profile)
-
- for _ in range(20):
- self.qWait(200)
- if not toolBar.getProfileManager().hasPendingOperations():
- break
-
- # There is a displayed profile
- self.assertIsNotNone(profileWindow.getProfile())
- self.assertIs(toolBar.getProfileMainWindow(), profileWindow)
-
- # There is nothing anymore but the window is still there
- toolBar.getProfileManager().clearProfile()
- self.qapp.processEvents()
- self.assertIsNone(profileWindow.getProfile())
-
-
class TestProfile3DToolBar(TestCaseQt):
- """Tests for Profile3DToolBar widget.
- """
+ """Tests for Profile3DToolBar widget."""
+
def setUp(self):
super(TestProfile3DToolBar, self).setUp()
self.plot = StackView()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
- self.plot.setStack(numpy.array([
- [[0, 1, 2], [3, 4, 5]],
- [[6, 7, 8], [9, 10, 11]],
- [[12, 13, 14], [15, 16, 17]]
- ]))
- deprecation.FORCE = True
+ self.plot.setStack(
+ numpy.array(
+ [
+ [[0, 1, 2], [3, 4, 5]],
+ [[6, 7, 8], [9, 10, 11]],
+ [[12, 13, 14], [15, 16, 17]],
+ ]
+ )
+ )
def tearDown(self):
- deprecation.FORCE = False
profileManager = self.plot.getProfileToolbar().getProfileManager()
profileManager.clearProfile()
profileManager = None
@@ -506,7 +462,6 @@ class TestProfile3DToolBar(TestCaseQt):
super(TestProfile3DToolBar, self).tearDown()
- @testutils.validate_logging(deprecation.depreclog.name, warning=2)
def testMethodProfile2D(self):
"""Test that the profile can have a different method if we want to
compute then in 1D or in 2D"""
@@ -530,15 +485,13 @@ class TestProfile3DToolBar(TestCaseQt):
break
# check 2D 'mean' profile
- profilePlot = toolBar.getProfilePlot()
+ profilePlot = roi.getProfileWindow().getCurrentPlotWidget()
data = profilePlot.getAllImages()[0].getData()
expected = numpy.array([[1, 4], [7, 10], [13, 16]])
numpy.testing.assert_almost_equal(data, expected)
- @testutils.validate_logging(deprecation.depreclog.name, warning=2)
def testMethodSumLine(self):
- """Simple interaction test to make sure the sum is correctly computed
- """
+ """Simple interaction test to make sure the sum is correctly computed"""
toolBar = self.plot.getProfileToolbar()
toolBar.lineAction.trigger()
@@ -563,14 +516,13 @@ class TestProfile3DToolBar(TestCaseQt):
break
# check 2D 'sum' profile
- profilePlot = toolBar.getProfilePlot()
+ profilePlot = roi.getProfileWindow().getCurrentPlotWidget()
data = profilePlot.getAllImages()[0].getData()
expected = numpy.array([[3, 12], [21, 30], [39, 48]])
numpy.testing.assert_almost_equal(data, expected)
class TestGetProfilePlot(TestCaseQt):
-
def setUp(self):
self.plot = None
super(TestGetProfilePlot, self).setUp()
@@ -618,8 +570,7 @@ class TestGetProfilePlot(TestCaseQt):
self.plot.show()
self.qWaitForWindowExposed(self.plot)
- self.plot.setStack(numpy.array([[[0, 1], [2, 3]],
- [[4, 5], [6, 7]]]))
+ self.plot.setStack(numpy.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]))
toolBar = self.plot.getProfileToolbar()