diff --git a/Orange/widgets/utils/tests/test_colorgradientselection.py b/Orange/widgets/utils/tests/test_colorgradientselection.py index eee7ddf3cb3..2bc086cfc02 100644 --- a/Orange/widgets/utils/tests/test_colorgradientselection.py +++ b/Orange/widgets/utils/tests/test_colorgradientselection.py @@ -1,11 +1,15 @@ +from unittest.mock import Mock + import numpy as np from AnyQt.QtTest import QSignalSpy -from AnyQt.QtCore import Qt, QStringListModel +from AnyQt.QtCore import Qt, QStringListModel, QModelIndex +from Orange.widgets.utils import itemmodels from Orange.widgets.utils.colorgradientselection import ColorGradientSelection from Orange.widgets.tests.base import GuiTest + class TestColorGradientSelection(GuiTest): def test_constructor(self): w = ColorGradientSelection(thresholds=(0.1, 0.9)) @@ -68,3 +72,40 @@ def test_slider_move(self): low, high = changed[-1] self.assertLessEqual(low, high) self.assertEqual(high, 0.0) + + def test_center(self): + w = ColorGradientSelection(center=42) + self.assertEqual(w.center(), 42) + w.setCenter(40) + self.assertEqual(w.center(), 40) + + def test_center_visibility(self): + w = ColorGradientSelection(center=0) + w.center_box.setVisible = Mock() + model = itemmodels.ContinuousPalettesModel() + w.setModel(model) + for row in range(model.rowCount(QModelIndex())): + palette = model.data(model.index(row, 0), Qt.UserRole) + if palette: + if palette.flags & palette.Diverging: + diverging = row + else: + nondiverging = row + + w.setCurrentIndex(diverging) + w.center_box.setVisible.assert_called_with(True) + w.setCurrentIndex(nondiverging) + w.center_box.setVisible.assert_called_with(False) + w.setCurrentIndex(diverging) + w.center_box.setVisible.assert_called_with(True) + + w = ColorGradientSelection() + self.assertIsNone(w.center_box) + + def test_center_changed(self): + w = ColorGradientSelection(center=42) + changed = QSignalSpy(w.centerChanged) + w.center_edit.setText("41") + w.center_edit.editingFinished.emit() + self.assertEqual(w.center(), 41) + self.assertEqual(list(changed), [[41]]) diff --git a/Orange/widgets/visualize/tests/test_owheatmap.py b/Orange/widgets/visualize/tests/test_owheatmap.py index d0dbf978055..9dad11c8a0d 100644 --- a/Orange/widgets/visualize/tests/test_owheatmap.py +++ b/Orange/widgets/visualize/tests/test_owheatmap.py @@ -2,7 +2,7 @@ # pylint: disable=missing-docstring, protected-access import warnings import unittest -from unittest.mock import patch +from unittest.mock import patch, Mock import numpy as np from sklearn.exceptions import ConvergenceWarning @@ -245,6 +245,21 @@ def test_palette_centering(self): colors = image_row_colors(image) np.testing.assert_almost_equal(colors, desired) + def test_centering_threshold_change(self): + data = np.arange(2).reshape(-1, 1) + table = Table.from_numpy(Domain([ContinuousVariable("y")]), data) + self.send_signal(self.widget.Inputs.data, table) + + cmw = self.widget.color_map_widget + palette_index = cmw.findData( + colorpalettes.ContinuousPalettes["diverging_bwr_40_95_c42"], + Qt.UserRole) + cmw.setCurrentIndex(palette_index) + + self.widget.update_color_schema = Mock() + cmw.centerChanged.emit(42) + self.widget.update_color_schema.assert_called() + def test_palette_center(self): widget = self.widget model = widget.color_map_widget.model()