Skip to content

Commit

Permalink
Merge pull request #3402 from AndrejaKovacic/owfile_fix
Browse files Browse the repository at this point in the history
[Fix] Missing url error
  • Loading branch information
janezd authored Nov 16, 2018
2 parents 231937d + 4bf9f26 commit dda3505
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ class Error(widget.OWWidget.Error):
sheet_error = widget.Msg("Error listing available sheets.")
unknown = widget.Msg("Read error:\n{}")

class NoFileSelected:
pass

def __init__(self):
super().__init__()
RecentPathsWComboMixin.__init__(self)
Expand Down Expand Up @@ -306,6 +309,10 @@ def _try_load(self):
assert self.reader is not None
except Exception:
return self.Error.missing_reader

if self.reader is self.NoFileSelected:
self.Outputs.data.send(None)
return

try:
self._update_sheet_combo()
Expand Down Expand Up @@ -338,6 +345,8 @@ def _get_reader(self):
"""
if self.source == self.LOCAL_FILE:
path = self.last_path()
if path is None:
return self.NoFileSelected
if self.recent_paths and self.recent_paths[0].file_format:
qname = self.recent_paths[0].file_format
reader_class = class_from_qualified_name(qname)
Expand All @@ -351,6 +360,8 @@ def _get_reader(self):
url = self.url_combo.currentText().strip()
if url:
return UrlReader(url)
else:
return self.NoFileSelected

def _update_sheet_combo(self):
if len(self.reader.sheets) < 2:
Expand Down
13 changes: 13 additions & 0 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ def test_file_not_found(self):
self.open_dataset("iris")
self.assertFalse(self.widget.Error.file_not_found.is_shown())

def test_nothing_selected(self):
widget = self.widget = \
self.create_widget(OWFile, stored_settings={"recent_paths": []})

widget.Outputs.data.send = Mock()
widget._try_load()
widget.Outputs.data.send.assert_called_with(None)

widget.Outputs.data.send.reset_mock()
widget.source = widget.URL
widget._try_load()
widget.Outputs.data.send.assert_called_with(None)

def test_check_column_noname(self):
"""
Column name cannot be changed to an empty string or a string with whitespaces.
Expand Down

0 comments on commit dda3505

Please sign in to comment.