tests: Wait for data in the clipboard.
This should hopefully stabilize the flaky clipboard tests. See #1183.
This commit is contained in:
parent
f19de5b908
commit
8786e979a6
@ -10,7 +10,7 @@ Feature: Caret mode
|
||||
Scenario: Selecting the entire document
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-end-of-document
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain:
|
||||
one two three
|
||||
eins zwei drei
|
||||
@ -23,14 +23,14 @@ Feature: Caret mode
|
||||
And I run :move-to-start-of-document
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one"
|
||||
|
||||
Scenario: Moving to end and to start of document (with selection)
|
||||
When I run :move-to-end-of-document
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-start-of-document
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain:
|
||||
one two three
|
||||
eins zwei drei
|
||||
@ -43,7 +43,7 @@ Feature: Caret mode
|
||||
Scenario: Selecting a block
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-end-of-next-block
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain:
|
||||
one two three
|
||||
eins zwei drei
|
||||
@ -53,7 +53,7 @@ Feature: Caret mode
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-prev-block
|
||||
And I run :move-to-prev-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain:
|
||||
drei
|
||||
|
||||
@ -64,14 +64,14 @@ Feature: Caret mode
|
||||
And I run :move-to-end-of-prev-block
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-prev-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "drei"
|
||||
|
||||
Scenario: Moving back to the start of previous block (with selection)
|
||||
When I run :move-to-end-of-next-block with count 2
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-start-of-prev-block
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain:
|
||||
eins zwei drei
|
||||
|
||||
@ -82,20 +82,20 @@ Feature: Caret mode
|
||||
And I run :move-to-start-of-prev-block
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-next-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "eins "
|
||||
|
||||
Scenario: Moving to the start of next block (with selection)
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-start-of-next-block
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three\n"
|
||||
|
||||
Scenario: Moving to the start of next block
|
||||
When I run :move-to-start-of-next-block
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "eins"
|
||||
|
||||
# line
|
||||
@ -103,20 +103,20 @@ Feature: Caret mode
|
||||
Scenario: Selecting a line
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-end-of-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three"
|
||||
|
||||
Scenario: Moving and selecting a line
|
||||
When I run :move-to-next-line
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "eins zwei drei"
|
||||
|
||||
Scenario: Selecting next line
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-next-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three\n"
|
||||
|
||||
Scenario: Moving to end and to start of line
|
||||
@ -124,21 +124,21 @@ Feature: Caret mode
|
||||
And I run :move-to-start-of-line
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one"
|
||||
|
||||
Scenario: Selecting a line (backwards)
|
||||
When I run :move-to-end-of-line
|
||||
And I run :toggle-selection
|
||||
When I run :move-to-start-of-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three"
|
||||
|
||||
Scenario: Selecting previous line
|
||||
When I run :move-to-next-line
|
||||
And I run :toggle-selection
|
||||
When I run :move-to-prev-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three\n"
|
||||
|
||||
Scenario: Moving to previous line
|
||||
@ -146,7 +146,7 @@ Feature: Caret mode
|
||||
When I run :move-to-prev-line
|
||||
And I run :toggle-selection
|
||||
When I run :move-to-next-line
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one two three\n"
|
||||
|
||||
# word
|
||||
@ -154,35 +154,35 @@ Feature: Caret mode
|
||||
Scenario: Selecting a word
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one"
|
||||
|
||||
Scenario: Moving to end and selecting a word
|
||||
When I run :move-to-end-of-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain " two"
|
||||
|
||||
Scenario: Moving to next word and selecting a word
|
||||
When I run :move-to-next-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "two"
|
||||
|
||||
Scenario: Moving to next word and selecting until next word
|
||||
When I run :move-to-next-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-next-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "two "
|
||||
|
||||
Scenario: Moving to previous word and selecting a word
|
||||
When I run :move-to-end-of-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-prev-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one"
|
||||
|
||||
Scenario: Moving to previous word
|
||||
@ -190,7 +190,7 @@ Feature: Caret mode
|
||||
And I run :move-to-prev-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "one"
|
||||
|
||||
# char
|
||||
@ -198,21 +198,21 @@ Feature: Caret mode
|
||||
Scenario: Selecting a char
|
||||
When I run :toggle-selection
|
||||
And I run :move-to-next-char
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "o"
|
||||
|
||||
Scenario: Moving and selecting a char
|
||||
When I run :move-to-next-char
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-next-char
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "n"
|
||||
|
||||
Scenario: Selecting previous char
|
||||
When I run :move-to-end-of-word
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-prev-char
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "e"
|
||||
|
||||
Scenario: Moving to previous char
|
||||
@ -220,7 +220,7 @@ Feature: Caret mode
|
||||
And I run :move-to-prev-char
|
||||
And I run :toggle-selection
|
||||
And I run :move-to-end-of-word
|
||||
And I yank the selected text
|
||||
And I run :yank-selected
|
||||
Then the clipboard should contain "e"
|
||||
|
||||
# :yank-selected
|
||||
|
@ -29,6 +29,7 @@ import collections
|
||||
import pytest
|
||||
import yaml
|
||||
import pytest_bdd as bdd
|
||||
from PyQt5.QtCore import QElapsedTimer
|
||||
from PyQt5.QtGui import QClipboard
|
||||
|
||||
from helpers import utils
|
||||
@ -350,12 +351,37 @@ def check_open_tabs(quteproc, tabs):
|
||||
assert 'active' not in session_tab
|
||||
|
||||
|
||||
def _wait_for_clipboard(qtbot, clipboard, mode, expected):
|
||||
timeout = 1000
|
||||
timer = QElapsedTimer()
|
||||
timer.start()
|
||||
|
||||
while True:
|
||||
if clipboard.text(mode=mode) == expected:
|
||||
return
|
||||
with qtbot.waitSignal(clipboard.changed, timeout=timeout) as blocker:
|
||||
pass
|
||||
if not blocker.signal_emitted or timer.hasExpired(timeout):
|
||||
mode_names = {
|
||||
QClipboard.Clipboard: 'clipboard',
|
||||
QClipboard.Selection: 'primary selection',
|
||||
}
|
||||
raise WaitForTimeout(
|
||||
"Timed out after {}ms waiting for {} in {}.".format(
|
||||
timeout, expected, mode_names[mode]))
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.re(r'the (?P<what>primary selection|clipboard) should '
|
||||
r'contain "(?P<content>.*)"'))
|
||||
def clipboard_contains(qapp, httpbin, what, content):
|
||||
def clipboard_contains(qtbot, qapp, httpbin, what, content):
|
||||
mode = _clipboard_mode(qapp, what)
|
||||
expected = content.replace('(port)', str(httpbin.port))
|
||||
expected = expected.replace('\\n', '\n')
|
||||
_wait_for_clipboard(qtbot, qapp.clipboard(), mode, expected)
|
||||
|
||||
data = qapp.clipboard().text(mode=mode)
|
||||
assert data == expected
|
||||
|
||||
@bdd.then(bdd.parsers.parse('the clipboard should contain:\n{content}'))
|
||||
def clipboard_contains_multiline(qtbot, qapp, content):
|
||||
expected = '\n'.join(line.strip() for line in content.splitlines())
|
||||
_wait_for_clipboard(qtbot, qapp.clipboard(), QClipboard.Clipboard,
|
||||
expected)
|
||||
|
@ -20,6 +20,7 @@
|
||||
import pytest
|
||||
|
||||
import pytest_bdd as bdd
|
||||
from PyQt5.QtGui import QClipboard
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from test_yankpaste import skip_with_broken_clipboard
|
||||
@ -31,17 +32,3 @@ pytestmark = pytest.mark.qt_log_ignore(
|
||||
|
||||
|
||||
bdd.scenarios('caret.feature')
|
||||
|
||||
|
||||
@bdd.when("I yank the selected text")
|
||||
def yank_selected_text(qtbot, qapp, quteproc):
|
||||
"""Run :yank-selected and wait until the clipboard content changes."""
|
||||
with qtbot.wait_signal(qapp.clipboard().changed):
|
||||
quteproc.send_cmd(':yank-selected')
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.parse('the clipboard should contain:\n{content}'))
|
||||
def clipboard_contains_multiline(qapp, content):
|
||||
data = qapp.clipboard().text()
|
||||
expected = '\n'.join(line.strip() for line in content.splitlines())
|
||||
assert data == expected
|
||||
|
Loading…
Reference in New Issue
Block a user