Skip to content

Commit

Permalink
OWFile: Fix invalid settings reuse
Browse files Browse the repository at this point in the history
As domain editor shows variable's values, it should only reuse settings
when two discrete variables have the same settings.
  • Loading branch information
astaric committed Mar 24, 2017
1 parent 2bbe7ed commit f70f9e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Orange/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=None):
file = tempfile.NamedTemporaryFile("wt", delete=False,
encoding=encoding, suffix=suffix)
file.write(content)
name = file.name
file.close()
Expand Down
4 changes: 3 additions & 1 deletion Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
25 changes: 25 additions & 0 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

0 comments on commit f70f9e1

Please sign in to comment.