filedialogs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from unittest import mock
|
||||
|
||||
from utils.filedialogs import get_dir_path_from_dialog, get_file_path_from_dialog
|
||||
|
||||
|
||||
def test_get_dir_path_from_dialog_returns_selected_path():
|
||||
with mock.patch("tkinter.Tk"), mock.patch(
|
||||
"tkinter.filedialog.askdirectory", return_value="/tmp/somewhere"
|
||||
) as dialog:
|
||||
result = get_dir_path_from_dialog(initialdir="/tmp", title="Pick")
|
||||
assert result == "/tmp/somewhere"
|
||||
dialog.assert_called_once_with(initialdir="/tmp", title="Pick")
|
||||
|
||||
|
||||
def test_get_dir_path_from_dialog_returns_empty_string_on_cancel():
|
||||
with mock.patch("tkinter.Tk"), mock.patch(
|
||||
"tkinter.filedialog.askdirectory", return_value=""
|
||||
):
|
||||
assert get_dir_path_from_dialog() == ""
|
||||
|
||||
|
||||
def test_get_file_path_from_dialog_returns_selected_path():
|
||||
with mock.patch("tkinter.Tk"), mock.patch(
|
||||
"tkinter.filedialog.askopenfilename", return_value="/tmp/file.txt"
|
||||
) as dialog:
|
||||
result = get_file_path_from_dialog(filetypes=[("Text", "*.txt")])
|
||||
assert result == "/tmp/file.txt"
|
||||
dialog.assert_called_once_with(filetypes=[("Text", "*.txt")])
|
||||
|
||||
|
||||
def test_get_file_path_from_dialog_returns_empty_string_on_cancel():
|
||||
with mock.patch("tkinter.Tk"), mock.patch(
|
||||
"tkinter.filedialog.askopenfilename", return_value=""
|
||||
):
|
||||
assert get_file_path_from_dialog() == ""
|
||||
Reference in New Issue
Block a user