From 3d291482a3004821276f4da5ae0fb9016315f295 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 26 Nov 2015 21:22:50 +0100 Subject: [PATCH] bdd: Move clipboard functions to conftest.py. Those are needed for caret.feature and yankpaste.feature. --- tests/integration/features/conftest.py | 40 ++++++++++++++++++++ tests/integration/features/test_yankpaste.py | 37 ------------------ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/tests/integration/features/conftest.py b/tests/integration/features/conftest.py index 009a2230f..8da76fcd3 100644 --- a/tests/integration/features/conftest.py +++ b/tests/integration/features/conftest.py @@ -28,10 +28,22 @@ import collections import yaml import pytest_bdd as bdd +from PyQt5.QtGui import QClipboard from helpers import utils # pylint: disable=import-error +def _clipboard_mode(qapp, what): + """Get the QClipboard::Mode to use based on a string.""" + if what == 'clipboard': + return QClipboard.Clipboard + elif what == 'primary selection': + assert qapp.clipboard().supportsSelection() + return QClipboard.Selection + else: + raise AssertionError + + ## Given @@ -159,6 +171,24 @@ def press_keys(quteproc, keys): quteproc.press_keys(keys) +@bdd.when("selection is supported") +def selection_supported(qapp): + """Skip the test if selection isn't supported.""" + if not qapp.clipboard().supportsSelection(): + pytest.skip("OS doesn't support primary selection!") + + +@bdd.when(bdd.parsers.re(r'I put "(?P.*)" into the ' + r'(?Pprimary selection|clipboard)')) +def fill_clipboard(qtbot, qapp, httpbin, what, content): + mode = _clipboard_mode(qapp, what) + content = content.replace('(port)', str(httpbin.port)) + + clipboard = qapp.clipboard() + with qtbot.waitSignal(clipboard.changed): + clipboard.setText(content, mode) + + ## Then @@ -317,3 +347,13 @@ def check_open_tabs(quteproc, tabs): assert session_tab['active'] else: assert 'active' not in session_tab + + +@bdd.then(bdd.parsers.re(r'the (?Pprimary selection|clipboard) should ' + r'contain "(?P.*)"')) +def clipboard_contains(qapp, httpbin, what, content): + mode = _clipboard_mode(qapp, what) + expected = content.replace('(port)', str(httpbin.port)) + + data = qapp.clipboard().text(mode=mode) + assert data == expected diff --git a/tests/integration/features/test_yankpaste.py b/tests/integration/features/test_yankpaste.py index f85f41939..862e470bc 100644 --- a/tests/integration/features/test_yankpaste.py +++ b/tests/integration/features/test_yankpaste.py @@ -43,40 +43,3 @@ def skip_with_broken_clipboard(qtbot, qapp): if clipboard.text() != "Does this work?": pytest.skip("Clipboard seems to be broken on this platform.") - - -def _get_mode(qapp, what): - """Get the QClipboard::Mode to use based on a string.""" - if what == 'clipboard': - return QClipboard.Clipboard - elif what == 'primary selection': - assert qapp.clipboard().supportsSelection() - return QClipboard.Selection - else: - raise AssertionError - - -@bdd.when("selection is supported") -def selection_supported(qapp): - if not qapp.clipboard().supportsSelection(): - pytest.skip("OS doesn't support primary selection!") - -@bdd.when(bdd.parsers.re(r'I put "(?P.*)" into the ' - r'(?Pprimary selection|clipboard)')) -def fill_clipboard(qtbot, qapp, httpbin, what, content): - mode = _get_mode(qapp, what) - content = content.replace('(port)', str(httpbin.port)) - - clipboard = qapp.clipboard() - with qtbot.waitSignal(clipboard.changed): - clipboard.setText(content, mode) - - -@bdd.then(bdd.parsers.re(r'the (?Pprimary selection|clipboard) should ' - r'contain "(?P.*)"')) -def clipboard_contains(qapp, httpbin, what, content): - mode = _get_mode(qapp, what) - expected = content.replace('(port)', str(httpbin.port)) - - data = qapp.clipboard().text(mode=mode) - assert data == expected