Improve tests for filesystem completion
This commit is contained in:
parent
12583d359e
commit
6fd2077b6c
|
|
@ -208,6 +208,8 @@ PERFECT_FILES = [
|
|||
'qutebrowser/completion/models/urlmodel.py'),
|
||||
('tests/unit/completion/test_models.py',
|
||||
'qutebrowser/completion/models/configmodel.py'),
|
||||
('tests/unit/completion/test_models.py',
|
||||
'qutebrowser/completion/models/filepathcategory.py'),
|
||||
('tests/unit/completion/test_histcategory.py',
|
||||
'qutebrowser/completion/models/histcategory.py'),
|
||||
('tests/unit/completion/test_listcategory.py',
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ except ImportError:
|
|||
from qutebrowser.misc import objects
|
||||
from qutebrowser.completion import completer
|
||||
from qutebrowser.completion.models import (
|
||||
configmodel, listcategory, miscmodels, urlmodel)
|
||||
configmodel, listcategory, miscmodels, urlmodel, filepathcategory)
|
||||
from qutebrowser.config import configdata, configtypes
|
||||
from qutebrowser.utils import usertypes
|
||||
from qutebrowser.mainwindow import tabbedbrowser
|
||||
|
|
@ -407,23 +407,68 @@ def test_open_categories_remove_one(qtmodeltester, config_stub, web_history_popu
|
|||
})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('method', ['normal', 'url', 'home'])
|
||||
def test_filesystem_completion(qtmodeltester, config_stub, info,
|
||||
web_history_populated, quickmarks, bookmarks,
|
||||
local_files_path):
|
||||
val = str(local_files_path) + os.sep
|
||||
local_files_path, monkeypatch, method):
|
||||
file_1 = local_files_path / 'file1.txt'
|
||||
file_2 = local_files_path / 'file2.txt'
|
||||
|
||||
if method == 'normal':
|
||||
base = str(local_files_path)
|
||||
expected_1 = str(file_1)
|
||||
expected_2 = str(file_2)
|
||||
elif method == 'url':
|
||||
base = local_files_path.as_uri()
|
||||
expected_1 = file_1.as_uri()
|
||||
expected_2 = file_2.as_uri()
|
||||
elif method == 'home':
|
||||
monkeypatch.setenv('HOME', str(local_files_path))
|
||||
base = '~'
|
||||
expected_1 = os.path.join('~', 'file1.txt')
|
||||
expected_2 = os.path.join('~', 'file2.txt')
|
||||
|
||||
config_stub.val.completion.open_categories = ['filesystem']
|
||||
model = urlmodel.url(info=info)
|
||||
model.set_pattern(val)
|
||||
model.set_pattern(base + os.sep)
|
||||
qtmodeltester.check(model)
|
||||
|
||||
_check_completions(model, {
|
||||
"Filesystem": [
|
||||
(val + 'file1.txt', None, None),
|
||||
(val + 'file2.txt', None, None),
|
||||
(expected_1, None, None),
|
||||
(expected_2, None, None),
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
def test_filesystem_completion_model_interface(info, local_files_path):
|
||||
model = filepathcategory.FilePathCategory('filepaths')
|
||||
model.set_pattern(str(local_files_path) + os.sep)
|
||||
|
||||
index = model.index(0, 0)
|
||||
assert index.isValid()
|
||||
assert model.rowCount(parent=index) == 0
|
||||
|
||||
index2 = model.index(0, 5)
|
||||
assert not index2.isValid()
|
||||
assert model.data(index2) is None
|
||||
|
||||
|
||||
@hypothesis.given(
|
||||
as_uri=hypothesis.strategies.booleans(),
|
||||
add_sep=hypothesis.strategies.booleans(),
|
||||
text=hypothesis.strategies.text(),
|
||||
)
|
||||
def test_filesystem_completion_hypothesis(info, as_uri, add_sep, text):
|
||||
if as_uri:
|
||||
text = 'file:///' + text
|
||||
if add_sep:
|
||||
text += os.sep
|
||||
|
||||
model = filepathcategory.FilePathCategory('filepaths')
|
||||
model.set_pattern(text)
|
||||
|
||||
|
||||
def test_default_filesystem_completion(qtmodeltester, config_stub, info,
|
||||
web_history_populated, quickmarks, bookmarks,
|
||||
local_files_path):
|
||||
|
|
|
|||
Loading…
Reference in New Issue