Exemple #1
0
    def test_select_file_dialogue(self, mock_tk, monkeypatch,
                                  select_file_dialogue_args,
                                  expected_askopenfilename_args,
                                  test_filename,
                                  returned_filepath):
        default_filetypes = [("all files", "*.*")]
        default_start_dir = '..'

        def mocked_filedialog_askopenfilename(title,
                                              filetypes,
                                              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_askopenfilename_args.get('title', None)
            assert filetypes == expected_askopenfilename_args.get('filetypes', default_filetypes)
            assert initialdir == expected_askopenfilename_args.get('initialdir', default_start_dir)
            # Return null test_filename value or filename + extension if present.
            if not test_filename:
                return test_filename
            return test_filename + (expected_askopenfilename_args.get('defaultextension', '') or '')

        monkeypatch.setattr(UI_functions.filedialog, 'askopenfilename', mocked_filedialog_askopenfilename)

        assert returned_filepath == select_file_dialogue(**select_file_dialogue_args)
def select_avatar_file_dialogue():
    """
    Prompts user to select an avatar file. Only displays PNG files.
    :return: str or None
    """
    dialogue_box_title = 'Select .png format avatar:'
    filetypes = [('.png files', '*.png'), ("all files", "*.*")]
    start_dir = '..'  # start at parent to app directory.

    filename = select_file_dialogue(dialogue_box_title, filetypes, start_dir)

    return filename
Exemple #3
0
    def test_select_file_dialogue_no_input_returns_None(self, mock_tkinter):
        with patch(
                'dionysus_app.UI_menus.UI_functions.filedialog.askopenfilename'
        ) as select_filedialog:
            select_filedialog.return_value = ''

            assert select_file_dialogue() is None

            mock_tkinter.assert_called()
            select_filedialog.assert_called_once_with(
                title=None,
                filetype=self.test_default_filetypes,
                initialdir=None)
def select_avatar_file_dialogue() -> Optional[Path]:
    """
    Prompts user to select an avatar file.

    Currently only displays PNG files by default.

    :return: Path or None
    """
    dialogue_box_title = 'Select .png format avatar:'
    filetypes = [('.png files', '*.png'), ("all files", "*.*")]
    start_dir = '..'  # start at parent to app directory.

    return select_file_dialogue(dialogue_box_title, filetypes, start_dir)
Exemple #5
0
    def test_select_file_dialogue_called_without_arguments(self, mock_tkinter):
        # Tests filedialog called with default_filetypes.
        with patch(
                'dionysus_app.UI_menus.UI_functions.filedialog.askopenfilename'
        ) as select_filedialog:
            select_filedialog.return_value = self.test_returned_filepath_str

            assert select_file_dialogue() == self.test_returned_filepath_str

            mock_tkinter.assert_called()
            select_filedialog.assert_called_once_with(
                title=None,
                filetype=self.test_default_filetypes,
                initialdir=None)
Exemple #6
0
def get_data_file():
    """
    Prompt user to select a file from a GUI file selection dialogue.

    :return: Path or None
    """
    selected_filename = select_file_dialogue(
        title_str='Select file to transform:',
        filetypes=[('.cld', '*.cld'), ("all files", "*.*")],
        start_dir=CLASSLIST_DATA_PATH,
    )

    if selected_filename is None:
        return None
    return selected_filename
Exemple #7
0
    def test_select_file_dialogue_called_with_all_arguments(
            self, mock_tkinter):
        with patch(
                'dionysus_app.UI_menus.UI_functions.filedialog.askopenfilename'
        ) as select_filedialog:
            select_filedialog.return_value = self.test_returned_filepath_str

            assert select_file_dialogue(
                title_str=self.test_title_str,
                filetypes=self.test_filetypes,
                start_dir=self.test_start_dir,
            ) == self.test_returned_filepath_str

            mock_tkinter.assert_called()
            select_filedialog.assert_called_once_with(
                title=self.test_title_str,
                filetype=self.test_filetypes,
                initialdir=self.test_start_dir)
Exemple #8
0
    def test_select_file_dialogue_all_None_arguments(self, mock_tkinter):
        with patch(
                'dionysus_app.UI_menus.UI_functions.filedialog.askopenfilename'
        ) as select_filedialog:
            select_filedialog.return_value = self.test_returned_filepath_path

            assert select_file_dialogue(
                title_str=None,
                filetypes=None,
                start_dir=None,
            ) == self.test_returned_filepath_path

            assert isinstance(self.test_returned_filepath_path, Path)

            mock_tkinter.assert_called()
            select_filedialog.assert_called_once_with(
                title=None,
                filetype=self.test_default_filetypes,
                initialdir=None)