summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJason Rosenzweig <mail4jasonr@gmail.com>2021-06-04 01:20:49 +0800
committerJason Rosenzweig <mail4jasonr@gmail.com>2021-06-04 01:20:49 +0800
commit1fe3ba356e4243581fa3ee308287560bff7ccab4 (patch)
tree2f02c1c064ac431cbf31831f88fa045e22a55773 /tests
parent0a87bb71cc4ceb3426bab82bc23da24c9cfabada (diff)
downloadqutebrowser-1fe3ba356e4243581fa3ee308287560bff7ccab4.tar.gz
qutebrowser-1fe3ba356e4243581fa3ee308287560bff7ccab4.zip
Better tests, added back _get_valid_dirs hopefully temporarily
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/mainwindow/test_prompt.py89
1 files changed, 54 insertions, 35 deletions
diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py
index 71d94e51d..558eaa89b 100644
--- a/tests/unit/mainwindow/test_prompt.py
+++ b/tests/unit/mainwindow/test_prompt.py
@@ -96,7 +96,11 @@ class TestFileCompletion:
prompt.item_focus('next')
assert prompt._lineedit.text() == str(testdir / 'bar')
- def test_filtering_path(self, qtbot, tmp_path, get_prompt):
+ @pytest.mark.parametrize("keys,expected",
+ [([], ['bar', 'foo', 'bat'].sort()),
+ (['F'], ['foo'].sort()),
+ (['Backspace', 'A'], ['bar', 'bat'].sort())])
+ def test_filtering_path(self, qtbot, tmp_path, get_prompt, keys, expected):
testdir = tmp_path / 'test'
for directory in ['bar', 'foo', 'bat']:
@@ -104,40 +108,55 @@ class TestFileCompletion:
prompt = get_prompt(str(testdir) + os.sep)
- # Make sure all directories are shown
- num_rows = prompt._file_model.rowCount(prompt._root_index)
- visible = []
- for row in range(num_rows):
- parent = prompt._file_model.index(os.path.basename(prompt._lineedit.text()))
- index = prompt._file_model.index(row, 0, parent)
- if prompt._file_view.isRowHidden(index.row(), index.parent()):
- visible.append(index.data())
-
- assert visible.sort() == ['bar', 'foo', 'bat'].sort()
-
- # Only foo should be completed with f
- qtbot.keyPress(prompt._lineedit, Qt.Key_F)
- num_rows = prompt._file_model.rowCount(prompt._root_index)
- visible = []
- for row in range(num_rows):
- parent = prompt._file_model.index(os.path.basename(prompt._lineedit.text()))
- index = prompt._file_model.index(row, 0, parent)
- if prompt._file_view.isRowHidden(index.row(), index.parent()):
- visible.append(index.data())
-
- assert visible.sort() == ['foo'].sort()
-
- # bat and bar should show up with a typed
- qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
- qtbot.keyPress(prompt._lineedit, Qt.Key_A)
- num_rows = prompt._file_model.rowCount(prompt._root_index)
- visible = []
- for row in range(num_rows):
- index = prompt._file_model.index(row, 0, prompt._file_model.index(os.path.basename(prompt._lineedit.text())))
- if prompt._file_view.isRowHidden(index.row(), index.parent()):
- visible.append(index.data())
-
- assert visible.sort() == ['bar', 'bat'].sort()
+ for _ in range(len(keys)):
+ for key in keys:
+ eval("qtbot.keyPress(prompt._lineedit, Qt.Key_{})".format(key))
+
+ num_rows = prompt._file_model.rowCount(prompt._root_index)
+ visible = []
+ for row in range(num_rows):
+ parent = prompt._file_model.index(os.path.basename(prompt._lineedit.text()))
+ index = prompt._file_model.index(row, 0, parent)
+ if prompt._file_view.isRowHidden(index.row(), index.parent()):
+ visible.append(index.data())
+
+ assert visible.sort() == expected
+
+
+ # # Make sure all directories are shown
+ # num_rows = prompt._file_model.rowCount(prompt._root_index)
+ # visible = []
+ # for row in range(num_rows):
+ # parent = prompt._file_model.index(os.path.basename(prompt._lineedit.text()))
+ # index = prompt._file_model.index(row, 0, parent)
+ # if prompt._file_view.isRowHidden(index.row(), index.parent()):
+ # visible.append(index.data())
+
+ # assert visible.sort() == ['bar', 'foo', 'bat'].sort()
+
+ # # Only foo should be completed with f
+ # qtbot.keyPress(prompt._lineedit, Qt.Key_F)
+ # num_rows = prompt._file_model.rowCount(prompt._root_index)
+ # visible = []
+ # for row in range(num_rows):
+ # parent = prompt._file_model.index(os.path.basename(prompt._lineedit.text()))
+ # index = prompt._file_model.index(row, 0, parent)
+ # if prompt._file_view.isRowHidden(index.row(), index.parent()):
+ # visible.append(index.data())
+
+ # assert visible.sort() == ['foo'].sort()
+
+ # # bat and bar should show up with a typed
+ # qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
+ # qtbot.keyPress(prompt._lineedit, Qt.Key_A)
+ # num_rows = prompt._file_model.rowCount(prompt._root_index)
+ # visible = []
+ # for row in range(num_rows):
+ # index = prompt._file_model.index(row, 0, prompt._file_model.index(os.path.basename(prompt._lineedit.text())))
+ # if prompt._file_view.isRowHidden(index.row(), index.parent()):
+ # visible.append(index.data())
+
+ # assert visible.sort() == ['bar', 'bat'].sort()
@pytest.mark.linux
def test_root_path(self, get_prompt):