示例#1
0
    def test_replace_params_params(self):
        """
        Test replace_params when given a positional and a keyword argument to change
        """
        # GIVEN: Some test data
        test_args = (1, 2)
        test_kwargs = {'arg3': 3, 'arg4': 4}
        test_params = ((1, 'arg2', str), (2, 'arg3', str))

        # WHEN: Calling replace_params
        result_args, result_kwargs = replace_params(test_args, test_kwargs,
                                                    test_params)

        # THEN: The positional and keyword args should have have changed
        assert result_args == (1, '2')
        assert result_kwargs == {'arg3': '3', 'arg4': 4}
示例#2
0
    def test_replace_params_no_params(self):
        """
        Test replace_params when called with and empty tuple instead of parameters to replace
        """
        # GIVEN: Some test data
        test_args = (1, 2)
        test_kwargs = {'arg3': 3, 'arg4': 4}
        test_params = tuple()

        # WHEN: Calling replace_params
        result_args, result_kwargs = replace_params(test_args, test_kwargs,
                                                    test_params)

        # THEN: The positional and keyword args should not have changed
        assert test_args == result_args
        assert test_kwargs == result_kwargs
示例#3
0
文件: dialogs.py 项目: ipic/projecao
    def getExistingDirectory(cls, *args, **kwargs):
        """
        Wraps `getExistingDirectory` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type options: QtWidgets.QFileDialog.Options
        :rtype: pathlib.Path
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        return_value = super().getExistingDirectory(*args, **kwargs)

        # getExistingDirectory returns a str that represents the path. The string is empty if the user cancels the
        # dialog.
        return str_to_path(return_value)
示例#4
0
文件: dialogs.py 项目: ipic/projecao
    def getSaveFileName(cls, *args, **kwargs):
        """
        Wraps `getSaveFileName` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type filter: str
        :type initialFilter: str
        :type options: QtWidgets.QFileDialog.Options
        :rtype: tuple[pathlib.Path | None, str]
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        file_name, selected_filter = super().getSaveFileName(*args, **kwargs)

        # getSaveFileName returns a tuple. The first item represents the path as a str. The string is empty if the user
        # cancels the dialog.
        return str_to_path(file_name), selected_filter
示例#5
0
文件: dialogs.py 项目: ipic/projecao
    def getOpenFileNames(cls, *args, **kwargs):
        """
        Wraps `getOpenFileNames` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type filter: str
        :type initialFilter: str
        :type options: QtWidgets.QFileDialog.Options
        :rtype: tuple[list[pathlib.Path], str]
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        file_names, selected_filter = super().getOpenFileNames(*args, **kwargs)

        # getSaveFileName returns a tuple. The first item is a list of str's that represents the path. The list is
        # empty if the user cancels the dialog.
        paths = [str_to_path(path) for path in file_names]
        return paths, selected_filter