Fix some tests

This commit is contained in:
Florian Bruhin 2016-06-13 17:49:52 +02:00
parent 115021b8ea
commit bf286f8c74
4 changed files with 35 additions and 29 deletions

View File

@ -21,10 +21,12 @@
import itertools import itertools
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal, QUrl
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QLayout from PyQt5.QtWidgets import QWidget, QLayout
from qutebrowser.utils import utils
tab_id_gen = itertools.count(0) tab_id_gen = itertools.count(0)
@ -111,3 +113,8 @@ class AbstractTab(QWidget):
def openurl(self, url): def openurl(self, url):
raise NotImplementedError raise NotImplementedError
def __repr__(self):
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
100)
return utils.get_repr(self, tab_id=self.tab_id, url=url)

View File

@ -202,21 +202,22 @@ class QuteProc(testprocess.Process):
self._log(log_line) self._log(log_line)
start_okay_message_load = ( start_okay_message_load = (
"load status for <qutebrowser.browser.webkit.webview.WebView " "load status for <qutebrowser.browser.* tab_id=0 "
"tab_id=0 url='about:blank'>: LoadStatus.success") "url='about:blank'>: LoadStatus.success")
start_okay_message_focus = ( start_okay_message_focus = (
"Focus object changed: " "Focus object changed: "
"<qutebrowser.browser.webkit.webview.WebView " "<qutebrowser.browser.* tab_id=0 url='about:blank'>")
"tab_id=0 url='about:blank'>")
if (log_line.category == 'ipc' and if (log_line.category == 'ipc' and
log_line.message.startswith("Listening as ")): log_line.message.startswith("Listening as ")):
self._ipc_socket = log_line.message.split(' ', maxsplit=2)[2] self._ipc_socket = log_line.message.split(' ', maxsplit=2)[2]
elif (log_line.category == 'webview' and elif (log_line.category == 'webview' and
log_line.message == start_okay_message_load): testutils.pattern_match(pattern=start_okay_message_load,
value=log_line.message)):
self._is_ready('load') self._is_ready('load')
elif (log_line.category == 'misc' and elif (log_line.category == 'misc' and
log_line.message == start_okay_message_focus): testutils.pattern_match(pattern=start_okay_message_focus,
value=log_line.message)):
self._is_ready('focus') self._is_ready('focus')
elif (log_line.category == 'init' and elif (log_line.category == 'init' and
log_line.module == 'standarddir' and log_line.module == 'standarddir' and
@ -291,8 +292,7 @@ class QuteProc(testprocess.Process):
# Try to complain about the most common mistake when accidentally # Try to complain about the most common mistake when accidentally
# loading external resources. # loading external resources.
is_ddg_load = testutils.pattern_match( is_ddg_load = testutils.pattern_match(
pattern="load status for <qutebrowser.browser.webview.WebView " pattern="load status for <* tab_id=* url='*duckduckgo*'>: *",
"tab_id=* url='*duckduckgo*'>: *",
value=msg.message) value=msg.message)
return msg.loglevel > logging.INFO or is_js_error or is_ddg_load return msg.loglevel > logging.INFO or is_js_error or is_ddg_load
@ -442,8 +442,7 @@ class QuteProc(testprocess.Process):
assert url assert url
pattern = re.compile( pattern = re.compile(
r"(load status for " r"(load status for <qutebrowser\.browser\..* "
r"<qutebrowser\.browser\.webkit\.webview\.WebView "
r"tab_id=\d+ url='{url}/?'>: LoadStatus\.{load_status}|fetch: " r"tab_id=\d+ url='{url}/?'>: LoadStatus\.{load_status}|fetch: "
r"PyQt5\.QtCore\.QUrl\('{url}'\) -> .*)".format( r"PyQt5\.QtCore\.QUrl\('{url}'\) -> .*)".format(
load_status=re.escape(load_status), url=re.escape(url))) load_status=re.escape(load_status), url=re.escape(url)))

View File

@ -24,8 +24,8 @@ from collections import namedtuple
import pytest import pytest
from qutebrowser.browser.webkit import webview
from qutebrowser.mainwindow.statusbar.progress import Progress from qutebrowser.mainwindow.statusbar.progress import Progress
from qutebrowser.utils import usertypes
@pytest.fixture @pytest.fixture
@ -60,11 +60,11 @@ Tab = namedtuple('Tab', 'progress load_status')
@pytest.mark.parametrize('tab, expected_visible', [ @pytest.mark.parametrize('tab, expected_visible', [
(Tab(15, webview.LoadStatus.loading), True), (Tab(15, usertypes.LoadStatus.loading), True),
(Tab(100, webview.LoadStatus.success), False), (Tab(100, usertypes.LoadStatus.success), False),
(Tab(100, webview.LoadStatus.error), False), (Tab(100, usertypes.LoadStatus.error), False),
(Tab(100, webview.LoadStatus.warn), False), (Tab(100, usertypes.LoadStatus.warn), False),
(Tab(100, webview.LoadStatus.none), False), (Tab(100, usertypes.LoadStatus.none), False),
]) ])
def test_tab_changed(progress_widget, tab, expected_visible): def test_tab_changed(progress_widget, tab, expected_visible):
"""Test that progress widget value and visibility state match expectations. """Test that progress widget value and visibility state match expectations.

View File

@ -23,7 +23,7 @@
import pytest import pytest
import collections import collections
from qutebrowser.browser.webkit import webview from qutebrowser.utils import usertypes
from qutebrowser.mainwindow.statusbar import url from qutebrowser.mainwindow.statusbar import url
@ -105,12 +105,12 @@ def test_set_hover_url_encoded(url_widget, url_text, expected):
@pytest.mark.parametrize('status, expected', [ @pytest.mark.parametrize('status, expected', [
(webview.LoadStatus.success, url.UrlType.success), (usertypes.LoadStatus.success, url.UrlType.success),
(webview.LoadStatus.success_https, url.UrlType.success_https), (usertypes.LoadStatus.success_https, url.UrlType.success_https),
(webview.LoadStatus.error, url.UrlType.error), (usertypes.LoadStatus.error, url.UrlType.error),
(webview.LoadStatus.warn, url.UrlType.warn), (usertypes.LoadStatus.warn, url.UrlType.warn),
(webview.LoadStatus.loading, url.UrlType.normal), (usertypes.LoadStatus.loading, url.UrlType.normal),
(webview.LoadStatus.none, url.UrlType.normal) (usertypes.LoadStatus.none, url.UrlType.normal)
]) ])
def test_on_load_status_changed(url_widget, status, expected): def test_on_load_status_changed(url_widget, status, expected):
"""Test text when status is changed.""" """Test text when status is changed."""
@ -141,15 +141,15 @@ def test_on_tab_changed(url_widget, tab_widget, load_status, url_text):
@pytest.mark.parametrize('url_text, load_status, expected_status', [ @pytest.mark.parametrize('url_text, load_status, expected_status', [
('http://abc123.com/this/awesome/url.html', webview.LoadStatus.success, ('http://abc123.com/this/awesome/url.html', usertypes.LoadStatus.success,
url.UrlType.success), url.UrlType.success),
('https://supersecret.gov/nsa/files.txt', webview.LoadStatus.success_https, ('https://supersecret.gov/nsa/files.txt', usertypes.LoadStatus.success_https,
url.UrlType.success_https), url.UrlType.success_https),
('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', webview.LoadStatus.error, ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', usertypes.LoadStatus.error,
url.UrlType.error), url.UrlType.error),
('http://www.qutebrowser.org/CONTRIBUTING.html', webview.LoadStatus.loading, ('http://www.qutebrowser.org/CONTRIBUTING.html', usertypes.LoadStatus.loading,
url.UrlType.normal), url.UrlType.normal),
('www.whatisthisurl.com', webview.LoadStatus.warn, url.UrlType.warn) ('www.whatisthisurl.com', usertypes.LoadStatus.warn, url.UrlType.warn)
]) ])
def test_normal_url(url_widget, url_text, load_status, expected_status): def test_normal_url(url_widget, url_text, load_status, expected_status):
url_widget.set_url(url_text) url_widget.set_url(url_text)