def test_extension_from_filter(self): self.assertEqual( OWSaveBase._extension_from_filter("Description (*.ext)"), ".ext") self.assertEqual( OWSaveBase._extension_from_filter("Description (*.foo.ba)"), ".foo.ba") self.assertEqual( OWSaveBase._extension_from_filter("Description (.ext)"), ".ext") self.assertEqual( OWSaveBase._extension_from_filter("Description (.foo.bar)"), ".foo.bar")
def test_save_file_dialog_asks_for_overwrite_darwin(self, msgbox, dlg): def selected_files(): nonlocal attempts attempts += 1 return [["old.tab", "new.tab"][attempts]] widget = self.widget widget.initial_start_dir = lambda: "baz" filter1 = "" # prevent pylint warning 'undefined-loop-variable' for filter1 in widget.get_filters(): if OWSaveBase._extension_from_filter(filter1) == ".tab": break widget.filter = filter1 instance = dlg.return_value instance.exec.return_value = QFileDialog.Accepted instance.selectedFiles = selected_files instance.selectedNameFilter.return_value = self.remove_star(filter1) attempts = -1 msgbox.question.return_value = msgbox.Yes = 1 self.assertEqual(widget.get_save_filename()[0], "old.tab") attempts = -1 msgbox.question.return_value = msgbox.No = 0 self.assertEqual(widget.get_save_filename()[0], "new.tab")
def test_save_file_dialog_enforces_extension_darwin(self, dlg): widget = self.widget filter1 = "" # prevent pylint warning 'undefined-loop-variable' for filter1 in widget.get_filters(): if OWSaveBase._extension_from_filter(filter1) == ".tab": break for filter2 in widget.get_filters(): if OWSaveBase._extension_from_filter(filter2) == ".csv.gz": break widget.filter = filter1 instance = dlg.return_value instance.exec.return_value = QFileDialog.Accepted instance.selectedNameFilter.return_value = self.remove_star(filter1) instance.selectedFiles.return_value = ["foo"] self.assertEqual(widget.get_save_filename()[0], "foo.tab") instance.selectedFiles.return_value = ["foo.pkl"] self.assertEqual(widget.get_save_filename()[0], "foo.tab") instance.selectedFiles.return_value = ["foo.tab.gz"] self.assertEqual(widget.get_save_filename()[0], "foo.tab") instance.selectedFiles.return_value = ["foo.csv.gz"] self.assertEqual(widget.get_save_filename()[0], "foo.tab") instance.selectedFiles.return_value = ["foo.bar"] self.assertEqual(widget.get_save_filename()[0], "foo.bar.tab") instance.selectedNameFilter.return_value = self.remove_star(filter2) instance.selectedFiles.return_value = ["foo"] self.assertEqual(widget.get_save_filename()[0], "foo.csv.gz") instance.selectedFiles.return_value = ["foo.pkl"] self.assertEqual(widget.get_save_filename()[0], "foo.csv.gz") instance.selectedFiles.return_value = ["foo.tab.gz"] self.assertEqual(widget.get_save_filename()[0], "foo.csv.gz") instance.selectedFiles.return_value = ["foo.csv.gz"] self.assertEqual(widget.get_save_filename()[0], "foo.csv.gz") instance.selectedFiles.return_value = ["foo.bar"] self.assertEqual(widget.get_save_filename()[0], "foo.bar.csv.gz")