Example #1
0
    def prompt_open_download(self, cmdline: str = None):
        """Immediately open a download.

        If no specific command is given, this will use the system's default
        application to open the file.

        Args:
            cmdline: The command which should be used to open the file. A `{}`
                     is expanded to the temporary file name. If no `{}` is
                     present, the filename is automatically appended to the
                     cmdline.
        """
        if self._question.mode != usertypes.PromptMode.download:
            # We just ignore this if we don't have a download question.
            return
        self._question.answer = usertypes.OpenFileDownloadTarget(cmdline)
        modeman.maybe_leave(self._win_id, usertypes.KeyMode.prompt,
                            'download open')
        self._question.done()
def test_openfile_custom_command():
    target = usertypes.OpenFileDownloadTarget('echo')
    assert target.cmdline == 'echo'

def test_filename():
    target = usertypes.FileDownloadTarget("/foo/bar")
    assert target.filename == "/foo/bar"


def test_fileobj():
    fobj = object()
    target = usertypes.FileObjDownloadTarget(fobj)
    assert target.fileobj is fobj


def test_openfile():
    target = usertypes.OpenFileDownloadTarget()
    assert target.cmdline is None


def test_openfile_custom_command():
    target = usertypes.OpenFileDownloadTarget('echo')
    assert target.cmdline == 'echo'


@pytest.mark.parametrize('obj', [
    usertypes.FileDownloadTarget('foobar'),
    usertypes.FileObjDownloadTarget(None),
    usertypes.OpenFileDownloadTarget(),
])
def test_class_hierarchy(obj):
    assert isinstance(obj, usertypes.DownloadTarget)
def test_openfile():
    target = usertypes.OpenFileDownloadTarget()
    assert target.cmdline is None
Example #5
0
 def download_open(self, cmdline):
     self.question.answer = usertypes.OpenFileDownloadTarget(cmdline)
     self.question.done()
     message.global_bridge.prompt_done.emit(self.KEY_MODE)