From 672d11e25a2fbf4c0d24d039224d8c3b45eb9224 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 2 Nov 2015 07:43:37 +0100 Subject: [PATCH] Add bdd test for :yank/:paste. --- tests/integration/data/yankpaste/test.html | 10 ++++++ tests/integration/features/test_features.py | 35 ++++++++++++++++++-- tests/integration/features/yankpaste.feature | 26 +++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/integration/data/yankpaste/test.html create mode 100644 tests/integration/features/yankpaste.feature diff --git a/tests/integration/data/yankpaste/test.html b/tests/integration/data/yankpaste/test.html new file mode 100644 index 000000000..d5e2ab9da --- /dev/null +++ b/tests/integration/data/yankpaste/test.html @@ -0,0 +1,10 @@ + + + + + Test title + + + foo + + diff --git a/tests/integration/features/test_features.py b/tests/integration/features/test_features.py index 7614aa1c9..8a146895a 100644 --- a/tests/integration/features/test_features.py +++ b/tests/integration/features/test_features.py @@ -22,6 +22,8 @@ import logging import pytest +from PyQt5.QtGui import QClipboard + if hasattr(sys, 'frozen'): pytest.skip("test") else: @@ -68,7 +70,34 @@ def list_of_loaded_pages(httpbin, pages): assert httpbin.get_requests() == requests -@bdd.then(bdd.parsers.parse('the error "{message}" should be shown.')) -def expect_error(quteproc, message): - quteproc.mark_expected(category='message', loglevel=logging.ERROR, +@bdd.then(bdd.parsers.re(r'the (?Perror|message) "(?P.*)" ' + r'should be shown.')) +def expect_error(quteproc, httpbin, category, message): + category_to_loglevel = { + 'message': logging.INFO, + 'error': logging.ERROR, + } + message = message.replace('(port)', str(httpbin.port)) + quteproc.mark_expected(category='message', + loglevel=category_to_loglevel[category], message=message) + + +@bdd.then(bdd.parsers.re(r'the (?Pprimary selection|clipboard) should ' + r'contain "(?P.*)"')) +def clipboard_contains(qapp, httpbin, what, content): + clipboard = qapp.clipboard() + + if what == 'clipboard': + mode = QClipboard.Clipboard + elif what == 'primary selection': + if not clipboard.supportsSelection(): + pytest.skip("OS doesn't support primary selection!") + mode = QClipboard.Selection + else: + raise AssertionError + + expected = content.replace('(port)', str(httpbin.port)) + + data = clipboard.text(mode=mode) + assert data == expected diff --git a/tests/integration/features/yankpaste.feature b/tests/integration/features/yankpaste.feature new file mode 100644 index 000000000..195aa4f14 --- /dev/null +++ b/tests/integration/features/yankpaste.feature @@ -0,0 +1,26 @@ +Feature: Yanking and pasting. + :yank and :paste can be used to copy/paste the URL or title from/to the + clipboard and primary selection. + + Background: + Given I open data/yankpaste/test.html + + Scenario: Yanking URLs to clipboard + When I run :yank + Then the message "Yanked URL to clipboard: http://localhost:(port)/data/yankpaste/test.html" should be shown. + And the clipboard should contain "http://localhost:(port)/data/yankpaste/test.html" + + Scenario: Yanking URLs to primary selection + When I run :yank --sel + Then the message "Yanked URL to primary selection: http://localhost:(port)/data/yankpaste/test.html" should be shown. + And the primary selection should contain "http://localhost:(port)/data/yankpaste/test.html" + + Scenario: Yanking title to clipboard + When I run :yank --title + Then the message "Yanked title to clipboard: Test title" should be shown. + And the clipboard should contain "Test title" + + Scenario: Yanking domain to clipboard + 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)"