Skip to content

Commit

Permalink
Merge pull request #5198 from ales-erjavec/datasets-no-self-capture
Browse files Browse the repository at this point in the history
[FIX] owdataset: Do not capture self in closure
  • Loading branch information
PrimozGodec authored Jan 22, 2021
2 parents 3d6b923 + db6e84f commit 3015722
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions Orange/widgets/data/owdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def ensure_local(index_url, file_path, local_cache_path,
return localfiles.localpath_download(*file_path, callback=progress_advance)


def list_remote(server: str) -> Dict[Tuple[str, ...], dict]:
client = ServerFiles(server)
return client.allinfo()


def list_local(path: str) -> Dict[Tuple[str, ...], dict]:
return LocalFiles(path).allinfo()


def format_exception(error):
# type: (BaseException) -> str
return "\n".join(traceback.format_exception_only(type(error), error))
Expand Down Expand Up @@ -256,7 +265,7 @@ def __init__(self):
self.setStatusMessage("Initializing")

self._executor = ThreadPoolExecutor(max_workers=1)
f = self._executor.submit(self.list_remote)
f = self._executor.submit(list_remote, self.INDEX_URL)
w = FutureWatcher(f, parent=self)
w.done.connect(self.__set_index)

Expand Down Expand Up @@ -349,7 +358,7 @@ def __set_index(self, f):
assert f.done()
self.setBlocking(False)
self.setStatusMessage("")
self.allinfo_local = self.list_local()
self.allinfo_local = list_local(self.local_cache_path)

try:
self.allinfo_remote = f.result()
Expand Down Expand Up @@ -385,7 +394,7 @@ def __set_index(self, f):

def __update_cached_state(self):
model = self.view.model().sourceModel()
localinfo = self.list_local()
localinfo = list_local(self.local_cache_path)
assert isinstance(model, QStandardItemModel)
allinfo = []
for i in range(model.rowCount()):
Expand Down Expand Up @@ -552,15 +561,6 @@ def load_and_output(self, path):
def load_data(path):
return Orange.data.Table(path)

def list_remote(self):
# type: () -> Dict[Tuple[str, ...], dict]
client = ServerFiles(server=self.INDEX_URL)
return client.allinfo()

def list_local(self):
# type: () -> Dict[Tuple[str, ...], dict]
return LocalFiles(self.local_cache_path).allinfo()


class FutureWatcher(QObject):
done = Signal(object)
Expand Down
24 changes: 12 additions & 12 deletions Orange/widgets/data/tests/test_owdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@


class TestOWDataSets(WidgetTest):
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(side_effect=requests.exceptions.ConnectionError))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={}))
@patch("Orange.widgets.data.owdatasets.log", Mock())
def test_no_internet_connection(self):
w = self.create_widget(OWDataSets) # type: OWDataSets
self.wait_until_stop_blocking(w)
self.assertTrue(w.Error.no_remote_datasets.is_shown())

@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(side_effect=requests.exceptions.ConnectionError))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={('core', 'foo.tab'): {}}))
@patch("Orange.widgets.data.owdatasets.log", Mock())
def test_only_local(self):
Expand All @@ -32,9 +32,9 @@ def test_only_local(self):
self.assertTrue(w.Warning.only_local_datasets.is_shown())
self.assertEqual(w.view.model().rowCount(), 1)

@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(side_effect=requests.exceptions.ConnectionError))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={('core', 'foo.tab'): {},
('core', 'bar.tab'): {}}))
@patch("Orange.widgets.data.owdatasets.log", Mock())
Expand All @@ -49,9 +49,9 @@ def test_filtering(self):
w.filterLineEdit.setText("")
self.assertEqual(w.view.model().rowCount(), 2)

@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(return_value={('core', 'iris.tab'): {}}))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={}))
@patch("Orange.widgets.data.owdatasets.ensure_local",
Mock(return_value="iris.tab"))
Expand All @@ -65,9 +65,9 @@ def test_download_iris(self):
iris = self.get_output(w.Outputs.data, w)
self.assertEqual(len(iris), 150)

@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(side_effect=requests.exceptions.ConnectionError))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={('dir1', 'dir2', 'foo.tab'): {},
('bar.tab',): {}}))
@patch("Orange.widgets.data.owdatasets.log", Mock())
Expand All @@ -76,9 +76,9 @@ def test_dir_depth(self):
self.wait_until_stop_blocking(w)
self.assertEqual(w.view.model().rowCount(), 2)

@patch("Orange.widgets.data.owdatasets.OWDataSets.list_remote",
@patch("Orange.widgets.data.owdatasets.list_remote",
Mock(return_value={('core', 'iris.tab'): {}}))
@patch("Orange.widgets.data.owdatasets.OWDataSets.list_local",
@patch("Orange.widgets.data.owdatasets.list_local",
Mock(return_value={}))
@patch("Orange.widgets.data.owdatasets.ensure_local",
Mock(return_value="iris.tab"))
Expand Down

0 comments on commit 3015722

Please sign in to comment.