Fix most tests/lint

This commit is contained in:
Florian Bruhin 2017-04-24 23:09:03 +02:00
parent f4d3f97cb7
commit c6e31391de
13 changed files with 41 additions and 231 deletions

View File

@ -40,7 +40,7 @@ from qutebrowser.keyinput import modeman
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
objreg, utils, typing)
from qutebrowser.utils.usertypes import KeyMode
from qutebrowser.misc import editor, guiprocess
from qutebrowser.misc import editor, guiprocess, objects
from qutebrowser.completion.models import instances, sortfilter
@ -256,15 +256,11 @@ class CommandDispatcher:
urls = self._parse_url_input(url)
if private:
try:
from PyQt5.QtWebKit import qWebKitVersion
except ImportError:
pass
else:
# WORKAROUND for https://github.com/annulen/webkit/issues/54
if qtutils.is_qtwebkit_ng(qWebKitVersion()):
message.warning("Private browsing is not fully "
"implemented by QtWebKit-NG!")
# WORKAROUND for https://github.com/annulen/webkit/issues/54
if (objects.backend == usertypes.Backend.QtWebKit and
qtutils.is_qtwebkit_ng()):
message.warning("Private browsing is not fully "
"implemented by QtWebKit-NG!")
window = True
for i, cur_url in enumerate(urls):

View File

@ -27,7 +27,6 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject
from qutebrowser.commands import cmdutils
from qutebrowser.utils import (utils, objreg, standarddir, log, qtutils,
usertypes, message)
from qutebrowser.config import config
from qutebrowser.misc import lineparser, objects
@ -274,7 +273,6 @@ class WebHistory(QObject):
(hidden in completion)
atime: Override the atime used to add the entry
"""
assert not config.get('general', 'private-browsing')
if not url.isValid():
log.misc.warning("Ignoring invalid URL being added to history")
return

View File

@ -156,7 +156,7 @@ def update_settings(section, option):
def _init_profiles():
"""Init the two used QWebEngineProfiles"""
"""Init the two used QWebEngineProfiles."""
global default_profile, private_profile
default_profile = QWebEngineProfile.defaultProfile()
default_profile.setCachePath(

View File

@ -27,8 +27,7 @@ from PyQt5.QtGui import QKeyEvent
from PyQt5.QtNetwork import QAuthenticator
# pylint: disable=no-name-in-module,import-error,useless-suppression
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import (QWebEnginePage, QWebEngineScript,
QWebEngineProfile)
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineScript
# pylint: enable=no-name-in-module,import-error,useless-suppression
from qutebrowser.browser import browsertab, mouse, shared

View File

@ -91,7 +91,8 @@ def _set_user_stylesheet():
def _init_private_browsing():
if qtutils.is_qtwebkit_ng():
# WORKAROUND for https://github.com/annulen/webkit/issues/54
message.warning("Private browsing is not fully implemented by QtWebKit-NG!")
message.warning("Private browsing is not fully implemented by "
"QtWebKit-NG!")
elif not qtutils.version_check('5.4.2'):
# WORKAROUND for https://codereview.qt-project.org/#/c/108936/
# Won't work when private browsing is not enabled globally, but that's

View File

@ -206,15 +206,7 @@ class MainWindow(QWidget):
self._messageview = messageview.MessageView(parent=self)
self._add_overlay(self._messageview, self._messageview.update_geometry)
if geometry is not None:
self._load_geometry(geometry)
elif self.win_id == 0:
self._load_state_geometry()
else:
self._set_default_geometry()
log.init.debug("Initial main window geometry: {}".format(
self.geometry()))
self._init_geometry(geometry)
self._connect_signals()
# When we're here the statusbar might not even really exist yet, so
@ -225,6 +217,17 @@ class MainWindow(QWidget):
objreg.get("app").new_window.emit(self)
def _init_geometry(self, geometry):
"""Initialize the window geometry or load it from disk."""
if geometry is not None:
self._load_geometry(geometry)
elif self.win_id == 0:
self._load_state_geometry()
else:
self._set_default_geometry()
log.init.debug("Initial main window geometry: {}".format(
self.geometry()))
def _add_overlay(self, widget, signal, *, centered=False, padding=0):
self._overlays.append((widget, signal, centered, padding))

View File

@ -336,6 +336,7 @@ class StatusBar(QWidget):
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Notify sub-widgets when the tab has been changed."""
self.url.on_tab_changed(tab)
self.prog.on_tab_changed(tab)
self.percentage.on_tab_changed(tab)

View File

@ -21,7 +21,6 @@
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
from qutebrowser.config import config
from qutebrowser.utils import usertypes, log

View File

@ -230,7 +230,7 @@ class FakeWebTab(browsertab.AbstractTab):
scroll_pos_perc=(0, 0),
load_status=usertypes.LoadStatus.success,
progress=0):
super().__init__(win_id=0, mode_manager=None)
super().__init__(win_id=0, mode_manager=None, private=False)
self._load_status = load_status
self._title = title
self._url = url

View File

@ -22,20 +22,11 @@ import pytest
from qutebrowser.browser.webkit.network import networkmanager
from qutebrowser.browser.webkit import cookies
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
class TestPrivateMode:
def test_init_with_private_mode(self, config_stub):
config_stub.data = {'general': {'private-browsing': True}}
nam = networkmanager.NetworkManager(0, 0)
assert isinstance(nam.cookieJar(), cookies.RAMCookieJar)
def test_setting_private_mode_later(self, config_stub):
config_stub.data = {'general': {'private-browsing': False}}
nam = networkmanager.NetworkManager(0, 0)
assert not isinstance(nam.cookieJar(), cookies.RAMCookieJar)
config_stub.data = {'general': {'private-browsing': True}}
nam.on_config_changed()
assert isinstance(nam.cookieJar(), cookies.RAMCookieJar)
def test_init_with_private_mode(config_stub):
nam = networkmanager.NetworkManager(win_id=0, tab_id=0, private=True)
assert isinstance(nam.cookieJar(), cookies.RAMCookieJar)
assert nam.cache() is None

View File

@ -54,41 +54,6 @@ def test_cache_config_change_cache_size(config_stub, tmpdir):
assert disk_cache.maximumCacheSize() == max_cache_size * 2
def test_cache_config_enable_private_browsing(config_stub, tmpdir):
"""Change private-browsing config to True and emit signal."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': False}
}
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.cacheSize() == 0
preload_cache(disk_cache)
assert disk_cache.cacheSize() > 0
config_stub.set('general', 'private-browsing', True)
assert disk_cache.cacheSize() == 0
def test_cache_config_disable_private_browsing(config_stub, tmpdir):
"""Change private-browsing config to False and emit signal."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
url = 'http://qutebrowser.org'
metadata = QNetworkCacheMetaData()
metadata.setUrl(QUrl(url))
assert metadata.isValid()
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.prepare(metadata) is None
config_stub.set('general', 'private-browsing', False)
content = b'cute'
preload_cache(disk_cache, url, content)
assert disk_cache.data(QUrl(url)).readAll() == content
def test_cache_size_leq_max_cache_size(config_stub, tmpdir):
"""Test cacheSize <= MaximumCacheSize when cache is activated."""
limit = 100
@ -108,16 +73,6 @@ def test_cache_size_leq_max_cache_size(config_stub, tmpdir):
assert disk_cache.cacheSize() < limit + 100
def test_cache_size_deactivated(config_stub, tmpdir):
"""Confirm that the cache size returns 0 when deactivated."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.cacheSize() == 0
def test_cache_existing_metadata_file(config_stub, tmpdir):
"""Test querying existing meta data file from activated cache."""
config_stub.data = {
@ -155,42 +110,6 @@ def test_cache_nonexistent_metadata_file(config_stub, tmpdir):
assert not cache_file.isValid()
def test_cache_deactivated_metadata_file(config_stub, tmpdir):
"""Test querying meta data file when cache is deactivated."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.fileMetaData("foo") == QNetworkCacheMetaData()
def test_cache_deactivated_private_browsing(config_stub, tmpdir):
"""Test if cache is deactivated in private-browsing mode."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
metadata = QNetworkCacheMetaData()
metadata.setUrl(QUrl('http://www.example.com/'))
assert metadata.isValid()
assert disk_cache.prepare(metadata) is None
def test_cache_deactivated_get_data(config_stub, tmpdir):
"""Query some data from a deactivated cache."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
url = QUrl('http://www.example.com/')
assert disk_cache.data(url) is None
def test_cache_get_nonexistent_data(config_stub, tmpdir):
"""Test querying some data that was never inserted."""
config_stub.data = {
@ -203,18 +122,6 @@ def test_cache_get_nonexistent_data(config_stub, tmpdir):
assert disk_cache.data(QUrl('http://qutebrowser.org')) is None
def test_cache_deactivated_remove_data(config_stub, tmpdir):
"""Test removing some data from a deactivated cache."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
url = QUrl('http://www.example.com/')
assert not disk_cache.remove(url)
def test_cache_insert_data(config_stub, tmpdir):
"""Test if entries inserted into the cache are actually there."""
config_stub.data = {
@ -232,28 +139,6 @@ def test_cache_insert_data(config_stub, tmpdir):
assert disk_cache.data(QUrl(url)).readAll() == content
def test_cache_deactivated_insert_data(config_stub, tmpdir):
"""Insert data when cache is deactivated."""
# First create QNetworkDiskCache just to get a valid QIODevice from it
url = 'http://qutebrowser.org'
disk_cache = QNetworkDiskCache()
disk_cache.setCacheDirectory(str(tmpdir))
metadata = QNetworkCacheMetaData()
metadata.setUrl(QUrl(url))
device = disk_cache.prepare(metadata)
assert device is not None
# Now create a deactivated DiskCache and insert the valid device created
# above (there probably is a better way to get a valid QIODevice...)
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
deactivated_cache = cache.DiskCache(str(tmpdir))
assert deactivated_cache.insert(device) is None
def test_cache_remove_data(config_stub, tmpdir):
"""Test if a previously inserted entry can be removed from the cache."""
config_stub.data = {
@ -285,16 +170,6 @@ def test_cache_clear_activated(config_stub, tmpdir):
assert disk_cache.cacheSize() == 0
def test_cache_clear_deactivated(config_stub, tmpdir):
"""Test method clear() on deactivated cache."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.clear() is None
def test_cache_metadata(config_stub, tmpdir):
"""Ensure that DiskCache.metaData() returns exactly what was inserted."""
config_stub.data = {
@ -313,18 +188,6 @@ def test_cache_metadata(config_stub, tmpdir):
assert disk_cache.metaData(QUrl(url)) == metadata
def test_cache_deactivated_metadata(config_stub, tmpdir):
"""Test querying metaData() on not activated cache."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
url = 'http://qutebrowser.org'
disk_cache = cache.DiskCache(str(tmpdir))
assert disk_cache.metaData(QUrl(url)) == QNetworkCacheMetaData()
def test_cache_update_metadata(config_stub, tmpdir):
"""Test updating the meta data for an existing cache entry."""
config_stub.data = {
@ -343,21 +206,6 @@ def test_cache_update_metadata(config_stub, tmpdir):
assert disk_cache.metaData(QUrl(url)) == metadata
def test_cache_deactivated_update_metadata(config_stub, tmpdir):
"""Test updating the meta data when cache is not activated."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': True}
}
url = 'http://qutebrowser.org'
disk_cache = cache.DiskCache(str(tmpdir))
metadata = QNetworkCacheMetaData()
metadata.setUrl(QUrl(url))
assert metadata.isValid()
assert disk_cache.updateMetaData(metadata) is None
def test_cache_full(config_stub, tmpdir):
"""Do a sanity test involving everything."""
config_stub.data = {
@ -385,3 +233,10 @@ def test_cache_full(config_stub, tmpdir):
assert disk_cache.metaData(QUrl(url)).lastModified() == soon
assert disk_cache.data(QUrl(url)).readAll() == content
def test_private_browsing(config_stub, tmpdir):
"""Make sure the cache asserts with private browsing."""
config_stub.data = {'general': {'private-browsing': True}}
with pytest.raises(AssertionError):
cache.DiskCache(str(tmpdir))

View File

@ -38,18 +38,13 @@ class FakeWebHistory:
self.history_dict = history_dict
@pytest.fixture(autouse=True)
def prerequisites(config_stub, fake_save_manager):
"""Make sure everything is ready to initialize a WebHistory."""
config_stub.data = {'general': {'private-browsing': False}}
@pytest.fixture()
def hist(tmpdir):
def hist(tmpdir, fake_save_manager):
return history.WebHistory(hist_dir=str(tmpdir), hist_name='history')
def test_async_read_twice(monkeypatch, qtbot, tmpdir, caplog):
def test_async_read_twice(monkeypatch, qtbot, tmpdir, caplog,
fake_save_manager):
(tmpdir / 'filled-history').write('\n'.join([
'12345 http://example.com/ title',
'67890 http://example.com/',
@ -88,34 +83,6 @@ def test_adding_item_during_async_read(qtbot, hist, redirect):
assert list(hist.history_dict.values()) == [expected]
def test_private_browsing(qtbot, tmpdir, fake_save_manager, config_stub):
"""Make sure no data is saved at all with private browsing."""
config_stub.data = {'general': {'private-browsing': True}}
private_hist = history.WebHistory(hist_dir=str(tmpdir),
hist_name='history')
# Before initial read
with qtbot.assertNotEmitted(private_hist.add_completion_item), \
qtbot.assertNotEmitted(private_hist.item_added):
private_hist.add_url(QUrl('http://www.example.com/'))
assert not private_hist._temp_history
# read
with qtbot.assertNotEmitted(private_hist.add_completion_item), \
qtbot.assertNotEmitted(private_hist.item_added):
with qtbot.waitSignals([private_hist.async_read_done], order='strict'):
list(private_hist.async_read())
# after read
with qtbot.assertNotEmitted(private_hist.add_completion_item), \
qtbot.assertNotEmitted(private_hist.item_added):
private_hist.add_url(QUrl('http://www.example.com/'))
assert not private_hist._temp_history
assert not private_hist._new_history
assert not private_hist.history_dict
def test_iter(hist):
list(hist.async_read())
@ -257,7 +224,7 @@ def test_add_item_redirect(qtbot, hist):
assert hist.history_dict[url] == entry
def test_add_item_redirect_update(qtbot, tmpdir):
def test_add_item_redirect_update(qtbot, tmpdir, fake_save_manager):
"""A redirect update added should override a non-redirect one."""
url = 'http://www.example.com/'

View File

@ -34,7 +34,7 @@ class TestCommandLineEdit:
@pytest.fixture
def cmd_edit(self, qtbot):
"""Fixture to initialize a CommandLineEdit."""
cmd_edit = miscwidgets.CommandLineEdit(None)
cmd_edit = miscwidgets.CommandLineEdit()
cmd_edit.set_prompt(':')
qtbot.add_widget(cmd_edit)
assert cmd_edit.text() == ''