2016-10-31 13:53:55 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2018-02-05 12:19:50 +01:00
|
|
|
# Copyright 2016-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2016-10-31 13:53:55 +01:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-02 09:25:24 +01:00
|
|
|
import os
|
|
|
|
|
2016-10-31 13:53:55 +01:00
|
|
|
import pytest
|
2016-11-02 12:47:08 +01:00
|
|
|
from PyQt5.QtCore import Qt
|
2016-10-31 13:53:55 +01:00
|
|
|
|
|
|
|
from qutebrowser.mainwindow import prompt as promptmod
|
|
|
|
from qutebrowser.utils import usertypes
|
|
|
|
|
|
|
|
|
2016-11-02 09:25:24 +01:00
|
|
|
class TestFileCompletion:
|
|
|
|
|
|
|
|
@pytest.fixture
|
2017-07-03 18:42:41 +02:00
|
|
|
def get_prompt(self, qtbot, config_stub, key_config_stub):
|
2016-11-02 12:47:08 +01:00
|
|
|
"""Get a function to display a prompt with a path."""
|
2017-07-03 18:42:41 +02:00
|
|
|
config_stub.val.bindings.default = {}
|
2017-07-04 13:05:10 +02:00
|
|
|
|
2016-11-02 09:25:24 +01:00
|
|
|
def _get_prompt_func(path):
|
|
|
|
question = usertypes.Question()
|
|
|
|
question.title = "test"
|
|
|
|
question.default = path
|
|
|
|
|
|
|
|
prompt = promptmod.DownloadFilenamePrompt(question)
|
|
|
|
qtbot.add_widget(prompt)
|
|
|
|
with qtbot.wait_signal(prompt._file_model.directoryLoaded):
|
|
|
|
pass
|
|
|
|
assert prompt._lineedit.text() == path
|
|
|
|
|
|
|
|
return prompt
|
|
|
|
return _get_prompt_func
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('steps, where, subfolder', [
|
|
|
|
(1, 'next', '..'),
|
|
|
|
(1, 'prev', 'c'),
|
|
|
|
(2, 'next', 'a'),
|
|
|
|
(2, 'prev', 'b'),
|
|
|
|
])
|
|
|
|
def test_simple_completion(self, tmpdir, get_prompt, steps, where,
|
|
|
|
subfolder):
|
2016-11-02 12:47:08 +01:00
|
|
|
"""Simply trying to tab through items."""
|
2018-02-19 15:35:29 +01:00
|
|
|
testdir = tmpdir / 'test'
|
2016-11-02 09:25:24 +01:00
|
|
|
for directory in 'abc':
|
2018-02-19 15:35:29 +01:00
|
|
|
(testdir / directory).ensure(dir=True)
|
2016-11-02 09:25:24 +01:00
|
|
|
|
2018-02-19 15:35:29 +01:00
|
|
|
prompt = get_prompt(str(testdir) + os.sep)
|
2016-11-02 09:25:24 +01:00
|
|
|
|
|
|
|
for _ in range(steps):
|
|
|
|
prompt.item_focus(where)
|
|
|
|
|
2018-02-19 15:35:29 +01:00
|
|
|
assert prompt._lineedit.text() == str(testdir / subfolder)
|
2016-11-02 12:47:08 +01:00
|
|
|
|
|
|
|
def test_backspacing_path(self, qtbot, tmpdir, get_prompt):
|
|
|
|
"""When we start deleting a path we want to see the subdir."""
|
2018-02-19 15:35:29 +01:00
|
|
|
testdir = tmpdir / 'test'
|
|
|
|
|
2016-11-02 12:47:08 +01:00
|
|
|
for directory in ['bar', 'foo']:
|
2018-02-19 15:35:29 +01:00
|
|
|
(testdir / directory).ensure(dir=True)
|
2016-11-02 12:47:08 +01:00
|
|
|
|
2018-02-19 15:35:29 +01:00
|
|
|
prompt = get_prompt(str(testdir / 'foo') + os.sep)
|
2016-11-02 12:47:08 +01:00
|
|
|
|
|
|
|
# Deleting /f[oo/]
|
|
|
|
with qtbot.wait_signal(prompt._file_model.directoryLoaded):
|
|
|
|
for _ in range(3):
|
|
|
|
qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
|
|
|
|
|
2018-02-17 20:58:33 +01:00
|
|
|
# foo should get completed from f
|
|
|
|
prompt.item_focus('next')
|
|
|
|
assert prompt._lineedit.text() == str(testdir / 'foo')
|
|
|
|
|
|
|
|
# Deleting /[foo]
|
|
|
|
for _ in range(3):
|
|
|
|
qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
|
|
|
|
|
2016-11-02 12:47:08 +01:00
|
|
|
# We should now show / again, so tabbing twice gives us .. -> bar
|
|
|
|
prompt.item_focus('next')
|
|
|
|
prompt.item_focus('next')
|
2018-02-19 15:35:29 +01:00
|
|
|
assert prompt._lineedit.text() == str(testdir / 'bar')
|
2016-11-02 22:58:24 +01:00
|
|
|
|
|
|
|
@pytest.mark.linux
|
|
|
|
def test_root_path(self, get_prompt):
|
|
|
|
"""With / as path, show root contents."""
|
|
|
|
prompt = get_prompt('/')
|
|
|
|
assert prompt._file_model.rootPath() == '/'
|