summaryrefslogtreecommitdiff
path: root/silx/gui/plot/test
diff options
context:
space:
mode:
authorAlexandre Marie <alexandre.marie@synchrotron-soleil.fr>2018-12-17 12:28:24 +0100
committerAlexandre Marie <alexandre.marie@synchrotron-soleil.fr>2018-12-17 12:28:24 +0100
commitcebdc9244c019224846cb8d2668080fe386a6adc (patch)
treeaedec55da0f9dd4fc4d6c7eb0f58489a956e2e8c /silx/gui/plot/test
parent159ef14fb9e198bb0066ea14e6b980f065de63dd (diff)
New upstream version 0.9.0+dfsg
Diffstat (limited to 'silx/gui/plot/test')
-rw-r--r--silx/gui/plot/test/__init__.py6
-rw-r--r--silx/gui/plot/test/testAlphaSlider.py2
-rw-r--r--silx/gui/plot/test/testColorBar.py2
-rw-r--r--silx/gui/plot/test/testCompareImages.py117
-rw-r--r--silx/gui/plot/test/testCurvesROIWidget.py2
-rw-r--r--silx/gui/plot/test/testImageView.py2
-rw-r--r--silx/gui/plot/test/testItem.py2
-rw-r--r--silx/gui/plot/test/testLegendSelector.py2
-rw-r--r--silx/gui/plot/test/testMaskToolsWidget.py8
-rw-r--r--silx/gui/plot/test/testPixelIntensityHistoAction.py2
-rw-r--r--silx/gui/plot/test/testPlotWidget.py203
-rw-r--r--silx/gui/plot/test/testPlotWindow.py2
-rw-r--r--silx/gui/plot/test/testProfile.py198
-rw-r--r--silx/gui/plot/test/testScatterMaskToolsWidget.py8
-rw-r--r--silx/gui/plot/test/testScatterView.py19
-rw-r--r--silx/gui/plot/test/testStackView.py7
-rw-r--r--silx/gui/plot/test/testStats.py3
-rw-r--r--silx/gui/plot/test/testUtilsAxis.py2
-rw-r--r--silx/gui/plot/test/utils.py2
19 files changed, 498 insertions, 91 deletions
diff --git a/silx/gui/plot/test/__init__.py b/silx/gui/plot/test/__init__.py
index 1428bad..89c10c6 100644
--- a/silx/gui/plot/test/__init__.py
+++ b/silx/gui/plot/test/__init__.py
@@ -24,7 +24,7 @@
# ###########################################################################*/
__authors__ = ["T. Vincent"]
__license__ = "MIT"
-__date__ = "24/04/2018"
+__date__ = "23/07/2018"
import unittest
@@ -52,6 +52,7 @@ from . import testImageView
from . import testSaveAction
from . import testScatterView
from . import testPixelIntensityHistoAction
+from . import testCompareImages
def suite():
@@ -83,6 +84,7 @@ def suite():
testImageView.suite(),
testSaveAction.suite(),
testScatterView.suite(),
- testPixelIntensityHistoAction.suite()
+ testPixelIntensityHistoAction.suite(),
+ testCompareImages.suite()
])
return test_suite
diff --git a/silx/gui/plot/test/testAlphaSlider.py b/silx/gui/plot/test/testAlphaSlider.py
index 304a562..63de441 100644
--- a/silx/gui/plot/test/testAlphaSlider.py
+++ b/silx/gui/plot/test/testAlphaSlider.py
@@ -33,7 +33,7 @@ import numpy
import unittest
from silx.gui import qt
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import PlotWidget
from silx.gui.plot import AlphaSlider
diff --git a/silx/gui/plot/test/testColorBar.py b/silx/gui/plot/test/testColorBar.py
index 0d1c952..9a02e04 100644
--- a/silx/gui/plot/test/testColorBar.py
+++ b/silx/gui/plot/test/testColorBar.py
@@ -29,7 +29,7 @@ __license__ = "MIT"
__date__ = "24/04/2018"
import unittest
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot.ColorBar import _ColorScale
from silx.gui.plot.ColorBar import ColorBarWidget
from silx.gui.colors import Colormap
diff --git a/silx/gui/plot/test/testCompareImages.py b/silx/gui/plot/test/testCompareImages.py
new file mode 100644
index 0000000..ed6942a
--- /dev/null
+++ b/silx/gui/plot/test/testCompareImages.py
@@ -0,0 +1,117 @@
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2016-2017 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
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""Tests for CompareImages widget"""
+
+__authors__ = ["H. Payno"]
+__license__ = "MIT"
+__date__ = "23/07/2018"
+
+import unittest
+import numpy
+import weakref
+
+from silx.gui.utils.testutils import TestCaseQt
+from silx.gui.plot.CompareImages import CompareImages
+
+
+class TestCompareImages(TestCaseQt):
+ """Test that CompareImages widget is working in some cases"""
+
+ def setUp(self):
+ super(TestCompareImages, self).setUp()
+ self.widget = CompareImages()
+
+ def tearDown(self):
+ ref = weakref.ref(self.widget)
+ self.widget = None
+ self.qWaitForDestroy(ref)
+ super(TestCompareImages, self).tearDown()
+
+ def testIntensityImage(self):
+ image1 = numpy.random.rand(10, 10)
+ image2 = numpy.random.rand(10, 10)
+ self.widget.setData(image1, image2)
+
+ def testRgbImage(self):
+ image1 = numpy.random.randint(0, 255, size=(10, 10, 3))
+ image2 = numpy.random.randint(0, 255, size=(10, 10, 3))
+ self.widget.setData(image1, image2)
+
+ def testRgbaImage(self):
+ image1 = numpy.random.randint(0, 255, size=(10, 10, 4))
+ image2 = numpy.random.randint(0, 255, size=(10, 10, 4))
+ self.widget.setData(image1, image2)
+
+ def testVizualisations(self):
+ image1 = numpy.random.rand(10, 10)
+ image2 = numpy.random.rand(10, 10)
+ self.widget.setData(image1, image2)
+ for mode in CompareImages.VisualizationMode:
+ self.widget.setVisualizationMode(mode)
+
+ def testAlignemnt(self):
+ image1 = numpy.random.rand(10, 10)
+ image2 = numpy.random.rand(5, 5)
+ self.widget.setData(image1, image2)
+ for mode in CompareImages.AlignmentMode:
+ self.widget.setAlignmentMode(mode)
+
+ def testGetPixel(self):
+ image1 = numpy.random.rand(11, 11)
+ image2 = numpy.random.rand(5, 5)
+ image1[5, 5] = 111.111
+ image2[2, 2] = 222.222
+ self.widget.setData(image1, image2)
+ expectedValue = {}
+ expectedValue[CompareImages.AlignmentMode.CENTER] = 222.222
+ expectedValue[CompareImages.AlignmentMode.STRETCH] = 222.222
+ expectedValue[CompareImages.AlignmentMode.ORIGIN] = None
+ for mode in expectedValue.keys():
+ self.widget.setAlignmentMode(mode)
+ data = self.widget.getRawPixelData(11 / 2.0, 11 / 2.0)
+ data1, data2 = data
+ self.assertEqual(data1, 111.111)
+ self.assertEqual(data2, expectedValue[mode])
+
+ def testImageEmpty(self):
+ self.widget.setData(image1=None, image2=None)
+ self.assertTrue(self.widget.getRawPixelData(11 / 2.0, 11 / 2.0) == (None, None))
+
+ def testSetImageSeparately(self):
+ self.widget.setImage1(numpy.random.rand(10, 10))
+ self.widget.setImage2(numpy.random.rand(10, 10))
+ for mode in CompareImages.VisualizationMode:
+ self.widget.setVisualizationMode(mode)
+
+
+def suite():
+ test_suite = unittest.TestSuite()
+ loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
+ test_suite.addTest(loadTests(TestCompareImages))
+ return test_suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
diff --git a/silx/gui/plot/test/testCurvesROIWidget.py b/silx/gui/plot/test/testCurvesROIWidget.py
index 7a2e3d1..0704779 100644
--- a/silx/gui/plot/test/testCurvesROIWidget.py
+++ b/silx/gui/plot/test/testCurvesROIWidget.py
@@ -36,7 +36,7 @@ from collections import OrderedDict
import numpy
from silx.gui import qt
from silx.test.utils import temp_dir
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import PlotWindow, CurvesROIWidget
diff --git a/silx/gui/plot/test/testImageView.py b/silx/gui/plot/test/testImageView.py
index 5059a0b..3c8d84c 100644
--- a/silx/gui/plot/test/testImageView.py
+++ b/silx/gui/plot/test/testImageView.py
@@ -33,7 +33,7 @@ import unittest
import numpy
from silx.gui import qt
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import ImageView
from silx.gui.colors import Colormap
diff --git a/silx/gui/plot/test/testItem.py b/silx/gui/plot/test/testItem.py
index 1ba09c6..993cce7 100644
--- a/silx/gui/plot/test/testItem.py
+++ b/silx/gui/plot/test/testItem.py
@@ -33,7 +33,7 @@ import unittest
import numpy
-from silx.gui.test.utils import SignalListener
+from silx.gui.utils.testutils import SignalListener
from silx.gui.plot.items import ItemChangedType
from .utils import PlotWidgetTestCase
diff --git a/silx/gui/plot/test/testLegendSelector.py b/silx/gui/plot/test/testLegendSelector.py
index 9d4ada7..de5ffde 100644
--- a/silx/gui/plot/test/testLegendSelector.py
+++ b/silx/gui/plot/test/testLegendSelector.py
@@ -33,7 +33,7 @@ import logging
import unittest
from silx.gui import qt
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import LegendSelector
diff --git a/silx/gui/plot/test/testMaskToolsWidget.py b/silx/gui/plot/test/testMaskToolsWidget.py
index 40c1db3..6912ea3 100644
--- a/silx/gui/plot/test/testMaskToolsWidget.py
+++ b/silx/gui/plot/test/testMaskToolsWidget.py
@@ -38,7 +38,7 @@ import numpy
from silx.gui import qt
from silx.test.utils import temp_dir
from silx.utils.testutils import ParametricTestCase
-from silx.gui.test.utils import getQToolButtonFromAction
+from silx.gui.utils.testutils import getQToolButtonFromAction
from silx.gui.plot import PlotWindow, MaskToolsWidget
from .utils import PlotWidgetTestCase
@@ -87,10 +87,10 @@ class TestMaskToolsWidget(PlotWidgetTestCase, ParametricTestCase):
self.mouseMove(plot, pos=(0, 0))
self.mouseMove(plot, pos=pos0)
- self.mousePress(plot, qt.Qt.LeftButton, pos=pos0)
+ self.mouseClick(plot, qt.Qt.LeftButton, pos=pos0)
self.mouseMove(plot, pos=(0, 0))
self.mouseMove(plot, pos=pos1)
- self.mouseRelease(plot, qt.Qt.LeftButton, pos=pos1)
+ self.mouseClick(plot, qt.Qt.LeftButton, pos=pos1)
def _drawPolygon(self):
"""Draw a star polygon in the plot"""
@@ -108,7 +108,9 @@ class TestMaskToolsWidget(PlotWidgetTestCase, ParametricTestCase):
self.mouseMove(plot, pos=(0, 0))
for pos in star:
self.mouseMove(plot, pos=pos)
+ self.qapp.processEvents()
self.mouseClick(plot, qt.Qt.LeftButton, pos=pos)
+ self.qapp.processEvents()
def _drawPencil(self):
"""Draw a star polygon in the plot"""
diff --git a/silx/gui/plot/test/testPixelIntensityHistoAction.py b/silx/gui/plot/test/testPixelIntensityHistoAction.py
index 987e5b2..20d1ea2 100644
--- a/silx/gui/plot/test/testPixelIntensityHistoAction.py
+++ b/silx/gui/plot/test/testPixelIntensityHistoAction.py
@@ -33,7 +33,7 @@ import numpy
import unittest
from silx.utils.testutils import ParametricTestCase
-from silx.gui.test.utils import TestCaseQt, getQToolButtonFromAction
+from silx.gui.utils.testutils import TestCaseQt, getQToolButtonFromAction
from silx.gui import qt
from silx.gui.plot import Plot2D
diff --git a/silx/gui/plot/test/testPlotWidget.py b/silx/gui/plot/test/testPlotWidget.py
index dac6580..857b9bc 100644
--- a/silx/gui/plot/test/testPlotWidget.py
+++ b/silx/gui/plot/test/testPlotWidget.py
@@ -26,7 +26,7 @@
__authors__ = ["T. Vincent"]
__license__ = "MIT"
-__date__ = "24/04/2018"
+__date__ = "21/09/2018"
import unittest
@@ -34,8 +34,8 @@ import logging
import numpy
from silx.utils.testutils import ParametricTestCase, parameterize
-from silx.gui.test.utils import SignalListener
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import SignalListener
+from silx.gui.utils.testutils import TestCaseQt
from silx.utils import testutils
from silx.utils import deprecation
@@ -43,6 +43,7 @@ from silx.test.utils import test_options
from silx.gui import qt
from silx.gui.plot import PlotWidget
+from silx.gui.plot.items.curve import CurveStyle
from silx.gui.colors import Colormap
from .utils import PlotWidgetTestCase
@@ -118,6 +119,7 @@ class TestPlotWidget(PlotWidgetTestCase, ParametricTestCase):
"""Test resizing the widget and receiving limitsChanged events"""
self.plot.resize(200, 200)
self.qapp.processEvents()
+ self.qWait(100)
xlim = self.plot.getXAxis().getLimits()
ylim = self.plot.getYAxis().getLimits()
@@ -129,18 +131,58 @@ class TestPlotWidget(PlotWidgetTestCase, ParametricTestCase):
# Resize without aspect ratio
self.plot.resize(200, 300)
self.qapp.processEvents()
+ self.qWait(100)
self._checkLimits(expectedXLim=xlim, expectedYLim=ylim)
self.assertEqual(listener.callCount(), 0)
# Resize with aspect ratio
self.plot.setKeepDataAspectRatio(True)
self.qapp.processEvents()
+ self.qWait(1000)
listener.clear() # Clean-up received signal
self.plot.resize(200, 200)
self.qapp.processEvents()
+ self.qWait(100)
self.assertNotEqual(listener.callCount(), 0)
+ def testAddRemoveItemSignals(self):
+ """Test sigItemAdded and sigItemAboutToBeRemoved"""
+ listener = SignalListener()
+ self.plot.sigItemAdded.connect(listener.partial('add'))
+ self.plot.sigItemAboutToBeRemoved.connect(listener.partial('remove'))
+
+ self.plot.addCurve((1, 2, 3), (3, 2, 1), legend='curve')
+ self.assertEqual(listener.callCount(), 1)
+
+ curve = self.plot.getCurve('curve')
+ self.plot.remove('curve')
+ self.assertEqual(listener.callCount(), 2)
+ self.assertEqual(listener.arguments(callIndex=0), ('add', curve))
+ self.assertEqual(listener.arguments(callIndex=1), ('remove', curve))
+
+ def testGetItems(self):
+ """Test getItems method"""
+ curve_x = 1, 2
+ self.plot.addCurve(curve_x, (3, 4))
+ image = (0, 1), (2, 3)
+ self.plot.addImage(image)
+ scatter_x = 10, 11
+ self.plot.addScatter(scatter_x, (12, 13), (0, 1))
+ marker_pos = 5, 5
+ self.plot.addMarker(*marker_pos)
+ marker_x = 6
+ self.plot.addXMarker(marker_x)
+ self.plot.addItem((0, 5), (2, 10), shape='rectangle')
+
+ items = self.plot.getItems()
+ self.assertEqual(len(items), 6)
+ self.assertTrue(numpy.all(numpy.equal(items[0].getXData(), curve_x)))
+ self.assertTrue(numpy.all(numpy.equal(items[1].getData(), image)))
+ self.assertTrue(numpy.all(numpy.equal(items[2].getXData(), scatter_x)))
+ self.assertTrue(numpy.all(numpy.equal(items[3].getPosition(), marker_pos)))
+ self.assertTrue(numpy.all(numpy.equal(items[4].getPosition()[0], marker_x)))
+ self.assertEqual(items[5].getType(), 'rectangle')
class TestPlotImage(PlotWidgetTestCase, ParametricTestCase):
"""Basic tests for addImage"""
@@ -270,10 +312,10 @@ class TestPlotImage(PlotWidgetTestCase, ParametricTestCase):
self.plot.setKeepDataAspectRatio(True)
xmin, xmax = self.plot.getXAxis().getLimits()
ymin, ymax = self.plot.getYAxis().getLimits()
- self.assertTrue(xmin <= min(xbounds))
- self.assertTrue(xmax >= max(xbounds))
- self.assertTrue(ymin <= min(ybounds))
- self.assertTrue(ymax >= max(ybounds))
+ self.assertTrue(round(xmin, 7) <= min(xbounds))
+ self.assertTrue(round(xmax, 7) >= max(xbounds))
+ self.assertTrue(round(ymin, 7) <= min(ybounds))
+ self.assertTrue(round(ymax, 7) >= max(ybounds))
self.plot.setKeepDataAspectRatio(False) # Reset aspect ratio
self.plot.clear()
@@ -390,8 +432,7 @@ class TestPlotCurve(PlotWidgetTestCase):
self.plot.addCurve(self.xData, self.yData,
legend="curve 2",
replace=False, resetzoom=False,
- color=color, symbol='o')
-
+ color=color, symbol='o')
class TestPlotMarker(PlotWidgetTestCase):
"""Basic tests for add*Marker"""
@@ -562,7 +603,15 @@ class TestPlotItem(PlotWidgetTestCase):
class TestPlotActiveCurveImage(PlotWidgetTestCase):
- """Basic tests for active image handling"""
+ """Basic tests for active curve and image handling"""
+ xData = numpy.arange(1000)
+ yData = -500 + 100 * numpy.sin(xData)
+ xData2 = xData + 1000
+ yData2 = xData - 1000 + 200 * numpy.random.random(1000)
+
+ def tearDown(self):
+ self.plot.setActiveCurveHandling(False)
+ super(TestPlotActiveCurveImage, self).tearDown()
def testActiveCurveAndLabels(self):
# Active curve handling off, no label change
@@ -589,6 +638,7 @@ class TestPlotActiveCurveImage(PlotWidgetTestCase):
# labels changed as active curve
self.plot.addCurve((1, 2), (1, 2), legend='1',
xlabel='x1', ylabel='y1')
+ self.plot.setActiveCurve('1')
self.assertEqual(self.plot.getXAxis().getLabel(), 'x1')
self.assertEqual(self.plot.getYAxis().getLabel(), 'y1')
@@ -610,6 +660,110 @@ class TestPlotActiveCurveImage(PlotWidgetTestCase):
self.assertEqual(self.plot.getXAxis().getLabel(), 'XLabel')
self.assertEqual(self.plot.getYAxis().getLabel(), 'YLabel')
+ def testPlotActiveCurveSelectionMode(self):
+ self.plot.clear()
+ self.plot.setActiveCurveHandling(True)
+ legend = "curve 1"
+ self.plot.addCurve(self.xData, self.yData,
+ legend=legend,
+ color="green")
+
+ # active curve should be None
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), None)
+
+ # active curve should be None when None is set as active curve
+ self.plot.setActiveCurve(legend)
+ current = self.plot.getActiveCurve(just_legend=True)
+ self.assertEqual(current, legend)
+ self.plot.setActiveCurve(None)
+ current = self.plot.getActiveCurve(just_legend=True)
+ self.assertEqual(current, None)
+
+ # testing it automatically toggles if there is only one
+ self.plot.setActiveCurveSelectionMode("legacy")
+ current = self.plot.getActiveCurve(just_legend=True)
+ self.assertEqual(current, legend)
+
+ # active curve should not change when None set as active curve
+ self.assertEqual(self.plot.getActiveCurveSelectionMode(), "legacy")
+ self.plot.setActiveCurve(None)
+ current = self.plot.getActiveCurve(just_legend=True)
+ self.assertEqual(current, legend)
+
+ # situation where no curve is active
+ self.plot.clear()
+ self.plot.setActiveCurveHandling(True)
+ self.assertEqual(self.plot.getActiveCurveSelectionMode(), "atmostone")
+ self.plot.addCurve(self.xData, self.yData,
+ legend=legend,
+ color="green")
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), None)
+ self.plot.addCurve(self.xData2, self.yData2,
+ legend="curve 2",
+ color="red")
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), None)
+ self.plot.setActiveCurveSelectionMode("legacy")
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), None)
+
+ # the first curve added should be active
+ self.plot.clear()
+ self.plot.addCurve(self.xData, self.yData,
+ legend=legend,
+ color="green")
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), legend)
+ self.plot.addCurve(self.xData2, self.yData2,
+ legend="curve 2",
+ color="red")
+ self.assertEqual(self.plot.getActiveCurve(just_legend=True), legend)
+
+ def testActiveCurveStyle(self):
+ """Test change of active curve style"""
+ self.plot.setActiveCurveHandling(True)
+ self.plot.setActiveCurveStyle(color='black')
+ style = self.plot.getActiveCurveStyle()
+ self.assertEqual(style.getColor(), (0., 0., 0., 1.))
+ self.assertIsNone(style.getLineStyle())
+ self.assertIsNone(style.getLineWidth())
+ self.assertIsNone(style.getSymbol())
+ self.assertIsNone(style.getSymbolSize())
+
+ self.plot.addCurve(x=self.xData, y=self.yData, legend="curve1")
+ curve = self.plot.getCurve("curve1")
+ curve.setColor('blue')
+ curve.setLineStyle('-')
+ curve.setLineWidth(1)
+ curve.setSymbol('o')
+ curve.setSymbolSize(5)
+
+ # Check default current style
+ defaultStyle = curve.getCurrentStyle()
+ self.assertEqual(defaultStyle, CurveStyle(color='blue',
+ linestyle='-',
+ linewidth=1,
+ symbol='o',
+ symbolsize=5))
+
+ # Activate curve with highlight color=black
+ self.plot.setActiveCurve("curve1")
+ style = curve.getCurrentStyle()
+ self.assertEqual(style.getColor(), (0., 0., 0., 1.))
+ self.assertEqual(style.getLineStyle(), '-')
+ self.assertEqual(style.getLineWidth(), 1)
+ self.assertEqual(style.getSymbol(), 'o')
+ self.assertEqual(style.getSymbolSize(), 5)
+
+ # Change highlight to linewidth=2
+ self.plot.setActiveCurveStyle(linewidth=2)
+ style = curve.getCurrentStyle()
+ self.assertEqual(style.getColor(), (0., 0., 1., 1.))
+ self.assertEqual(style.getLineStyle(), '-')
+ self.assertEqual(style.getLineWidth(), 2)
+ self.assertEqual(style.getSymbol(), 'o')
+ self.assertEqual(style.getSymbolSize(), 5)
+
+ self.plot.setActiveCurve(None)
+ self.assertEqual(curve.getCurrentStyle(), defaultStyle)
+
def testActiveImageAndLabels(self):
# Active image handling always on, no API for toggling it
self.plot.getXAxis().setLabel('XLabel')
@@ -881,7 +1035,7 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
self.plot.getYAxis(axis="right").sigLimitsChanged.connect(listener.partial(axis="y2"))
self.plot.setLimits(0, 1, 0, 1, 0, 1)
# at least one event per axis
- self.assertEquals(len(set(listener.karguments(argumentName="axis"))), 3)
+ self.assertEqual(len(set(listener.karguments(argumentName="axis"))), 3)
def testLimitsChanged_resetZoom(self):
self.plot.addCurve(self.xData, self.yData,
@@ -894,7 +1048,7 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
self.plot.getYAxis(axis="right").sigLimitsChanged.connect(listener.partial(axis="y2"))
self.plot.resetZoom()
# at least one event per axis
- self.assertEquals(len(set(listener.karguments(argumentName="axis"))), 3)
+ self.assertEqual(len(set(listener.karguments(argumentName="axis"))), 3)
def testLimitsChanged_setXLimit(self):
self.plot.addCurve(self.xData, self.yData,
@@ -906,8 +1060,8 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
axis.sigLimitsChanged.connect(listener)
axis.setLimits(20, 30)
# at least one event per axis
- self.assertEquals(listener.arguments(callIndex=-1), (20.0, 30.0))
- self.assertEquals(axis.getLimits(), (20.0, 30.0))
+ self.assertEqual(listener.arguments(callIndex=-1), (20.0, 30.0))
+ self.assertEqual(axis.getLimits(), (20.0, 30.0))
def testLimitsChanged_setYLimit(self):
self.plot.addCurve(self.xData, self.yData,
@@ -919,8 +1073,8 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
axis.sigLimitsChanged.connect(listener)
axis.setLimits(20, 30)
# at least one event per axis
- self.assertEquals(listener.arguments(callIndex=-1), (20.0, 30.0))
- self.assertEquals(axis.getLimits(), (20.0, 30.0))
+ self.assertEqual(listener.arguments(callIndex=-1), (20.0, 30.0))
+ self.assertEqual(axis.getLimits(), (20.0, 30.0))
def testLimitsChanged_setYRightLimit(self):
self.plot.addCurve(self.xData, self.yData,
@@ -932,8 +1086,8 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
axis.sigLimitsChanged.connect(listener)
axis.setLimits(20, 30)
# at least one event per axis
- self.assertEquals(listener.arguments(callIndex=-1), (20.0, 30.0))
- self.assertEquals(axis.getLimits(), (20.0, 30.0))
+ self.assertEqual(listener.arguments(callIndex=-1), (20.0, 30.0))
+ self.assertEqual(axis.getLimits(), (20.0, 30.0))
def testScaleProxy(self):
listener = SignalListener()
@@ -943,9 +1097,9 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
yright.sigScaleChanged.connect(listener.partial("right"))
yright.setScale(yright.LOGARITHMIC)
- self.assertEquals(y.getScale(), y.LOGARITHMIC)
+ self.assertEqual(y.getScale(), y.LOGARITHMIC)
events = listener.arguments()
- self.assertEquals(len(events), 2)
+ self.assertEqual(len(events), 2)
self.assertIn(("left", y.LOGARITHMIC), events)
self.assertIn(("right", y.LOGARITHMIC), events)
@@ -957,9 +1111,9 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
yright.sigAutoScaleChanged.connect(listener.partial("right"))
yright.setAutoScale(False)
- self.assertEquals(y.isAutoScale(), False)
+ self.assertEqual(y.isAutoScale(), False)
events = listener.arguments()
- self.assertEquals(len(events), 2)
+ self.assertEqual(len(events), 2)
self.assertIn(("left", False), events)
self.assertIn(("right", False), events)
@@ -971,9 +1125,9 @@ class TestPlotAxes(TestCaseQt, ParametricTestCase):
yright.sigInvertedChanged.connect(listener.partial("right"))
yright.setInverted(True)
- self.assertEquals(y.isInverted(), True)
+ self.assertEqual(y.isInverted(), True)
events = listener.arguments()
- self.assertEquals(len(events), 2)
+ self.assertEqual(len(events), 2)
self.assertIn(("left", True), events)
self.assertIn(("right", True), events)
@@ -1363,6 +1517,7 @@ class TestPlotItemLog(PlotWidgetTestCase):
def suite():
testClasses = (TestPlotWidget, TestPlotImage, TestPlotCurve,
TestPlotMarker, TestPlotItem, TestPlotAxes,
+ TestPlotActiveCurveImage,
TestPlotEmptyLog, TestPlotCurveLog, TestPlotImageLog,
TestPlotMarkerLog, TestPlotItemLog)
diff --git a/silx/gui/plot/test/testPlotWindow.py b/silx/gui/plot/test/testPlotWindow.py
index 24d840b..6d3eb8f 100644
--- a/silx/gui/plot/test/testPlotWindow.py
+++ b/silx/gui/plot/test/testPlotWindow.py
@@ -32,7 +32,7 @@ __date__ = "27/06/2017"
import doctest
import unittest
-from silx.gui.test.utils import TestCaseQt, getQToolButtonFromAction
+from silx.gui.utils.testutils import TestCaseQt, getQToolButtonFromAction
from silx.gui import qt
from silx.gui.plot import PlotWindow
diff --git a/silx/gui/plot/test/testProfile.py b/silx/gui/plot/test/testProfile.py
index 28d9669..847f404 100644
--- a/silx/gui/plot/test/testProfile.py
+++ b/silx/gui/plot/test/testProfile.py
@@ -32,7 +32,7 @@ import numpy
import unittest
from silx.utils.testutils import ParametricTestCase
-from silx.gui.test.utils import (
+from silx.gui.utils.testutils import (
TestCaseQt, getQToolButtonFromAction)
from silx.gui import qt
from silx.gui.plot import PlotWindow, Plot1D, Plot2D, Profile
@@ -75,58 +75,168 @@ 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'):
+ with self.subTest(method=method):
+ # 2 positions to use for mouse events
+ pos1 = widget.width() * 0.4, widget.height() * 0.4
+ pos2 = widget.width() * 0.6, widget.height() * 0.6
+
+ for action in (self.toolBar.hLineAction, self.toolBar.vLineAction):
+ with self.subTest(mode=action.text()):
+ # Trigger tool button for mode
+ toolButton = getQToolButtonFromAction(action)
+ self.assertIsNot(toolButton, None)
+ self.mouseMove(toolButton)
+ self.mouseClick(toolButton, qt.Qt.LeftButton)
+
+ # Without image
+ self.mouseMove(widget, pos=pos1)
+ self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)
+
+ # with image
+ 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)
+
+ self.mouseMove(widget)
+ self.mouseClick(widget, qt.Qt.LeftButton)
- # 2 positions to use for mouse events
- pos1 = widget.width() * 0.4, widget.height() * 0.4
- pos2 = widget.width() * 0.6, widget.height() * 0.6
+ def testDiagonalProfile(self):
+ """Test diagonal profile, without and with image"""
+ # Use Plot backend widget to submit mouse events
+ widget = self.plot.getWidgetHandle()
- for action in (self.toolBar.hLineAction, self.toolBar.vLineAction):
- with self.subTest(mode=action.text()):
- # Trigger tool button for mode
- toolButton = getQToolButtonFromAction(action)
- self.assertIsNot(toolButton, None)
- self.mouseMove(toolButton)
- self.mouseClick(toolButton, qt.Qt.LeftButton)
+ for method in ('sum', 'mean'):
+ with self.subTest(method=method):
+ self.toolBar.setProfileMethod(method)
+
+ # 2 positions to use for mouse events
+ pos1 = widget.width() * 0.4, widget.height() * 0.4
+ pos2 = widget.width() * 0.6, widget.height() * 0.6
+
+ for image in (False, True):
+ with self.subTest(image=image):
+ if image:
+ self.plot.addImage(
+ numpy.arange(100 * 100).reshape(100, -1))
+
+ # Trigger tool button for diagonal profile mode
+ toolButton = getQToolButtonFromAction(
+ self.toolBar.lineAction)
+ self.assertIsNot(toolButton, None)
+ self.mouseMove(toolButton)
+ self.mouseClick(toolButton, qt.Qt.LeftButton)
+ self.toolBar.lineWidthSpinBox.setValue(3)
+
+ # draw profile line
+ self.mouseMove(widget, pos=pos1)
+ self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
+ self.mouseMove(widget, pos=pos2)
+ self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)
+
+ if image is True:
+ profileCurve = self.toolBar.getProfilePlot().getAllCurves()[0]
+ if method == 'sum':
+ self.assertTrue(profileCurve.getData()[1].max() > 10000)
+ elif method == 'mean':
+ self.assertTrue(profileCurve.getData()[1].max() < 10000)
+ self.plot.clear()
+
+
+class TestProfile3DToolBar(TestCaseQt):
+ """Tests for Profile3DToolBar widget.
+ """
+ def setUp(self):
+ super(TestProfile3DToolBar, self).setUp()
+ self.plot = StackView()
+ self.plot.show()
+ self.qWaitForWindowExposed(self.plot)
- # Without image
- self.mouseMove(widget, pos=pos1)
- self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)
+ self.plot.setStack(numpy.array([
+ [[0, 1, 2], [3, 4, 5]],
+ [[6, 7, 8], [9, 10, 11]],
+ [[12, 13, 14], [15, 16, 17]]
+ ]))
- # with image
- 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)
+ def tearDown(self):
+ self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
+ self.plot.close()
+ self.plot = None
- self.mouseMove(widget)
- self.mouseClick(widget, qt.Qt.LeftButton)
+ super(TestProfile3DToolBar, self).tearDown()
- def testDiagonalProfile(self):
- """Test diagonal profile, without and with image"""
- # Use Plot backend widget to submit mouse events
- widget = self.plot.getWidgetHandle()
+ def testMethodProfile1DAnd2D(self):
+ """Test that the profile can have a different method if we want to
+ compute then in 1D or in 2D"""
- # 2 positions to use for mouse events
- pos1 = widget.width() * 0.4, widget.height() * 0.4
- pos2 = widget.width() * 0.6, widget.height() * 0.6
+ _3DProfileToolbar = self.plot.getProfileToolbar()
+ _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
+ self.plot.getProfileToolbar().setProfileMethod('mean')
+ self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
+ self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'mean')
- # Trigger tool button for diagonal profile mode
- toolButton = getQToolButtonFromAction(self.toolBar.lineAction)
+ # check 2D 'mean' profile
+ _3DProfileToolbar.profile3dAction.computeProfileIn2D()
+ toolButton = getQToolButtonFromAction(_3DProfileToolbar.vLineAction)
self.assertIsNot(toolButton, None)
self.mouseMove(toolButton)
self.mouseClick(toolButton, qt.Qt.LeftButton)
+ plot2D = self.plot.getPlot().getWidgetHandle()
+ pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
+ self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)
+ self.assertTrue(numpy.array_equal(
+ _2DProfilePlot.getActiveImage().getData(),
+ numpy.array([[1, 4], [7, 10], [13, 16]])
+ ))
+
+ # check 1D 'sum' profile
+ _2DProfileToolbar = _2DProfilePlot.getProfileToolbar()
+ _2DProfileToolbar.setProfileMethod('sum')
+ self.assertTrue(_2DProfileToolbar.getProfileMethod() == 'sum')
+ _1DProfilePlot = _2DProfileToolbar.getProfilePlot()
+
+ _2DProfileToolbar.lineWidthSpinBox.setValue(3)
+ toolButton = getQToolButtonFromAction(_2DProfileToolbar.vLineAction)
+ self.assertIsNot(toolButton, None)
+ self.mouseMove(toolButton)
+ self.mouseClick(toolButton, qt.Qt.LeftButton)
+ plot1D = _2DProfilePlot.getWidgetHandle()
+ pos1 = plot1D.width() * 0.5, plot1D.height() * 0.5
+ self.mouseClick(plot1D, qt.Qt.LeftButton, pos=pos1)
+ self.assertTrue(numpy.array_equal(
+ _1DProfilePlot.getAllCurves()[0].getData()[1],
+ numpy.array([5, 17, 29])
+ ))
+
+ def testMethodSumLine(self):
+ """Simple interaction test to make sure the sum is correctly computed
+ """
+ _3DProfileToolbar = self.plot.getProfileToolbar()
+ _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
+ self.plot.getProfileToolbar().setProfileMethod('sum')
+ self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
+ self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'sum')
+
+ # check 2D 'mean' profile
+ _3DProfileToolbar.profile3dAction.computeProfileIn2D()
+ toolButton = getQToolButtonFromAction(_3DProfileToolbar.lineAction)
+ self.assertIsNot(toolButton, None)
+ self.mouseMove(toolButton)
+ self.mouseClick(toolButton, qt.Qt.LeftButton)
+ plot2D = self.plot.getPlot().getWidgetHandle()
+ pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
+ pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8
- for image in (False, True):
- with self.subTest(image=image):
- if image:
- self.plot.addImage(numpy.arange(100 * 100).reshape(100, -1))
-
- self.mouseMove(widget, pos=pos1)
- self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
- self.mouseMove(widget, pos=pos2)
- self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)
-
- self.plot.clear()
+ self.mouseMove(plot2D, pos=pos1)
+ self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
+ self.mouseMove(plot2D, pos=pos2)
+ self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)
+ self.assertTrue(numpy.array_equal(
+ _2DProfilePlot.getActiveImage().getData(),
+ numpy.array([[3, 12], [21, 30], [39, 48]])
+ ))
class TestGetProfilePlot(TestCaseQt):
@@ -157,8 +267,6 @@ class TestGetProfilePlot(TestCaseQt):
self.assertIsInstance(plot.getProfileToolbar().getProfileMainWindow(),
qt.QMainWindow)
- # plot.getProfileToolbar().profile3dAction.computeProfileIn2D() # default
-
self.assertIsInstance(plot.getProfileToolbar().getProfilePlot(),
Plot2D)
plot.getProfileToolbar().profile3dAction.computeProfileIn1D()
@@ -172,8 +280,8 @@ class TestGetProfilePlot(TestCaseQt):
def suite():
test_suite = unittest.TestSuite()
- # test_suite.addTest(positionInfoTestSuite)
- for testClass in (TestProfileToolBar, TestGetProfilePlot):
+ for testClass in (TestProfileToolBar, TestGetProfilePlot,
+ TestProfile3DToolBar):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(
testClass))
return test_suite
diff --git a/silx/gui/plot/test/testScatterMaskToolsWidget.py b/silx/gui/plot/test/testScatterMaskToolsWidget.py
index 0342c8f..a446911 100644
--- a/silx/gui/plot/test/testScatterMaskToolsWidget.py
+++ b/silx/gui/plot/test/testScatterMaskToolsWidget.py
@@ -38,7 +38,7 @@ import numpy
from silx.gui import qt
from silx.test.utils import temp_dir
from silx.utils.testutils import ParametricTestCase
-from silx.gui.test.utils import getQToolButtonFromAction
+from silx.gui.utils.testutils import getQToolButtonFromAction
from silx.gui.plot import PlotWindow, ScatterMaskToolsWidget
from .utils import PlotWidgetTestCase
@@ -89,10 +89,10 @@ class TestScatterMaskToolsWidget(PlotWidgetTestCase, ParametricTestCase):
self.mouseMove(plot, pos=(0, 0))
self.mouseMove(plot, pos=pos0)
- self.mousePress(plot, qt.Qt.LeftButton, pos=pos0)
+ self.mouseClick(plot, qt.Qt.LeftButton, pos=pos0)
self.mouseMove(plot, pos=(0, 0))
self.mouseMove(plot, pos=pos1)
- self.mouseRelease(plot, qt.Qt.LeftButton, pos=pos1)
+ self.mouseClick(plot, qt.Qt.LeftButton, pos=pos1)
def _drawPolygon(self):
"""Draw a star polygon in the plot"""
@@ -110,7 +110,9 @@ class TestScatterMaskToolsWidget(PlotWidgetTestCase, ParametricTestCase):
self.mouseMove(plot, pos=[0, 0])
for pos in star:
self.mouseMove(plot, pos=pos)
+ self.qapp.processEvents()
self.mouseClick(plot, qt.Qt.LeftButton, pos=pos)
+ self.qapp.processEvents()
def _drawPencil(self):
"""Draw a star polygon in the plot"""
diff --git a/silx/gui/plot/test/testScatterView.py b/silx/gui/plot/test/testScatterView.py
index 40fdac6..583e3ed 100644
--- a/silx/gui/plot/test/testScatterView.py
+++ b/silx/gui/plot/test/testScatterView.py
@@ -103,6 +103,25 @@ class TestScatterView(PlotWidgetTestCase):
self.assertIsNone(data[3]) # xerror
self.assertIsNone(data[4]) # yerror
+ def testAlpha(self):
+ """Test alpha transparency in setData"""
+ _pts = 100
+ _levels = 100
+ _fwhm = 50
+ x = numpy.random.rand(_pts)*_levels
+ y = numpy.random.rand(_pts)*_levels
+ value = numpy.random.rand(_pts)*_levels
+ x0 = x[int(_pts/2)]
+ y0 = x[int(_pts/2)]
+ #2D Gaussian kernel
+ alpha = numpy.exp(-4*numpy.log(2) * ((x-x0)**2 + (y-y0)**2) / _fwhm**2)
+
+ self.plot.setData(x, y, value, alpha=alpha)
+ self.qapp.processEvents()
+
+ alphaData = self.plot.getScatterItem().getAlphaData()
+ self.assertTrue(numpy.all(numpy.equal(alpha, alphaData)))
+
def suite():
test_suite = unittest.TestSuite()
diff --git a/silx/gui/plot/test/testStackView.py b/silx/gui/plot/test/testStackView.py
index 3dcea36..a5f649c 100644
--- a/silx/gui/plot/test/testStackView.py
+++ b/silx/gui/plot/test/testStackView.py
@@ -32,7 +32,7 @@ __date__ = "20/03/2017"
import unittest
import numpy
-from silx.gui.test.utils import TestCaseQt, SignalListener
+from silx.gui.utils.testutils import TestCaseQt, SignalListener
from silx.gui import qt
from silx.gui.plot import StackView
@@ -123,8 +123,9 @@ class TestStackView(TestCaseQt):
"Plane selection combobox not updating perspective")
self.stackview.setStack(numpy.arange(6).reshape((1, 2, 3)))
- self.assertEqual(self.stackview._perspective, 0,
- "Default perspective not restored in setStack.")
+ self.assertEqual(self.stackview._perspective, 1,
+ "Perspective not preserved when calling setStack "
+ "without specifying the perspective parameter.")
self.stackview.setStack(numpy.arange(24).reshape((2, 3, 4)), perspective=2)
self.assertEqual(self.stackview._perspective, 2,
diff --git a/silx/gui/plot/test/testStats.py b/silx/gui/plot/test/testStats.py
index 123eb89..faedcff 100644
--- a/silx/gui/plot/test/testStats.py
+++ b/silx/gui/plot/test/testStats.py
@@ -33,7 +33,7 @@ from silx.gui import qt
from silx.gui.plot.stats import stats
from silx.gui.plot import StatsWidget
from silx.gui.plot.stats import statshandler
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import Plot1D, Plot2D
import unittest
import logging
@@ -361,6 +361,7 @@ class TestStatsWidgetWithCurves(TestCaseQt):
def setUp(self):
TestCaseQt.setUp(self)
self.plot = Plot1D()
+ self.plot.show()
x = range(20)
y = range(20)
self.plot.addCurve(x, y, legend='curve0')
diff --git a/silx/gui/plot/test/testUtilsAxis.py b/silx/gui/plot/test/testUtilsAxis.py
index 3f19dcd..016fafe 100644
--- a/silx/gui/plot/test/testUtilsAxis.py
+++ b/silx/gui/plot/test/testUtilsAxis.py
@@ -31,7 +31,7 @@ __date__ = "14/02/2018"
import unittest
from silx.gui.plot import PlotWidget
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot.utils.axis import SyncAxes
diff --git a/silx/gui/plot/test/utils.py b/silx/gui/plot/test/utils.py
index efba39c..ed1917a 100644
--- a/silx/gui/plot/test/utils.py
+++ b/silx/gui/plot/test/utils.py
@@ -31,7 +31,7 @@ __date__ = "26/01/2018"
import logging
-from silx.gui.test.utils import TestCaseQt
+from silx.gui.utils.testutils import TestCaseQt
from silx.gui import qt
from silx.gui.plot import PlotWidget