diff --git a/Orange/widgets/data/owfile.py b/Orange/widgets/data/owfile.py index 4596deaac2e..9dd1ad7a466 100644 --- a/Orange/widgets/data/owfile.py +++ b/Orange/widgets/data/owfile.py @@ -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) @@ -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() @@ -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) @@ -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: diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index 315d5c7cfdd..75aec949f88 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -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.