diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index e33c8b0c574..e3292f575cd 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -171,6 +171,12 @@ def test_variable_name_change(self): data = self.get_output(self.widget.Outputs.data) self.assertIn("a", data.domain) + idx = self.widget.domain_editor.model().createIndex(3, 0) + self.widget.domain_editor.model().setData(idx, "d", Qt.EditRole) + self.widget.apply_button.click() + data = self.get_output(self.widget.Outputs.data) + self.assertIn("d", data.domain) + # rename and change to text idx = self.widget.domain_editor.model().createIndex(4, 0) self.widget.domain_editor.model().setData(idx, "b", Qt.EditRole) @@ -266,6 +272,13 @@ def test_check_column_noname(self): self.widget.domain_editor.model().setData(idx, "", Qt.EditRole) self.assertEqual(self.widget.domain_editor.model().data(idx, Qt.DisplayRole), temp) + def test_invalid_role_mode(self): + self.open_dataset("iris") + model = self.widget.domain_editor.model() + idx = model.createIndex(1, 0) + self.assertFalse(model.setData(idx, Qt.StatusTipRole, "")) + self.assertIsNone(model.data(idx, Qt.StatusTipRole)) + def test_context_match_includes_variable_values(self): file1 = """\ var diff --git a/Orange/widgets/utils/domaineditor.py b/Orange/widgets/utils/domaineditor.py index 22940470074..1b7a47cb7dd 100644 --- a/Orange/widgets/utils/domaineditor.py +++ b/Orange/widgets/utils/domaineditor.py @@ -62,13 +62,14 @@ def set_variables(self, variables): def rowCount(self, parent): return 0 if parent.isValid() else len(self.variables) - def columnCount(self, parent): + @staticmethod + def columnCount(parent): return 0 if parent.isValid() else Column.not_valid def data(self, index, role): row, col = index.row(), index.column() val = self.variables[row][col] - if role == Qt.DisplayRole or role == Qt.EditRole: + if role in (Qt.DisplayRole, Qt.EditRole): if col == Column.tpe: return self.type2name[val] if col == Column.place: @@ -91,6 +92,7 @@ def data(self, index, role): font = QFont() font.setBold(True) return font + return None def setData(self, index, value, role=Qt.EditRole): row, col = index.row(), index.column() @@ -111,6 +113,7 @@ def setData(self, index, value, role=Qt.EditRole): # Settings may change background colors self.dataChanged.emit(index.sibling(row, 0), index.sibling(row, 3)) return True + return False def headerData(self, i, orientation, role=Qt.DisplayRole): if orientation == Qt.Horizontal and role == Qt.DisplayRole and i < 4: @@ -131,7 +134,7 @@ def __init__(self, view, items): self.view = view self.items = items - def createEditor(self, parent, option, index): + def createEditor(self, parent, _option, index): # This ugly hack closes the combo when the user selects an item class Combo(QComboBox): def __init__(self, *args): @@ -146,6 +149,8 @@ def showPopup(self, *args): super().showPopup(*args) self.popup_shown = True + # Here, we need `self` from the closure + # pylint: disable=no-self-argument,attribute-defined-outside-init def hidePopup(me): if me.popup_shown: self.view.model().setData( @@ -356,7 +361,7 @@ def numbers_are_round(var, col_data): # merge columns for X, Y and metas feats = cols[Place.feature] - X = self._merge(feats) if len(feats) else np.empty((len(data), 0)) + X = self._merge(feats) if feats else np.empty((len(data), 0)) Y = self._merge(cols[Place.class_var], force_dense=True) m = self._merge(cols[Place.meta], force_dense=True) domain = Domain(*places) @@ -365,7 +370,8 @@ def numbers_are_round(var, col_data): else: return domain, [X, Y, m] - def _get_column(self, data, source_var, source_place): + @staticmethod + def _get_column(data, source_var, source_place): """ Extract column from data and preserve sparsity. """ if source_place == Place.meta: col_data = data[:, source_var].metas diff --git a/Orange/widgets/utils/tests/test_domaineditor.py b/Orange/widgets/utils/tests/test_domaineditor.py index 84803ef1c94..c5e445cce2e 100644 --- a/Orange/widgets/utils/tests/test_domaineditor.py +++ b/Orange/widgets/utils/tests/test_domaineditor.py @@ -1,5 +1,4 @@ import unittest -from unittest.mock import Mock import numpy as np @@ -8,7 +7,7 @@ from Orange.data import DiscreteVariable, ContinuousVariable, StringVariable, \ TimeVariable, Domain, Table from Orange.widgets.tests.base import GuiTest -from Orange.widgets.utils.domaineditor import DomainEditor, Column, Place +from Orange.widgets.utils.domaineditor import DomainEditor, Column class MockWidget(OWBaseWidget):