Esempio n. 1
0
def user_set_chart_save_folder():
    dialogue_message = 'Please_select location for chart save folder, or press cancel to use default.'
    new_default_save_location = select_folder_dialogue(
        title_str=dialogue_message, start_dir='..')

    if not new_default_save_location:  # User presses cancel, doesn't select a folder.
        return APP_DEFAULT_CHART_SAVE_FOLDER
    # else:
    return new_default_save_location
Esempio n. 2
0
    def test_select_folder_dialogue_no_input_returns_None(self, mock_tkinter):
        with patch('dionysus_app.UI_menus.UI_functions.filedialog.askdirectory'
                   ) as select_directorydialog:
            select_directorydialog.return_value = ''

            assert select_folder_dialogue() is None

            mock_tkinter.assert_called()
            select_directorydialog.assert_called_once_with(
                title=None, initialdir=self.test_default_start_dir)
Esempio n. 3
0
    def test_select_folder_dialogue_called_without_arguments(
            self, mock_tkinter):
        with patch('dionysus_app.UI_menus.UI_functions.filedialog.askdirectory'
                   ) as select_directorydialog:
            select_directorydialog.return_value = self.test_returned_folderpath_str

            assert select_folder_dialogue(
            ) == self.test_returned_folderpath_str

            mock_tkinter.assert_called()
            select_directorydialog.assert_called_once_with(
                title=None, initialdir=self.test_default_start_dir)
Esempio n. 4
0
    def test_select_folder_dialogue_all_None_arguments(self, mock_tkinter):
        with patch('dionysus_app.UI_menus.UI_functions.filedialog.askdirectory'
                   ) as select_directorydialog:
            select_directorydialog.return_value = self.test_returned_folderpath_path

            assert select_folder_dialogue(
                title_str=None,
                start_dir=None,
            ) == self.test_returned_folderpath_path

            assert isinstance(self.test_returned_folderpath_path, Path)

            mock_tkinter.assert_called()
            select_directorydialog.assert_called_once_with(title=None,
                                                           initialdir=None)
def user_set_chart_save_folder() -> Path:
    """
    Prompt user for dir to save created charts in.

    Returns default if user declines.

    :return: Path
    """
    dialogue_message = ('Please select location for chart save folder, or'
                        ' press cancel to use default.')
    new_default_save_location = select_folder_dialogue(
        title_str=dialogue_message, start_dir='..')

    if not new_default_save_location:  # User presses cancel, doesn't select a folder.
        return APP_DEFAULT_CHART_SAVE_DIR
    # else:
    print(f'Default chart save folder set to {new_default_save_location}')
    return new_default_save_location
Esempio n. 6
0
    def test_select_folder_dialogue(self, mock_tk, monkeypatch,
                                    select_folder_dialogue_args,
                                    expected_askdirectory_args,
                                    test_path,
                                    returned_path):
        default_start_dir = '..'

        def mocked_filedialog_askdirectory(title,
                                           initialdir,
                                           ):
            """
            Test arguments passed to filedialog are as expected, subbing with defaults save_as_dialogue
            will supply if no value is passed (equivalent to expecting the default).
            """
            assert title == expected_askdirectory_args.get('title', None)
            assert initialdir == expected_askdirectory_args.get('initialdir', default_start_dir)

            return test_path

        monkeypatch.setattr(UI_functions.filedialog, 'askdirectory', mocked_filedialog_askdirectory)

        assert returned_path == select_folder_dialogue(**select_folder_dialogue_args)