From 0fd6a285e8a643b1a6f72069dac3b73b971d654b Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Sat, 8 Dec 2018 14:22:56 +0100 Subject: [PATCH] Linear Projection: Setup model_selected before calculating __invalidated --- .../widgets/visualize/owlinearprojection.py | 18 ++++++--------- .../tests/test_owlinearprojection.py | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Orange/widgets/visualize/owlinearprojection.py b/Orange/widgets/visualize/owlinearprojection.py index b5d3a9f9913..244d5d789dc 100644 --- a/Orange/widgets/visualize/owlinearprojection.py +++ b/Orange/widgets/visualize/owlinearprojection.py @@ -358,6 +358,13 @@ def colors_changed(self): def set_data(self, data): super().set_data(data) + self._check_options() + self._init_vizrank() + self.init_projection() + + def use_context(self): + self.model_selected.clear() + self.model_other.clear() if self.data is not None and len(self.selected_vars): d, selected = self.data.domain, [v[0] for v in self.selected_vars] self.model_selected[:] = [d[attr] for attr in selected] @@ -368,10 +375,6 @@ def set_data(self, data): self.model_selected[:] = self.continuous_variables[:3] self.model_other[:] = self.continuous_variables[3:] - self._check_options() - self._init_vizrank() - self.init_projection() - def _check_options(self): buttons = self.radio_placement.buttons for btn in buttons: @@ -463,13 +466,6 @@ def projection_name(): ("Jittering", self.graph.jitter_size != 0 and "{} %".format(self.graph.jitter_size)))) - def clear(self): - if self.model_selected: - self.model_selected.clear() - if self.model_other: - self.model_other.clear() - super().clear() - @classmethod def migrate_settings(cls, settings_, version): if version < 2: diff --git a/Orange/widgets/visualize/tests/test_owlinearprojection.py b/Orange/widgets/visualize/tests/test_owlinearprojection.py index d314302220e..7a75b2c1510 100644 --- a/Orange/widgets/visualize/tests/test_owlinearprojection.py +++ b/Orange/widgets/visualize/tests/test_owlinearprojection.py @@ -1,5 +1,6 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring +from unittest.mock import Mock import numpy as np from AnyQt.QtCore import QItemSelectionModel @@ -159,6 +160,28 @@ def test_set_radius_no_data(self): self.send_signal(w.Inputs.data, None) w.controls.graph.hide_radius.setSliderPosition(3) + def test_invalidated_model_selected(self): + self.widget.setup_plot = Mock() + self.send_signal(self.widget.Inputs.data, self.data) + self.widget.setup_plot.assert_called_once() + + self.widget.setup_plot.reset_mock() + self.widget.model_selected[:] = self.data.domain[2:] + self.widget.variables_selection.removed.emit() + self.widget.setup_plot.assert_called_once() + + self.widget.setup_plot.reset_mock() + self.send_signal(self.widget.Inputs.data, self.data[:, 2:]) + self.widget.setup_plot.assert_not_called() + + self.widget.model_selected[:] = self.data.domain[3:] + self.widget.variables_selection.removed.emit() + self.widget.setup_plot.assert_called_once() + + self.widget.setup_plot.reset_mock() + self.send_signal(self.widget.Inputs.data, self.data) + self.widget.setup_plot.assert_called_once() + class LinProjVizRankTests(WidgetTest): """