-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filedialogs.get_file_name_save now uses filedialogs.get_filename_format
- Loading branch information
1 parent
373e7e8
commit 0551325
Showing
3 changed files
with
112 additions
and
38 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
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,71 @@ | ||
# Test methods with long descriptive names can omit docstrings | ||
# pylint: disable=missing-docstring | ||
from unittest.mock import patch | ||
import os | ||
|
||
from Orange.data import Table | ||
from Orange.data.io import TabReader, PickleReader | ||
from Orange.tests import named_file | ||
from Orange.widgets.tests.base import WidgetTest | ||
from Orange.widgets.utils.filedialogs import format_filter, fix_extension | ||
from Orange.widgets.data.owsave import OWSave | ||
|
||
|
||
class TestOWSave(WidgetTest): | ||
|
||
def setUp(self): | ||
self.widget = self.create_widget(OWSave) # type: OWSave | ||
|
||
def test_ordinary_save(self): | ||
self.send_signal(self.widget.Inputs.data, Table("iris")) | ||
|
||
for ext, writer in [('.tab', TabReader), ('.pickle', PickleReader)]: | ||
with named_file("", suffix=ext) as filename: | ||
def choose_file(a, b, c, d, e, fn=filename, w=writer): | ||
return fn, format_filter(w) | ||
with patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", choose_file): | ||
self.widget.save_file_as() | ||
self.assertEqual(len(Table(filename)), 150) | ||
|
||
def test_fix_extension(self): | ||
self.send_signal(self.widget.Inputs.data, Table("iris")) | ||
|
||
# need to add vars | ||
def mock_choice(ret): | ||
f = lambda a, b, c, d: ret | ||
for a, v in vars(fix_extension).items(): | ||
setattr(f, a, v) | ||
return f | ||
|
||
fix_change_ext = mock_choice(fix_extension.CHANGE_EXT) | ||
fix_change_format = mock_choice(fix_extension.CHANGE_FORMAT) | ||
fix_cancel = mock_choice(fix_extension.CANCEL) | ||
|
||
def pickle_file_tab_filter(a, b, c, d, e): | ||
return filename.replace("tab", "pickle"), format_filter(TabReader) | ||
|
||
def tab_file_pickle_filter(a, b, c, d, e): | ||
return filename, format_filter(PickleReader) | ||
|
||
counter = [0] | ||
|
||
def tab_file_change_filters(a, b, c, d, e): | ||
counter[0] += 1 | ||
if counter[0] == 1: | ||
return filename, format_filter(PickleReader) | ||
else: | ||
return filename, format_filter(TabReader) | ||
|
||
with named_file("", suffix=".tab") as filename: | ||
|
||
for file_choice, fix in [(pickle_file_tab_filter, fix_change_ext), | ||
(tab_file_pickle_filter, fix_change_format), | ||
(tab_file_change_filters, fix_cancel)]: | ||
|
||
os.remove(filename) | ||
|
||
with patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", file_choice),\ | ||
patch("Orange.widgets.utils.filedialogs.fix_extension", fix): | ||
self.widget.save_file_as() | ||
|
||
self.assertEqual(len(Table(filename)), 150) |
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