From 1f3df64fe4c72cfcec6c6b9a9b0d5585bdd64407 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 11 Nov 2015 22:38:43 +0100 Subject: [PATCH] bdd: Add some first tests for :paste. --- tests/integration/features/test_yankpaste.py | 26 ++++++++++++++------ tests/integration/features/yankpaste.feature | 15 +++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/tests/integration/features/test_yankpaste.py b/tests/integration/features/test_yankpaste.py index 4b5f51474..21a73e377 100644 --- a/tests/integration/features/test_yankpaste.py +++ b/tests/integration/features/test_yankpaste.py @@ -27,22 +27,34 @@ import pytest_bdd as bdd bdd.scenarios('yankpaste.feature') +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(qapp, httpbin, what, content): + mode = _get_mode(qapp, what) + content = content.replace('(port)', str(httpbin.port)) + qapp.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): - if what == 'clipboard': - mode = QClipboard.Clipboard - elif what == 'primary selection': - mode = QClipboard.Selection - else: - raise AssertionError - + mode = _get_mode(qapp, what) expected = content.replace('(port)', str(httpbin.port)) data = qapp.clipboard().text(mode=mode) diff --git a/tests/integration/features/yankpaste.feature b/tests/integration/features/yankpaste.feature index 20ffb973f..8f8e6c0f2 100644 --- a/tests/integration/features/yankpaste.feature +++ b/tests/integration/features/yankpaste.feature @@ -26,3 +26,18 @@ Feature: Yanking and pasting. When I run :yank --domain Then the message "Yanked domain to clipboard: http://localhost:(port)" should be shown. And the clipboard should contain "http://localhost:(port)" + + Scenario: Pasting an URL + When I put "http://localhost:(port)/data/hello.txt" into the clipboard + And I run :paste + And I wait until data/hello.txt is loaded + Then the requests should be: + data/hello.txt + + Scenario: Pasting an URL from primary selection + When selection is supported + And I put "http://localhost:(port)/data/hello2.txt" into the primary selection + And I run :paste --sel + And I wait until data/hello2.txt is loaded + Then the requests should be: + data/hello2.txt