From 2bbe7ed1fda9597a3ad3a049d6aced27c1e0f30a Mon Sep 17 00:00:00 2001 From: astaric Date: Fri, 24 Mar 2017 10:36:47 +0100 Subject: [PATCH 1/2] PerfectDomainContextHandler: Store copies of values --- Orange/widgets/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Orange/widgets/settings.py b/Orange/widgets/settings.py index 455a6a22f7d..a977b06f0f4 100644 --- a/Orange/widgets/settings.py +++ b/Orange/widgets/settings.py @@ -1150,7 +1150,7 @@ def encode_domain(self, domain): if self.match_values == self.MATCH_VALUES_ALL: def _encode(attrs): - return tuple((v.name, v.values if v.is_discrete else vartype(v)) + return tuple((v.name, list(v.values) if v.is_discrete else vartype(v)) for v in attrs) else: def _encode(attrs): From ee0281660c3765e46cc3a13846969bacecda0bfc Mon Sep 17 00:00:00 2001 From: astaric Date: Fri, 24 Mar 2017 10:38:10 +0100 Subject: [PATCH 2/2] OWFile: Fix invalid settings reuse As domain editor shows variable's values, it should only reuse settings when two discrete variables have the same settings. --- Orange/tests/__init__.py | 5 +++-- Orange/widgets/data/owfile.py | 4 +++- Orange/widgets/data/tests/test_owfile.py | 25 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Orange/tests/__init__.py b/Orange/tests/__init__.py index 8b910d1a03d..0c727965688 100644 --- a/Orange/tests/__init__.py +++ b/Orange/tests/__init__.py @@ -7,8 +7,9 @@ @contextmanager -def named_file(content, encoding=None): - file = tempfile.NamedTemporaryFile("wt", delete=False, encoding=encoding) +def named_file(content, encoding=None, suffix=''): + file = tempfile.NamedTemporaryFile("wt", delete=False, + encoding=encoding, suffix=suffix) file.write(content) name = file.name file.close() diff --git a/Orange/widgets/data/owfile.py b/Orange/widgets/data/owfile.py index 2f58b0704dc..db477b8ab99 100644 --- a/Orange/widgets/data/owfile.py +++ b/Orange/widgets/data/owfile.py @@ -86,7 +86,9 @@ class OWFile(widget.OWWidget, RecentPathsWComboMixin): SIZE_LIMIT = 1e7 LOCAL_FILE, URL = range(2) - settingsHandler = PerfectDomainContextHandler() + settingsHandler = PerfectDomainContextHandler( + match_values=PerfectDomainContextHandler.MATCH_VALUES_ALL + ) # Overload RecentPathsWidgetMixin.recent_paths to set defaults recent_paths = Setting([ diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index f7710b77c42..7c6c27dd691 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -11,6 +11,7 @@ import Orange from Orange.data import FileFormat, dataset_dirs, StringVariable, Table, \ Domain, DiscreteVariable +from Orange.tests import named_file from Orange.widgets.data.owfile import OWFile from Orange.widgets.tests.base import WidgetTest @@ -140,3 +141,27 @@ def test_check_column_noname(self): self.assertEqual(self.widget.domain_editor.model().data(idx, Qt.DisplayRole), temp) self.widget.domain_editor.model().setData(idx, "", Qt.EditRole) self.assertEqual(self.widget.domain_editor.model().data(idx, Qt.DisplayRole), temp) + + def test_context_match_includes_variable_values(self): + file1 = """\ +var +a b + +a +""" + file2 = """\ +var +a b c + +a +""" + editor = self.widget.domain_editor + idx = self.widget.domain_editor.model().createIndex(0, 3) + + with named_file(file1, suffix=".tab") as filename: + self.open_dataset(filename) + self.assertEqual(editor.model().data(idx, Qt.DisplayRole), "a, b") + + with named_file(file2, suffix=".tab") as filename: + self.open_dataset(filename) + self.assertEqual(editor.model().data(idx, Qt.DisplayRole), "a, b, c")