diff options
Diffstat (limited to 'silx/gui/widgets/test')
-rw-r--r-- | silx/gui/widgets/test/__init__.py | 59 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_boxlayoutdockwidget.py | 83 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_elidedlabel.py | 111 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_flowlayout.py | 77 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_framebrowser.py | 73 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_hierarchicaltableview.py | 117 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_legendiconwidget.py | 74 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_periodictable.py | 163 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_printpreview.py | 74 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_rangeslider.py | 114 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_tablewidget.py | 61 | ||||
-rw-r--r-- | silx/gui/widgets/test/test_threadpoolpushbutton.py | 135 |
12 files changed, 0 insertions, 1141 deletions
diff --git a/silx/gui/widgets/test/__init__.py b/silx/gui/widgets/test/__init__.py deleted file mode 100644 index 9aaec76..0000000 --- a/silx/gui/widgets/test/__init__.py +++ /dev/null @@ -1,59 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2020 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. -# -# ###########################################################################*/ -import unittest - -from . import test_periodictable -from . import test_tablewidget -from . import test_threadpoolpushbutton -from . import test_hierarchicaltableview -from . import test_printpreview -from . import test_framebrowser -from . import test_boxlayoutdockwidget -from . import test_rangeslider -from . import test_flowlayout -from . import test_elidedlabel -from . import test_legendiconwidget - -__authors__ = ["V. Valls", "P. Knobel"] -__license__ = "MIT" -__date__ = "19/07/2017" - - -def suite(): - test_suite = unittest.TestSuite() - test_suite.addTests( - [test_threadpoolpushbutton.suite(), - test_tablewidget.suite(), - test_periodictable.suite(), - test_printpreview.suite(), - test_hierarchicaltableview.suite(), - test_framebrowser.suite(), - test_boxlayoutdockwidget.suite(), - test_rangeslider.suite(), - test_flowlayout.suite(), - test_elidedlabel.suite(), - test_legendiconwidget.suite(), - ]) - return test_suite diff --git a/silx/gui/widgets/test/test_boxlayoutdockwidget.py b/silx/gui/widgets/test/test_boxlayoutdockwidget.py deleted file mode 100644 index 9a93ca1..0000000 --- a/silx/gui/widgets/test/test_boxlayoutdockwidget.py +++ /dev/null @@ -1,83 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2018 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 BoxLayoutDockWidget""" - -__authors__ = ["T. Vincent"] -__license__ = "MIT" -__date__ = "06/03/2018" - -import unittest - -from silx.gui.widgets.BoxLayoutDockWidget import BoxLayoutDockWidget -from silx.gui import qt -from silx.gui.utils.testutils import TestCaseQt - - -class TestBoxLayoutDockWidget(TestCaseQt): - """Tests for BoxLayoutDockWidget""" - - def setUp(self): - """Create and show a main window""" - self.window = qt.QMainWindow() - self.qWaitForWindowExposed(self.window) - - def tearDown(self): - """Delete main window""" - self.window.setAttribute(qt.Qt.WA_DeleteOnClose) - self.window.close() - del self.window - self.qapp.processEvents() - - def test(self): - """Test update of layout direction according to dock area""" - # Create a widget with a QBoxLayout - layout = qt.QBoxLayout(qt.QBoxLayout.LeftToRight) - layout.addWidget(qt.QLabel('First')) - layout.addWidget(qt.QLabel('Second')) - widget = qt.QWidget() - widget.setLayout(layout) - - # Add it to a BoxLayoutDockWidget - dock = BoxLayoutDockWidget() - dock.setWidget(widget) - - self.window.addDockWidget(qt.Qt.BottomDockWidgetArea, dock) - self.qapp.processEvents() - self.assertEqual(layout.direction(), qt.QBoxLayout.LeftToRight) - - self.window.addDockWidget(qt.Qt.LeftDockWidgetArea, dock) - self.qapp.processEvents() - self.assertEqual(layout.direction(), qt.QBoxLayout.TopToBottom) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestBoxLayoutDockWidget)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_elidedlabel.py b/silx/gui/widgets/test/test_elidedlabel.py deleted file mode 100644 index 2856733..0000000 --- a/silx/gui/widgets/test/test_elidedlabel.py +++ /dev/null @@ -1,111 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2020 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 ElidedLabel""" - -__license__ = "MIT" -__date__ = "08/06/2020" - -import unittest - -from silx.gui import qt -from silx.gui.widgets.ElidedLabel import ElidedLabel -from silx.gui.utils import testutils - - -class TestElidedLabel(testutils.TestCaseQt): - - def setUp(self): - self.label = ElidedLabel() - self.label.show() - self.qWaitForWindowExposed(self.label) - - def tearDown(self): - self.label.setAttribute(qt.Qt.WA_DeleteOnClose) - self.label.close() - del self.label - self.qapp.processEvents() - - def testElidedValue(self): - """Test elided text""" - raw = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" - self.label.setText(raw) - self.label.setFixedWidth(30) - displayedText = qt.QLabel.text(self.label) - self.assertNotEqual(raw, displayedText) - self.assertIn("…", displayedText) - self.assertIn("m", displayedText) - - def testNotElidedValue(self): - """Test elided text""" - raw = "mmmmmmm" - self.label.setText(raw) - self.label.setFixedWidth(200) - displayedText = qt.QLabel.text(self.label) - self.assertNotIn("…", displayedText) - self.assertEqual(raw, displayedText) - - def testUpdateFromElidedToNotElided(self): - """Test tooltip when not elided""" - raw1 = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" - raw2 = "nn" - self.label.setText(raw1) - self.label.setFixedWidth(30) - self.label.setText(raw2) - displayedTooltip = qt.QLabel.toolTip(self.label) - self.assertNotIn(raw1, displayedTooltip) - self.assertNotIn(raw2, displayedTooltip) - - def testUpdateFromNotElidedToElided(self): - """Test tooltip when elided""" - raw1 = "nn" - raw2 = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" - self.label.setText(raw1) - self.label.setFixedWidth(30) - self.label.setText(raw2) - displayedTooltip = qt.QLabel.toolTip(self.label) - self.assertNotIn(raw1, displayedTooltip) - self.assertIn(raw2, displayedTooltip) - - def testUpdateFromElidedToElided(self): - """Test tooltip when elided""" - raw1 = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" - raw2 = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" - self.label.setText(raw1) - self.label.setFixedWidth(30) - self.label.setText(raw2) - displayedTooltip = qt.QLabel.toolTip(self.label) - self.assertNotIn(raw1, displayedTooltip) - self.assertIn(raw2, displayedTooltip) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestElidedLabel)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_flowlayout.py b/silx/gui/widgets/test/test_flowlayout.py deleted file mode 100644 index 1497945..0000000 --- a/silx/gui/widgets/test/test_flowlayout.py +++ /dev/null @@ -1,77 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2018 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 FlowLayout""" - -__authors__ = ["T. Vincent"] -__license__ = "MIT" -__date__ = "02/08/2018" - -import unittest - -from silx.gui.widgets.FlowLayout import FlowLayout -from silx.gui import qt -from silx.gui.utils.testutils import TestCaseQt - - -class TestFlowLayout(TestCaseQt): - """Tests for FlowLayout""" - - def setUp(self): - """Create and show a widget""" - self.widget = qt.QWidget() - self.widget.show() - self.qWaitForWindowExposed(self.widget) - - def tearDown(self): - """Delete widget""" - self.widget.setAttribute(qt.Qt.WA_DeleteOnClose) - self.widget.close() - del self.widget - self.qapp.processEvents() - - def test(self): - """Basic tests""" - layout = FlowLayout() - self.widget.setLayout(layout) - - layout.addWidget(qt.QLabel('first')) - layout.addWidget(qt.QLabel('second')) - self.assertEqual(layout.count(), 2) - - layout.setHorizontalSpacing(10) - self.assertEqual(layout.horizontalSpacing(), 10) - layout.setVerticalSpacing(5) - self.assertEqual(layout.verticalSpacing(), 5) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestFlowLayout)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_framebrowser.py b/silx/gui/widgets/test/test_framebrowser.py deleted file mode 100644 index 2dfd302..0000000 --- a/silx/gui/widgets/test/test_framebrowser.py +++ /dev/null @@ -1,73 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2018 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. -# -# ###########################################################################*/ -__authors__ = ["T. Vincent"] -__license__ = "MIT" -__date__ = "23/03/2018" - - -import unittest - -from silx.gui.utils.testutils import TestCaseQt -from silx.gui.widgets.FrameBrowser import FrameBrowser - - -class TestFrameBrowser(TestCaseQt): - """Test for FrameBrowser""" - - def test(self): - """Test FrameBrowser""" - widget = FrameBrowser() - widget.show() - self.qWaitForWindowExposed(widget) - - nFrames = 20 - widget.setNFrames(nFrames) - self.assertEqual(widget.getRange(), (0, nFrames - 1)) - self.assertEqual(widget.getValue(), 0) - - range_ = -100, 100 - widget.setRange(*range_) - self.assertEqual(widget.getRange(), range_) - self.assertEqual(widget.getValue(), range_[0]) - - widget.setValue(0) - self.assertEqual(widget.getValue(), 0) - - widget.setValue(range_[1] + 100) - self.assertEqual(widget.getValue(), range_[1]) - - widget.setValue(range_[0] - 100) - self.assertEqual(widget.getValue(), range_[0]) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestFrameBrowser)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_hierarchicaltableview.py b/silx/gui/widgets/test/test_hierarchicaltableview.py deleted file mode 100644 index 9fad54d..0000000 --- a/silx/gui/widgets/test/test_hierarchicaltableview.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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. -# -# ###########################################################################*/ -__authors__ = ["V. Valls"] -__license__ = "MIT" -__date__ = "07/04/2017" - -import unittest - -from .. import HierarchicalTableView -from silx.gui.utils.testutils import TestCaseQt -from silx.gui import qt - - -class TableModel(HierarchicalTableView.HierarchicalTableModel): - - def __init__(self, parent): - HierarchicalTableView.HierarchicalTableModel.__init__(self, parent) - self.__content = {} - - def rowCount(self, parent=qt.QModelIndex()): - return 3 - - def columnCount(self, parent=qt.QModelIndex()): - return 3 - - def setData1(self): - if qt.qVersion() > "4.6": - self.beginResetModel() - else: - self.reset() - - content = {} - content[0, 0] = ("title", True, (1, 3)) - content[0, 1] = ("a", True, (2, 1)) - content[1, 1] = ("b", False, (1, 2)) - content[1, 2] = ("c", False, (1, 1)) - content[2, 2] = ("d", False, (1, 1)) - self.__content = content - if qt.qVersion() > "4.6": - self.endResetModel() - - def data(self, index, role=qt.Qt.DisplayRole): - if not index.isValid(): - return None - cell = self.__content.get((index.column(), index.row()), None) - if cell is None: - return None - - if role == self.SpanRole: - return cell[2] - elif role == self.IsHeaderRole: - return cell[1] - elif role == qt.Qt.DisplayRole: - return cell[0] - return None - - -class TestHierarchicalTableView(TestCaseQt): - """Test for HierarchicalTableView""" - - def testEmpty(self): - widget = HierarchicalTableView.HierarchicalTableView() - widget.show() - self.qWaitForWindowExposed(widget) - - def testModel(self): - widget = HierarchicalTableView.HierarchicalTableView() - model = TableModel(widget) - # set the data before using the model into the widget - model.setData1() - widget.setModel(model) - span = widget.rowSpan(0, 0), widget.columnSpan(0, 0) - self.assertEqual(span, (1, 3)) - widget.show() - self.qWaitForWindowExposed(widget) - - def testModelUpdate(self): - widget = HierarchicalTableView.HierarchicalTableView() - model = TableModel(widget) - widget.setModel(model) - # set the data after using the model into the widget - model.setData1() - span = widget.rowSpan(0, 0), widget.columnSpan(0, 0) - self.assertEqual(span, (1, 3)) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestHierarchicalTableView)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_legendiconwidget.py b/silx/gui/widgets/test/test_legendiconwidget.py deleted file mode 100644 index f845f75..0000000 --- a/silx/gui/widgets/test/test_legendiconwidget.py +++ /dev/null @@ -1,74 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2020 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 LegendIconWidget""" - -__authors__ = ["V. Valls"] -__license__ = "MIT" -__date__ = "23/10/2020" - -import unittest - -from silx.gui import qt -from silx.gui.widgets.LegendIconWidget import LegendIconWidget -from silx.gui.utils.testutils import TestCaseQt -from silx.utils.testutils import ParametricTestCase - - -class TestLegendIconWidget(TestCaseQt, ParametricTestCase): - """Tests for TestRangeSlider""" - - def setUp(self): - self.widget = LegendIconWidget() - self.widget.show() - self.qWaitForWindowExposed(self.widget) - - def tearDown(self): - self.widget.setAttribute(qt.Qt.WA_DeleteOnClose) - self.widget.close() - del self.widget - self.qapp.processEvents() - - def testCreate(self): - self.qapp.processEvents() - - def testColormap(self): - self.widget.setColormap("viridis") - self.qapp.processEvents() - - def testSymbol(self): - self.widget.setSymbol("o") - self.widget.setSymbolColormap("viridis") - self.qapp.processEvents() - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestLegendIconWidget)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_periodictable.py b/silx/gui/widgets/test/test_periodictable.py deleted file mode 100644 index 3e7eb16..0000000 --- a/silx/gui/widgets/test/test_periodictable.py +++ /dev/null @@ -1,163 +0,0 @@ -# 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. -# -# ###########################################################################*/ -__authors__ = ["P. Knobel"] -__license__ = "MIT" -__date__ = "05/12/2016" - -import unittest - -from .. import PeriodicTable -from silx.gui.utils.testutils import TestCaseQt -from silx.gui import qt - - -class TestPeriodicTable(TestCaseQt): - """Basic test for ArrayTableWidget with a numpy array""" - - def testShow(self): - """basic test (instantiation done in setUp)""" - pt = PeriodicTable.PeriodicTable() - pt.show() - self.qWaitForWindowExposed(pt) - - def testSelectable(self): - """basic test (instantiation done in setUp)""" - pt = PeriodicTable.PeriodicTable(selectable=True) - self.assertTrue(pt.selectable) - - def testCustomElements(self): - PTI = PeriodicTable.ColoredPeriodicTableItem - my_items = [ - PTI("Xx", 42, 43, 44, "xaxatorium", 1002.2, - bgcolor="#FF0000"), - PTI("Yy", 25, 22, 44, "yoyotrium", 8.8) - ] - - pt = PeriodicTable.PeriodicTable(elements=my_items) - - pt.setSelection(["He", "Xx"]) - selection = pt.getSelection() - self.assertEqual(len(selection), 1) # "He" not found - self.assertEqual(selection[0].symbol, "Xx") - self.assertEqual(selection[0].Z, 42) - self.assertEqual(selection[0].col, 43) - self.assertAlmostEqual(selection[0].mass, 1002.2) - self.assertEqual(qt.QColor(selection[0].bgcolor), - qt.QColor(qt.Qt.red)) - - self.assertTrue(pt.isElementSelected("Xx")) - self.assertFalse(pt.isElementSelected("Yy")) - self.assertRaises(KeyError, pt.isElementSelected, "Yx") - - def testVeryCustomElements(self): - class MyPTI(PeriodicTable.PeriodicTableItem): - def __init__(self, *args): - PeriodicTable.PeriodicTableItem.__init__(self, *args[:6]) - self.my_feature = args[6] - - my_items = [ - MyPTI("Xx", 42, 43, 44, "xaxatorium", 1002.2, "spam"), - MyPTI("Yy", 25, 22, 44, "yoyotrium", 8.8, "eggs") - ] - - pt = PeriodicTable.PeriodicTable(elements=my_items) - - pt.setSelection(["Xx", "Yy"]) - selection = pt.getSelection() - self.assertEqual(len(selection), 2) - self.assertEqual(selection[1].symbol, "Yy") - self.assertEqual(selection[1].Z, 25) - self.assertEqual(selection[1].col, 22) - self.assertEqual(selection[1].row, 44) - self.assertAlmostEqual(selection[0].mass, 1002.2) - self.assertAlmostEqual(selection[0].my_feature, "spam") - - -class TestPeriodicCombo(TestCaseQt): - """Basic test for ArrayTableWidget with a numpy array""" - def setUp(self): - super(TestPeriodicCombo, self).setUp() - self.pc = PeriodicTable.PeriodicCombo() - - def tearDown(self): - del self.pc - super(TestPeriodicCombo, self).tearDown() - - def testShow(self): - """basic test (instantiation done in setUp)""" - self.pc.show() - self.qWaitForWindowExposed(self.pc) - - def testSelect(self): - self.pc.setSelection("Sb") - selection = self.pc.getSelection() - self.assertIsInstance(selection, - PeriodicTable.PeriodicTableItem) - self.assertEqual(selection.symbol, "Sb") - self.assertEqual(selection.Z, 51) - self.assertEqual(selection.name, "antimony") - - -class TestPeriodicList(TestCaseQt): - """Basic test for ArrayTableWidget with a numpy array""" - def setUp(self): - super(TestPeriodicList, self).setUp() - self.pl = PeriodicTable.PeriodicList() - - def tearDown(self): - del self.pl - super(TestPeriodicList, self).tearDown() - - def testShow(self): - """basic test (instantiation done in setUp)""" - self.pl.show() - self.qWaitForWindowExposed(self.pl) - - def testSelect(self): - self.pl.setSelectedElements(["Li", "He", "Au"]) - sel_elmts = self.pl.getSelection() - - self.assertEqual(len(sel_elmts), 3, - "Wrong number of elements selected") - for e in sel_elmts: - self.assertIsInstance(e, PeriodicTable.PeriodicTableItem) - self.assertIn(e.symbol, ["Li", "He", "Au"]) - self.assertIn(e.Z, [2, 3, 79]) - self.assertIn(e.name, ["lithium", "helium", "gold"]) - - -def suite(): - test_suite = unittest.TestSuite() - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestPeriodicTable)) - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestPeriodicList)) - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestPeriodicCombo)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_printpreview.py b/silx/gui/widgets/test/test_printpreview.py deleted file mode 100644 index 3c29171..0000000 --- a/silx/gui/widgets/test/test_printpreview.py +++ /dev/null @@ -1,74 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 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. -# -# ###########################################################################*/ -"""Test PrintPreview""" - -__authors__ = ["P. Knobel"] -__license__ = "MIT" -__date__ = "19/07/2017" - - -import unittest -from silx.gui.utils.testutils import TestCaseQt -from silx.gui.widgets.PrintPreview import PrintPreviewDialog -from silx.gui import qt - -from silx.resources import resource_filename - - -class TestPrintPreview(TestCaseQt): - def testShow(self): - p = qt.QPrinter() - d = PrintPreviewDialog(printer=p) - d.show() - self.qapp.processEvents() - - def testAddImage(self): - p = qt.QPrinter() - d = PrintPreviewDialog(printer=p) - d.addImage(qt.QImage(resource_filename("gui/icons/clipboard.png"))) - self.qapp.processEvents() - - def testAddSvg(self): - p = qt.QPrinter() - d = PrintPreviewDialog(printer=p) - d.addSvgItem(qt.QSvgRenderer(resource_filename("gui/icons/clipboard.svg"), d.page)) - self.qapp.processEvents() - - def testAddPixmap(self): - p = qt.QPrinter() - d = PrintPreviewDialog(printer=p) - d.addPixmap(qt.QPixmap.fromImage(qt.QImage(resource_filename("gui/icons/clipboard.png")))) - self.qapp.processEvents() - - -def suite(): - test_suite = unittest.TestSuite() - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestPrintPreview)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_rangeslider.py b/silx/gui/widgets/test/test_rangeslider.py deleted file mode 100644 index 2829050..0000000 --- a/silx/gui/widgets/test/test_rangeslider.py +++ /dev/null @@ -1,114 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2018 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 RangeSlider""" - -__authors__ = ["T. Vincent"] -__license__ = "MIT" -__date__ = "01/08/2018" - -import unittest - -from silx.gui import qt, colors -from silx.gui.widgets.RangeSlider import RangeSlider -from silx.gui.utils.testutils import TestCaseQt -from silx.utils.testutils import ParametricTestCase - - -class TestRangeSlider(TestCaseQt, ParametricTestCase): - """Tests for TestRangeSlider""" - - def setUp(self): - self.slider = RangeSlider() - self.slider.show() - self.qWaitForWindowExposed(self.slider) - - def tearDown(self): - self.slider.setAttribute(qt.Qt.WA_DeleteOnClose) - self.slider.close() - del self.slider - self.qapp.processEvents() - - def testRangeValue(self): - """Test slider range and values""" - - # Play with range - self.slider.setRange(1, 2) - self.assertEqual(self.slider.getRange(), (1., 2.)) - self.assertEqual(self.slider.getValues(), (1., 1.)) - - self.slider.setMinimum(-1) - self.assertEqual(self.slider.getRange(), (-1., 2.)) - self.assertEqual(self.slider.getValues(), (1., 1.)) - - self.slider.setMaximum(0) - self.assertEqual(self.slider.getRange(), (-1., 0.)) - self.assertEqual(self.slider.getValues(), (0., 0.)) - - # Play with values - self.slider.setFirstValue(-2.) - self.assertEqual(self.slider.getValues(), (-1., 0.)) - - self.slider.setFirstValue(-0.5) - self.assertEqual(self.slider.getValues(), (-0.5, 0.)) - - self.slider.setSecondValue(2.) - self.assertEqual(self.slider.getValues(), (-0.5, 0.)) - - self.slider.setSecondValue(-0.1) - self.assertEqual(self.slider.getValues(), (-0.5, -0.1)) - - def testStepCount(self): - """Test related to step count""" - self.slider.setPositionCount(11) - self.assertEqual(self.slider.getPositionCount(), 11) - self.slider.setFirstValue(0.32) - self.assertEqual(self.slider.getFirstValue(), 0.3) - self.assertEqual(self.slider.getFirstPosition(), 3) - - self.slider.setPositionCount(3) # Value is adjusted - self.assertEqual(self.slider.getValues(), (0.5, 1.)) - self.assertEqual(self.slider.getPositions(), (1, 2)) - - def testGroove(self): - """Test Groove pixmap""" - profile = list(range(100)) - - for cmap in ('jet', colors.Colormap('viridis')): - with self.subTest(str(cmap)): - self.slider.setGroovePixmapFromProfile(profile, cmap) - pixmap = self.slider.getGroovePixmap() - self.assertIsInstance(pixmap, qt.QPixmap) - self.assertEqual(pixmap.width(), len(profile)) - - -def suite(): - loader = unittest.defaultTestLoader.loadTestsFromTestCase - test_suite = unittest.TestSuite() - test_suite.addTest(loader(TestRangeSlider)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_tablewidget.py b/silx/gui/widgets/test/test_tablewidget.py deleted file mode 100644 index 6822aef..0000000 --- a/silx/gui/widgets/test/test_tablewidget.py +++ /dev/null @@ -1,61 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2016 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. -# -# ###########################################################################*/ -"""Test TableWidget""" - -__authors__ = ["P. Knobel"] -__license__ = "MIT" -__date__ = "05/12/2016" - - -import unittest -from silx.gui.utils.testutils import TestCaseQt -from silx.gui.widgets.TableWidget import TableWidget - - -class TestTableWidget(TestCaseQt): - def setUp(self): - super(TestTableWidget, self).setUp() - self._result = [] - - def testShow(self): - table = TableWidget() - table.setColumnCount(10) - table.setRowCount(7) - table.enableCut() - table.enablePaste() - table.show() - table.hide() - self.qapp.processEvents() - - -def suite(): - test_suite = unittest.TestSuite() - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestTableWidget)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') diff --git a/silx/gui/widgets/test/test_threadpoolpushbutton.py b/silx/gui/widgets/test/test_threadpoolpushbutton.py deleted file mode 100644 index e92eb02..0000000 --- a/silx/gui/widgets/test/test_threadpoolpushbutton.py +++ /dev/null @@ -1,135 +0,0 @@ -# coding: utf-8 -# /*########################################################################## -# -# Copyright (c) 2016 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. -# -# ###########################################################################*/ -"""Test for silx.gui.hdf5 module""" - -__authors__ = ["V. Valls"] -__license__ = "MIT" -__date__ = "17/01/2018" - - -import unittest -import time -from silx.gui import qt -from silx.gui.utils.testutils import TestCaseQt -from silx.gui.utils.testutils import SignalListener -from silx.gui.widgets.ThreadPoolPushButton import ThreadPoolPushButton -from silx.utils.testutils import TestLogging - - -class TestThreadPoolPushButton(TestCaseQt): - - def setUp(self): - super(TestThreadPoolPushButton, self).setUp() - self._result = [] - - def waitForPendingOperations(self, object): - for i in range(50): - if not object.hasPendingOperations(): - break - self.qWait(10) - else: - raise RuntimeError("Still waiting for a pending operation") - - def _trace(self, name, delay=0): - self._result.append(name) - if delay != 0: - time.sleep(delay / 1000.0) - - def _compute(self): - return "result" - - def _computeFail(self): - raise Exception("exception") - - def testExecute(self): - button = ThreadPoolPushButton() - button.setCallable(self._trace, "a", 0) - button.executeCallable() - time.sleep(0.1) - self.assertListEqual(self._result, ["a"]) - self.waitForPendingOperations(button) - - def testMultiExecution(self): - button = ThreadPoolPushButton() - button.setCallable(self._trace, "a", 0) - number = qt.silxGlobalThreadPool().maxThreadCount() - for _ in range(number): - button.executeCallable() - self.waitForPendingOperations(button) - self.assertListEqual(self._result, ["a"] * number) - - def testSaturateThreadPool(self): - button = ThreadPoolPushButton() - button.setCallable(self._trace, "a", 100) - number = qt.silxGlobalThreadPool().maxThreadCount() * 2 - for _ in range(number): - button.executeCallable() - self.waitForPendingOperations(button) - self.assertListEqual(self._result, ["a"] * number) - - def testSuccess(self): - listener = SignalListener() - button = ThreadPoolPushButton() - button.setCallable(self._compute) - button.beforeExecuting.connect(listener.partial(test="be")) - button.started.connect(listener.partial(test="s")) - button.succeeded.connect(listener.partial(test="result")) - button.failed.connect(listener.partial(test="Unexpected exception")) - button.finished.connect(listener.partial(test="f")) - button.executeCallable() - self.qapp.processEvents() - time.sleep(0.1) - self.qapp.processEvents() - result = listener.karguments(argumentName="test") - self.assertListEqual(result, ["be", "s", "result", "f"]) - - def testFail(self): - listener = SignalListener() - button = ThreadPoolPushButton() - button.setCallable(self._computeFail) - button.beforeExecuting.connect(listener.partial(test="be")) - button.started.connect(listener.partial(test="s")) - button.succeeded.connect(listener.partial(test="Unexpected success")) - button.failed.connect(listener.partial(test="exception")) - button.finished.connect(listener.partial(test="f")) - with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1): - button.executeCallable() - self.qapp.processEvents() - time.sleep(0.1) - self.qapp.processEvents() - result = listener.karguments(argumentName="test") - self.assertListEqual(result, ["be", "s", "exception", "f"]) - listener.clear() - - -def suite(): - test_suite = unittest.TestSuite() - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestThreadPoolPushButton)) - return test_suite - - -if __name__ == '__main__': - unittest.main(defaultTest='suite') |