diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-01-20 10:30:25 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-01-20 10:30:25 +0100 |
commit | 6fd2077b6c84e0e3c9beb40f34ede9b3dc9a7c4f (patch) | |
tree | 663182b2f8733274cc8adefe0906f752a6ce7e1f /tests | |
parent | 12583d359ed1386f21eb92e4cc3708eb02790e22 (diff) | |
download | qutebrowser-6fd2077b6c84e0e3c9beb40f34ede9b3dc9a7c4f.tar.gz qutebrowser-6fd2077b6c84e0e3c9beb40f34ede9b3dc9a7c4f.zip |
Improve tests for filesystem completion
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/completion/test_models.py | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index d981caa9d..1709a4ef4 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.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): |