Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fix invalid settings reuse in File widget #2137

Merged
merged 2 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=''):
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")
2 changes: 1 addition & 1 deletion Orange/widgets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down