-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corpus - Open file dialogue in previous location
- Loading branch information
1 parent
9e2828c
commit b306874
Showing
2 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import patch, ANY | ||
|
||
from orangecontrib.text.corpus import get_sample_corpora_dir | ||
from orangecontrib.text.widgets.utils import FileWidget, QFileDialog | ||
from orangewidget.tests.base import GuiTest | ||
|
||
|
||
class TestFileWidget(GuiTest): | ||
@patch.object(QFileDialog, "getOpenFileName", return_value=("path", "")) | ||
def test_start_dir(self, mock): | ||
file_widget = FileWidget( | ||
recent_files=[], | ||
icon_size=(16, 16), | ||
dialog_title="Open Orange Document Corpus", | ||
reload_label="Reload", | ||
browse_label="Browse", | ||
allow_empty=False, | ||
minimal_width=250, | ||
) | ||
file_widget.browse() | ||
mock.assert_called_with(ANY, ANY, "~/", ANY) | ||
|
||
file_widget.recent_files = ["book-excerpts.tab"] | ||
file_widget.browse() | ||
mock.assert_called_with(ANY, ANY, get_sample_corpora_dir(), ANY) | ||
|
||
cur_dir = os.path.dirname(__file__) | ||
file_widget.recent_files.insert(0, os.path.join(cur_dir, "file.tab")) | ||
file_widget.browse() | ||
mock.assert_called_with(ANY, ANY, cur_dir, ANY) | ||
|
||
# dir doesn't exit case | ||
file_widget.recent_files.insert(0, "/non/exiting/dir/file.tab") | ||
file_widget.browse() | ||
mock.assert_called_with(ANY, ANY, "~/", ANY) | ||
|
||
# if browse have start_dir argument use this path | ||
file_widget.browse("/sample/path") | ||
mock.assert_called_with(ANY, ANY, "/sample/path", ANY) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters