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
|
Scenario: Selecting the entire document
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-end-of-document
|
And I run :move-to-end-of-document
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain:
|
Then the clipboard should contain:
|
||||||
one two three
|
one two three
|
||||||
eins zwei drei
|
eins zwei drei
|
||||||
@ -23,14 +23,14 @@ Feature: Caret mode
|
|||||||
And I run :move-to-start-of-document
|
And I run :move-to-start-of-document
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "one"
|
||||||
|
|
||||||
Scenario: Moving to end and to start of document (with selection)
|
Scenario: Moving to end and to start of document (with selection)
|
||||||
When I run :move-to-end-of-document
|
When I run :move-to-end-of-document
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-start-of-document
|
And I run :move-to-start-of-document
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain:
|
Then the clipboard should contain:
|
||||||
one two three
|
one two three
|
||||||
eins zwei drei
|
eins zwei drei
|
||||||
@ -43,7 +43,7 @@ Feature: Caret mode
|
|||||||
Scenario: Selecting a block
|
Scenario: Selecting a block
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-end-of-next-block
|
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:
|
Then the clipboard should contain:
|
||||||
one two three
|
one two three
|
||||||
eins zwei drei
|
eins zwei drei
|
||||||
@ -53,7 +53,7 @@ Feature: Caret mode
|
|||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-prev-block
|
And I run :move-to-end-of-prev-block
|
||||||
And I run :move-to-prev-word
|
And I run :move-to-prev-word
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain:
|
Then the clipboard should contain:
|
||||||
drei
|
drei
|
||||||
|
|
||||||
@ -64,14 +64,14 @@ Feature: Caret mode
|
|||||||
And I run :move-to-end-of-prev-block
|
And I run :move-to-end-of-prev-block
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-prev-word
|
And I run :move-to-prev-word
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "drei"
|
Then the clipboard should contain "drei"
|
||||||
|
|
||||||
Scenario: Moving back to the start of previous block (with selection)
|
Scenario: Moving back to the start of previous block (with selection)
|
||||||
When I run :move-to-end-of-next-block with count 2
|
When I run :move-to-end-of-next-block with count 2
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-start-of-prev-block
|
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:
|
Then the clipboard should contain:
|
||||||
eins zwei drei
|
eins zwei drei
|
||||||
|
|
||||||
@ -82,20 +82,20 @@ Feature: Caret mode
|
|||||||
And I run :move-to-start-of-prev-block
|
And I run :move-to-start-of-prev-block
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-next-word
|
And I run :move-to-next-word
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "eins "
|
Then the clipboard should contain "eins "
|
||||||
|
|
||||||
Scenario: Moving to the start of next block (with selection)
|
Scenario: Moving to the start of next block (with selection)
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-start-of-next-block
|
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"
|
Then the clipboard should contain "one two three\n"
|
||||||
|
|
||||||
Scenario: Moving to the start of next block
|
Scenario: Moving to the start of next block
|
||||||
When I run :move-to-start-of-next-block
|
When I run :move-to-start-of-next-block
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "eins"
|
||||||
|
|
||||||
# line
|
# line
|
||||||
@ -103,20 +103,20 @@ Feature: Caret mode
|
|||||||
Scenario: Selecting a line
|
Scenario: Selecting a line
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-end-of-line
|
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"
|
Then the clipboard should contain "one two three"
|
||||||
|
|
||||||
Scenario: Moving and selecting a line
|
Scenario: Moving and selecting a line
|
||||||
When I run :move-to-next-line
|
When I run :move-to-next-line
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-line
|
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"
|
Then the clipboard should contain "eins zwei drei"
|
||||||
|
|
||||||
Scenario: Selecting next line
|
Scenario: Selecting next line
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-next-line
|
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"
|
Then the clipboard should contain "one two three\n"
|
||||||
|
|
||||||
Scenario: Moving to end and to start of line
|
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 :move-to-start-of-line
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "one"
|
||||||
|
|
||||||
Scenario: Selecting a line (backwards)
|
Scenario: Selecting a line (backwards)
|
||||||
When I run :move-to-end-of-line
|
When I run :move-to-end-of-line
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
When I run :move-to-start-of-line
|
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"
|
Then the clipboard should contain "one two three"
|
||||||
|
|
||||||
Scenario: Selecting previous line
|
Scenario: Selecting previous line
|
||||||
When I run :move-to-next-line
|
When I run :move-to-next-line
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
When I run :move-to-prev-line
|
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"
|
Then the clipboard should contain "one two three\n"
|
||||||
|
|
||||||
Scenario: Moving to previous line
|
Scenario: Moving to previous line
|
||||||
@ -146,7 +146,7 @@ Feature: Caret mode
|
|||||||
When I run :move-to-prev-line
|
When I run :move-to-prev-line
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
When I run :move-to-next-line
|
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"
|
Then the clipboard should contain "one two three\n"
|
||||||
|
|
||||||
# word
|
# word
|
||||||
@ -154,35 +154,35 @@ Feature: Caret mode
|
|||||||
Scenario: Selecting a word
|
Scenario: Selecting a word
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "one"
|
||||||
|
|
||||||
Scenario: Moving to end and selecting a word
|
Scenario: Moving to end and selecting a word
|
||||||
When I run :move-to-end-of-word
|
When I run :move-to-end-of-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain " two"
|
||||||
|
|
||||||
Scenario: Moving to next word and selecting a word
|
Scenario: Moving to next word and selecting a word
|
||||||
When I run :move-to-next-word
|
When I run :move-to-next-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "two"
|
||||||
|
|
||||||
Scenario: Moving to next word and selecting until next word
|
Scenario: Moving to next word and selecting until next word
|
||||||
When I run :move-to-next-word
|
When I run :move-to-next-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-next-word
|
And I run :move-to-next-word
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "two "
|
Then the clipboard should contain "two "
|
||||||
|
|
||||||
Scenario: Moving to previous word and selecting a word
|
Scenario: Moving to previous word and selecting a word
|
||||||
When I run :move-to-end-of-word
|
When I run :move-to-end-of-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-prev-word
|
And I run :move-to-prev-word
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "one"
|
Then the clipboard should contain "one"
|
||||||
|
|
||||||
Scenario: Moving to previous word
|
Scenario: Moving to previous word
|
||||||
@ -190,7 +190,7 @@ Feature: Caret mode
|
|||||||
And I run :move-to-prev-word
|
And I run :move-to-prev-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "one"
|
||||||
|
|
||||||
# char
|
# char
|
||||||
@ -198,21 +198,21 @@ Feature: Caret mode
|
|||||||
Scenario: Selecting a char
|
Scenario: Selecting a char
|
||||||
When I run :toggle-selection
|
When I run :toggle-selection
|
||||||
And I run :move-to-next-char
|
And I run :move-to-next-char
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "o"
|
Then the clipboard should contain "o"
|
||||||
|
|
||||||
Scenario: Moving and selecting a char
|
Scenario: Moving and selecting a char
|
||||||
When I run :move-to-next-char
|
When I run :move-to-next-char
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-next-char
|
And I run :move-to-next-char
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "n"
|
Then the clipboard should contain "n"
|
||||||
|
|
||||||
Scenario: Selecting previous char
|
Scenario: Selecting previous char
|
||||||
When I run :move-to-end-of-word
|
When I run :move-to-end-of-word
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-prev-char
|
And I run :move-to-prev-char
|
||||||
And I yank the selected text
|
And I run :yank-selected
|
||||||
Then the clipboard should contain "e"
|
Then the clipboard should contain "e"
|
||||||
|
|
||||||
Scenario: Moving to previous char
|
Scenario: Moving to previous char
|
||||||
@ -220,7 +220,7 @@ Feature: Caret mode
|
|||||||
And I run :move-to-prev-char
|
And I run :move-to-prev-char
|
||||||
And I run :toggle-selection
|
And I run :toggle-selection
|
||||||
And I run :move-to-end-of-word
|
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"
|
Then the clipboard should contain "e"
|
||||||
|
|
||||||
# :yank-selected
|
# :yank-selected
|
||||||
|
@ -29,6 +29,7 @@ import collections
|
|||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
import pytest_bdd as bdd
|
import pytest_bdd as bdd
|
||||||
|
from PyQt5.QtCore import QElapsedTimer
|
||||||
from PyQt5.QtGui import QClipboard
|
from PyQt5.QtGui import QClipboard
|
||||||
|
|
||||||
from helpers import utils
|
from helpers import utils
|
||||||
@ -350,12 +351,37 @@ def check_open_tabs(quteproc, tabs):
|
|||||||
assert 'active' not in session_tab
|
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 '
|
@bdd.then(bdd.parsers.re(r'the (?P<what>primary selection|clipboard) should '
|
||||||
r'contain "(?P<content>.*)"'))
|
r'contain "(?P<content>.*)"'))
|
||||||
def clipboard_contains(qapp, httpbin, what, content):
|
def clipboard_contains(qtbot, qapp, httpbin, what, content):
|
||||||
mode = _clipboard_mode(qapp, what)
|
mode = _clipboard_mode(qapp, what)
|
||||||
expected = content.replace('(port)', str(httpbin.port))
|
expected = content.replace('(port)', str(httpbin.port))
|
||||||
expected = expected.replace('\\n', '\n')
|
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
|
||||||
|
|
||||||
import pytest_bdd as bdd
|
import pytest_bdd as bdd
|
||||||
|
from PyQt5.QtGui import QClipboard
|
||||||
|
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
from test_yankpaste import skip_with_broken_clipboard
|
from test_yankpaste import skip_with_broken_clipboard
|
||||||
@ -31,17 +32,3 @@ pytestmark = pytest.mark.qt_log_ignore(
|
|||||||
|
|
||||||
|
|
||||||
bdd.scenarios('caret.feature')
|
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