qutebrowser/tests/integration/features/test_features.py

106 lines
3.2 KiB
Python
Raw Normal View History

2015-10-11 13:53:59 +02:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import sys
2015-11-01 22:10:48 +01:00
import logging
2015-10-11 13:53:59 +02:00
import pytest
2015-11-02 07:43:37 +01:00
from PyQt5.QtGui import QClipboard
if hasattr(sys, 'frozen'):
pytest.skip("test")
else:
import pytest_bdd as bdd
bdd.scenarios('.')
2015-10-11 13:53:59 +02:00
@bdd.given(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))
def set_setting(quteproc, sect, opt, value):
quteproc.set_setting(sect, opt, value)
@bdd.given(bdd.parsers.parse("I open {path}"))
def open_path(quteproc, path):
2015-10-13 07:14:32 +02:00
quteproc.open_path(path, new_tab=True)
2015-10-11 13:53:59 +02:00
@bdd.when(bdd.parsers.parse("I open {path}"))
def open_path_when(quteproc, path):
quteproc.open_path(path)
@bdd.when(bdd.parsers.parse("I run {command}"))
def run_command(quteproc, command):
quteproc.send_cmd(command)
@bdd.when(bdd.parsers.parse("I reload"))
2015-10-27 08:07:16 +01:00
def reload(qtbot, httpbin, quteproc, command):
with qtbot.waitSignal(httpbin.new_request, raising=True):
quteproc.send_cmd(':reload')
2015-11-02 08:07:25 +01:00
@bdd.when("selection is supported")
def selection_supported(qapp):
if not qapp.clipboard().supportsSelection():
pytest.skip("OS doesn't support primary selection!")
2015-10-11 13:53:59 +02:00
@bdd.then(bdd.parsers.parse("{path} should be loaded"))
def path_should_be_loaded(httpbin, path):
requests = httpbin.get_requests()
assert requests[-1] == httpbin.Request('GET', '/' + path)
2015-10-11 13:53:59 +02:00
@bdd.then(bdd.parsers.parse("The requests should be:\n{pages}"))
2015-10-27 08:07:16 +01:00
def list_of_loaded_pages(httpbin, pages):
requests = [httpbin.Request('GET', '/' + path.strip())
for path in pages.split('\n')]
2015-10-11 13:53:59 +02:00
assert httpbin.get_requests() == requests
2015-10-22 06:44:05 +02:00
2015-11-02 07:43:37 +01:00
@bdd.then(bdd.parsers.re(r'the (?P<category>error|message) "(?P<message>.*)" '
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],
2015-11-01 22:10:48 +01:00
message=message)
2015-11-02 07:43:37 +01:00
@bdd.then(bdd.parsers.re(r'the (?P<what>primary selection|clipboard) should '
r'contain "(?P<content>.*)"'))
def clipboard_contains(qapp, httpbin, what, content):
if what == 'clipboard':
mode = QClipboard.Clipboard
elif what == 'primary selection':
mode = QClipboard.Selection
else:
raise AssertionError
expected = content.replace('(port)', str(httpbin.port))
2015-11-02 08:07:25 +01:00
data = qapp.clipboard().text(mode=mode)
2015-11-02 07:43:37 +01:00
assert data == expected