From bbd8cc56a2c0a646693546f55a7cbeb94e4714b8 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 2 Nov 2016 09:25:24 +0100 Subject: [PATCH] Restructure test_prompt --- tests/unit/mainwindow/test_prompt.py | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 6d50a515d..9018e3b88 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . +import os + import pytest from qutebrowser.mainwindow import prompt as promptmod @@ -28,26 +30,38 @@ def setup(qapp, key_config_stub): key_config_stub.set_bindings_for('prompt', {}) -@pytest.mark.parametrize('steps, where, subfolder', [ - (1, 'next', '..'), - (1, 'prev', 'c'), - (2, 'next', 'a'), - (2, 'prev', 'b'), -]) -def test_file_completion(tmpdir, qtbot, steps, where, subfolder): - for directory in 'abc': - (tmpdir / directory).ensure(dir=True) - question = usertypes.Question() - question.title = "test" - question.default = str(tmpdir) + '/' +class TestFileCompletion: - prompt = promptmod.DownloadFilenamePrompt(question) - qtbot.add_widget(prompt) - with qtbot.wait_signal(prompt._file_model.directoryLoaded): - pass - assert prompt._lineedit.text() == str(tmpdir) + '/' + @pytest.fixture + def get_prompt(self, qtbot): + def _get_prompt_func(path): + question = usertypes.Question() + question.title = "test" + question.default = path - for _ in range(steps): - prompt.item_focus(where) + prompt = promptmod.DownloadFilenamePrompt(question) + qtbot.add_widget(prompt) + with qtbot.wait_signal(prompt._file_model.directoryLoaded): + pass + assert prompt._lineedit.text() == path - assert prompt._lineedit.text() == str(tmpdir / subfolder) + 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): + for directory in 'abc': + (tmpdir / directory).ensure(dir=True) + + prompt = get_prompt(str(tmpdir) + os.sep) + + for _ in range(steps): + prompt.item_focus(where) + + assert prompt._lineedit.text() == str(tmpdir / subfolder)