Various simple test updates for new config
test_cache test_cookies test_webkitelem test_cmdutils test_runners test_completionwidget test_messageview test_editor test_miscwidgets test_sessions test_urlutils test_utils test_prompt statusbar/test_* test_cmdhistory test_tabwidget test_tab test_downloads test_networkmanager
This commit is contained in:
parent
1663280f53
commit
22b0f2fd24
@ -455,7 +455,6 @@ def fake_args():
|
||||
|
||||
@pytest.fixture
|
||||
def mode_manager(win_registry, config_stub, qapp):
|
||||
config_stub.data.update({'input': {'forward-unbound-keys': 'auto'}})
|
||||
mm = modeman.ModeManager(0)
|
||||
objreg.register('mode-manager', mm, scope='window', window=0)
|
||||
yield mm
|
||||
|
@ -40,16 +40,6 @@ except ImportError:
|
||||
|
||||
@pytest.fixture(params=[QWebView, QWebEngineView])
|
||||
def view(qtbot, config_stub, request):
|
||||
config_stub.data = {
|
||||
'input': {
|
||||
'forward-unbound-keys': 'auto'
|
||||
},
|
||||
'ui': {
|
||||
'zoom-levels': [100],
|
||||
'default-zoom': 100,
|
||||
}
|
||||
}
|
||||
|
||||
if request.param is None:
|
||||
pytest.skip("View not available")
|
||||
|
||||
|
@ -26,7 +26,7 @@ from qutebrowser.browser.webkit import cookies
|
||||
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
|
||||
|
||||
|
||||
def test_init_with_private_mode(config_stub):
|
||||
def test_init_with_private_mode():
|
||||
nam = networkmanager.NetworkManager(win_id=0, tab_id=0, private=True)
|
||||
assert isinstance(nam.cookieJar(), cookies.RAMCookieJar)
|
||||
assert nam.cache() is None
|
||||
|
@ -43,24 +43,20 @@ def preload_cache(cache, url='http://www.example.com/', content=b'foobar'):
|
||||
def test_cache_config_change_cache_size(config_stub, tmpdir):
|
||||
"""Change cache size and emit signal to trigger on_config_changed."""
|
||||
max_cache_size = 1024
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': max_cache_size},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
config_stub.val.content.cache.size = max_cache_size
|
||||
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
assert disk_cache.maximumCacheSize() == max_cache_size
|
||||
|
||||
config_stub.set('storage', 'cache-size', max_cache_size * 2)
|
||||
config_stub.val.content.cache.size = max_cache_size * 2
|
||||
assert disk_cache.maximumCacheSize() == max_cache_size * 2
|
||||
|
||||
|
||||
def test_cache_size_leq_max_cache_size(config_stub, tmpdir):
|
||||
"""Test cacheSize <= MaximumCacheSize when cache is activated."""
|
||||
limit = 100
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': limit},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
config_stub.val.content.cache.size = limit
|
||||
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
assert disk_cache.maximumCacheSize() == limit
|
||||
|
||||
@ -75,10 +71,6 @@ def test_cache_size_leq_max_cache_size(config_stub, tmpdir):
|
||||
|
||||
def test_cache_existing_metadata_file(config_stub, tmpdir):
|
||||
"""Test querying existing meta data file from activated cache."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
url = 'http://qutebrowser.org'
|
||||
content = b'foobar'
|
||||
|
||||
@ -100,11 +92,6 @@ def test_cache_existing_metadata_file(config_stub, tmpdir):
|
||||
|
||||
def test_cache_nonexistent_metadata_file(config_stub, tmpdir):
|
||||
"""Test querying nonexistent meta data file from activated cache."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
cache_file = disk_cache.fileMetaData("nosuchfile")
|
||||
assert not cache_file.isValid()
|
||||
@ -112,10 +99,6 @@ def test_cache_nonexistent_metadata_file(config_stub, tmpdir):
|
||||
|
||||
def test_cache_get_nonexistent_data(config_stub, tmpdir):
|
||||
"""Test querying some data that was never inserted."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
preload_cache(disk_cache, 'https://qutebrowser.org')
|
||||
|
||||
@ -124,10 +107,6 @@ def test_cache_get_nonexistent_data(config_stub, tmpdir):
|
||||
|
||||
def test_cache_insert_data(config_stub, tmpdir):
|
||||
"""Test if entries inserted into the cache are actually there."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
url = 'http://qutebrowser.org'
|
||||
content = b'foobar'
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
@ -141,10 +120,6 @@ def test_cache_insert_data(config_stub, tmpdir):
|
||||
|
||||
def test_cache_remove_data(config_stub, tmpdir):
|
||||
"""Test if a previously inserted entry can be removed from the cache."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
url = 'http://qutebrowser.org'
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
preload_cache(disk_cache, url)
|
||||
@ -156,10 +131,6 @@ def test_cache_remove_data(config_stub, tmpdir):
|
||||
|
||||
def test_cache_clear_activated(config_stub, tmpdir):
|
||||
"""Test if cache is empty after clearing it."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
assert disk_cache.cacheSize() == 0
|
||||
|
||||
@ -172,10 +143,6 @@ def test_cache_clear_activated(config_stub, tmpdir):
|
||||
|
||||
def test_cache_metadata(config_stub, tmpdir):
|
||||
"""Ensure that DiskCache.metaData() returns exactly what was inserted."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
url = 'http://qutebrowser.org'
|
||||
metadata = QNetworkCacheMetaData()
|
||||
metadata.setUrl(QUrl(url))
|
||||
@ -190,10 +157,6 @@ def test_cache_metadata(config_stub, tmpdir):
|
||||
|
||||
def test_cache_update_metadata(config_stub, tmpdir):
|
||||
"""Test updating the meta data for an existing cache entry."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
url = 'http://qutebrowser.org'
|
||||
disk_cache = cache.DiskCache(str(tmpdir))
|
||||
preload_cache(disk_cache, url, b'foo')
|
||||
@ -208,10 +171,6 @@ def test_cache_update_metadata(config_stub, tmpdir):
|
||||
|
||||
def test_cache_full(config_stub, tmpdir):
|
||||
"""Do a sanity test involving everything."""
|
||||
config_stub.data = {
|
||||
'storage': {'cache-size': 1024},
|
||||
'general': {'private-browsing': False}
|
||||
}
|
||||
disk_cache = QNetworkDiskCache()
|
||||
disk_cache.setCacheDirectory(str(tmpdir))
|
||||
|
||||
|
@ -26,10 +26,6 @@ from qutebrowser.misc import lineparser
|
||||
|
||||
pytestmark = pytest.mark.usefixtures('data_tmpdir')
|
||||
|
||||
CONFIG_ALL_COOKIES = {'content': {'cookies-accept': 'all'}}
|
||||
CONFIG_NEVER_COOKIES = {'content': {'cookies-accept': 'never'}}
|
||||
CONFIG_COOKIES_ENABLED = {'content': {'cookies-store': True}}
|
||||
|
||||
|
||||
COOKIE1 = b'foo1=bar; expires=Tue, 01-Jan-2036 08:00:01 GMT'
|
||||
COOKIE2 = b'foo2=bar; expires=Tue, 01-Jan-2036 08:00:01 GMT'
|
||||
@ -66,7 +62,8 @@ class LineparserSaveStub(lineparser.BaseLineParser):
|
||||
|
||||
def test_set_cookies_accept(config_stub, qtbot, monkeypatch):
|
||||
"""Test setCookiesFromUrl with cookies enabled."""
|
||||
config_stub.data = CONFIG_ALL_COOKIES
|
||||
config_stub.val.content.cookies.accept = 'all'
|
||||
|
||||
ram_jar = cookies.RAMCookieJar()
|
||||
cookie = QNetworkCookie(b'foo', b'bar')
|
||||
url = QUrl('http://example.com/')
|
||||
@ -83,13 +80,13 @@ def test_set_cookies_accept(config_stub, qtbot, monkeypatch):
|
||||
|
||||
def test_set_cookies_never_accept(qtbot, config_stub):
|
||||
"""Test setCookiesFromUrl when cookies are not accepted."""
|
||||
config_stub.data = CONFIG_NEVER_COOKIES
|
||||
ram_jar = cookies.RAMCookieJar()
|
||||
config_stub.val.content.cookies.accept = 'never'
|
||||
|
||||
ram_jar = cookies.RAMCookieJar()
|
||||
url = QUrl('http://example.com/')
|
||||
|
||||
with qtbot.assertNotEmitted(ram_jar.changed):
|
||||
assert not ram_jar.setCookiesFromUrl(url, 'test')
|
||||
assert not ram_jar.setCookiesFromUrl('test', url)
|
||||
assert not ram_jar.cookiesForUrl(url)
|
||||
|
||||
|
||||
@ -136,24 +133,22 @@ def test_save(config_stub, fake_save_manager, monkeypatch, qapp):
|
||||
def test_cookies_changed_emit(config_stub, fake_save_manager,
|
||||
monkeypatch, qtbot):
|
||||
"""Test that self.changed is emitted."""
|
||||
config_stub.data = CONFIG_COOKIES_ENABLED
|
||||
monkeypatch.setattr(lineparser, 'LineParser', LineparserSaveStub)
|
||||
jar = cookies.CookieJar()
|
||||
|
||||
with qtbot.waitSignal(jar.changed):
|
||||
config_stub.set('content', 'cookies-store', False)
|
||||
config_stub.val.content.cookies.store = False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('store_cookies,empty', [(True, False), (False, True)])
|
||||
def test_cookies_changed(config_stub, fake_save_manager, monkeypatch, qtbot,
|
||||
store_cookies, empty):
|
||||
"""Test that cookies are saved correctly."""
|
||||
config_stub.data = CONFIG_COOKIES_ENABLED
|
||||
monkeypatch.setattr(lineparser, 'LineParser', LineparserSaveStub)
|
||||
jar = cookies.CookieJar()
|
||||
jar._lineparser.data = [COOKIE1, COOKIE2]
|
||||
jar.parse_cookies()
|
||||
config_stub.set('content', 'cookies-store', store_cookies)
|
||||
config_stub.val.content.cookies.store = store_cookies
|
||||
|
||||
if empty:
|
||||
assert not jar._lineparser.data
|
||||
|
@ -24,7 +24,6 @@ from qutebrowser.browser import downloads, qtnetworkdownloads
|
||||
|
||||
def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache):
|
||||
"""Simple check for download model internals."""
|
||||
config_stub.data = {'general': {'private-browsing': False}}
|
||||
manager = qtnetworkdownloads.DownloadManager(win_id=0)
|
||||
model = downloads.DownloadModel(manager)
|
||||
qtmodeltester.check(model)
|
||||
|
@ -652,15 +652,7 @@ class TestIsVisibleIframe:
|
||||
|
||||
class TestRectOnView:
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def stubbed_config(self, config_stub, monkeypatch):
|
||||
"""Add a zoom-text-only fake config value.
|
||||
|
||||
This is needed for all the tests calling rect_on_view or is_visible.
|
||||
"""
|
||||
config_stub.data = {'ui': {'zoom-text-only': 'true'}}
|
||||
monkeypatch.setattr(webkitelem, 'config', config_stub)
|
||||
return config_stub
|
||||
pytestmark = pytest.mark.usefixtures('config_stub')
|
||||
|
||||
@pytest.mark.parametrize('js_rect', [
|
||||
None, # real geometry via getElementRects
|
||||
@ -719,7 +711,7 @@ class TestRectOnView:
|
||||
@pytest.mark.parametrize('zoom_text_only', [True, False])
|
||||
def test_zoomed(self, stubs, config_stub, js_rect, zoom_text_only):
|
||||
"""Make sure the coordinates are adjusted when zoomed."""
|
||||
config_stub.data = {'ui': {'zoom-text-only': zoom_text_only}}
|
||||
config_stub.val.zoom.text_only = zoom_text_only
|
||||
geometry = QRect(10, 10, 4, 4)
|
||||
frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100), zoom=0.5)
|
||||
elem = get_webelem(geometry, frame, js_rect_return=js_rect,
|
||||
@ -782,13 +774,6 @@ class TestIsEditable:
|
||||
|
||||
"""Tests for is_editable."""
|
||||
|
||||
@pytest.fixture
|
||||
def stubbed_config(self, config_stub, monkeypatch):
|
||||
"""Fixture to create a config stub with an input section."""
|
||||
config_stub.data = {'input': {}}
|
||||
monkeypatch.setattr(webkitelem, 'config', config_stub)
|
||||
return config_stub
|
||||
|
||||
@pytest.mark.parametrize('tagname, attributes, editable', [
|
||||
('input', {}, True),
|
||||
('input', {'type': 'text'}, True),
|
||||
@ -849,9 +834,9 @@ class TestIsEditable:
|
||||
(True, 'object', {}, False),
|
||||
(True, 'object', {'type': 'image/gif'}, False),
|
||||
])
|
||||
def test_is_editable_plugin(self, stubbed_config, setting, tagname,
|
||||
attributes, editable):
|
||||
stubbed_config.data['input']['insert-mode-on-plugins'] = setting
|
||||
def test_is_editable_plugin(self, config_stub,
|
||||
setting, tagname, attributes, editable):
|
||||
config_stub.val.input.insert_mode.plugins = setting
|
||||
elem = get_webelem(tagname=tagname, attributes=attributes)
|
||||
assert elem.is_editable() == editable
|
||||
|
||||
|
@ -127,7 +127,7 @@ class TestRegister:
|
||||
pass
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
@cmdutils.register(name=['foobar'])
|
||||
@cmdutils.register(name='foobar')
|
||||
def fun2():
|
||||
"""Blah."""
|
||||
pass
|
||||
|
@ -22,6 +22,7 @@
|
||||
import pytest
|
||||
|
||||
from qutebrowser.commands import runners, cmdexc
|
||||
from qutebrowser.config import configtypes
|
||||
|
||||
|
||||
class TestCommandParser:
|
||||
@ -41,8 +42,12 @@ class TestCommandParser:
|
||||
with pytest.raises(cmdexc.NoSuchCommandError):
|
||||
parser.parse_all(cmdline_test.cmd, aliases=False)
|
||||
|
||||
def test_parse_all_with_alias(self, cmdline_test, config_stub):
|
||||
config_stub.data = {'aliases': {'alias_name': cmdline_test.cmd}}
|
||||
def test_parse_all_with_alias(self, cmdline_test, monkeypatch, config_stub):
|
||||
if not cmdline_test.cmd:
|
||||
pytest.skip("Empty command")
|
||||
|
||||
monkeypatch.setattr(configtypes.Command, 'unvalidated', True)
|
||||
config_stub.val.aliases = {'alias_name': cmdline_test.cmd}
|
||||
|
||||
parser = runners.CommandParser()
|
||||
if cmdline_test.valid:
|
||||
|
@ -32,36 +32,6 @@ from qutebrowser.completion.models import base, sortfilter
|
||||
def completionview(qtbot, status_command_stub, config_stub, win_registry,
|
||||
mocker):
|
||||
"""Create the CompletionView used for testing."""
|
||||
config_stub.data = {
|
||||
'completion': {
|
||||
'show': 'always',
|
||||
'scrollbar-width': 12,
|
||||
'scrollbar-padding': 2,
|
||||
'shrink': False,
|
||||
'quick-complete': False,
|
||||
'height': '50%',
|
||||
},
|
||||
'colors': {
|
||||
'completion.fg': QColor(),
|
||||
'completion.bg': QColor(),
|
||||
'completion.alternate-bg': QColor(),
|
||||
'completion.category.fg': QColor(),
|
||||
'completion.category.bg': QColor(),
|
||||
'completion.category.border.top': QColor(),
|
||||
'completion.category.border.bottom': QColor(),
|
||||
'completion.item.selected.fg': QColor(),
|
||||
'completion.item.selected.bg': QColor(),
|
||||
'completion.item.selected.border.top': QColor(),
|
||||
'completion.item.selected.border.bottom': QColor(),
|
||||
'completion.match.fg': QColor(),
|
||||
'completion.scrollbar.fg': QColor(),
|
||||
'completion.scrollbar.bg': QColor(),
|
||||
},
|
||||
'fonts': {
|
||||
'completion': 'Comic Sans Monospace',
|
||||
'completion.category': 'Comic Sans Monospace bold',
|
||||
}
|
||||
}
|
||||
# mock the Completer that the widget creates in its constructor
|
||||
mocker.patch('qutebrowser.completion.completer.Completer', autospec=True)
|
||||
view = completionwidget.CompletionView(win_id=0)
|
||||
@ -92,7 +62,7 @@ def test_maybe_update_geometry(completionview, config_stub, qtbot):
|
||||
"""Ensure completion is resized only if shrink is True."""
|
||||
with qtbot.assertNotEmitted(completionview.update_geometry):
|
||||
completionview._maybe_update_geometry()
|
||||
config_stub.data['completion']['shrink'] = True
|
||||
config_stub.val.completion.shrink = True
|
||||
with qtbot.waitSignal(completionview.update_geometry):
|
||||
completionview._maybe_update_geometry()
|
||||
|
||||
@ -197,8 +167,8 @@ def test_completion_show(show, rows, quick_complete, completionview,
|
||||
rows: Each entry represents a completion category with only one item.
|
||||
quick_complete: The completion quick-complete config setting.
|
||||
"""
|
||||
config_stub.data['completion']['show'] = show
|
||||
config_stub.data['completion']['quick-complete'] = quick_complete
|
||||
config_stub.val.completion.show = show
|
||||
config_stub.val.completion.quick = quick_complete
|
||||
|
||||
model = base.BaseCompletionModel()
|
||||
for name in rows:
|
||||
|
@ -27,14 +27,8 @@ from qutebrowser.utils import usertypes
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def progress_widget(qtbot, monkeypatch, config_stub):
|
||||
def progress_widget(qtbot, config_stub):
|
||||
"""Create a Progress widget and checks its initial state."""
|
||||
config_stub.data = {
|
||||
'colors': {'statusbar.progress.bg': 'black'},
|
||||
'fonts': {},
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.mainwindow.statusbar.progress.style.config', config_stub)
|
||||
widget = Progress()
|
||||
qtbot.add_widget(widget)
|
||||
assert not widget.isVisible()
|
||||
|
@ -32,20 +32,6 @@ from helpers import utils
|
||||
@pytest.fixture
|
||||
def url_widget(qtbot, monkeypatch, config_stub):
|
||||
"""Fixture providing a Url widget."""
|
||||
config_stub.data = {
|
||||
'colors': {
|
||||
'statusbar.url.bg': 'white',
|
||||
'statusbar.url.fg': 'black',
|
||||
'statusbar.url.fg.success': 'yellow',
|
||||
'statusbar.url.fg.success.https': 'green',
|
||||
'statusbar.url.fg.error': 'red',
|
||||
'statusbar.url.fg.warn': 'orange',
|
||||
'statusbar.url.fg.hover': 'blue'
|
||||
},
|
||||
'fonts': {},
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.mainwindow.statusbar.url.style.config', config_stub)
|
||||
widget = url.UrlText()
|
||||
qtbot.add_widget(widget)
|
||||
assert not widget.isVisible()
|
||||
|
@ -26,27 +26,7 @@ from qutebrowser.utils import usertypes
|
||||
|
||||
@pytest.fixture
|
||||
def view(qtbot, config_stub):
|
||||
config_stub.data = {
|
||||
'colors': {
|
||||
'messages.fg.error': 'white',
|
||||
'messages.bg.error': 'red',
|
||||
'messages.border.error': '#bb0000',
|
||||
'messages.fg.warning': 'white',
|
||||
'messages.bg.warning': 'darkorange',
|
||||
'messages.border.warning': '#d47300',
|
||||
'messages.fg.info': 'white',
|
||||
'messages.bg.info': 'black',
|
||||
'messages.border.info': '#333333',
|
||||
},
|
||||
'fonts': {
|
||||
'messages.error': '8pt Monospace',
|
||||
'messages.warning': '8pt Monospace',
|
||||
'messages.info': '8pt Monospace',
|
||||
},
|
||||
'ui': {
|
||||
'message-timeout': 100,
|
||||
}
|
||||
}
|
||||
config_stub.val.messages.timeout = 100
|
||||
mv = messageview.MessageView()
|
||||
qtbot.add_widget(mv)
|
||||
return mv
|
||||
@ -98,10 +78,10 @@ def test_show_message_twice_after_first_disappears(qtbot, view):
|
||||
|
||||
def test_changing_timer_with_messages_shown(qtbot, view, config_stub):
|
||||
"""When we change messages.timeout, the timer should be restarted."""
|
||||
config_stub['ui']['message-timeout'] = 900000 # 15s
|
||||
config_stub.val.messages.timeout = 900000 # 15s
|
||||
view.show_message(usertypes.MessageLevel.info, 'test')
|
||||
with qtbot.waitSignal(view._clear_timer.timeout):
|
||||
config_stub.set('ui', 'message-timeout', 100)
|
||||
config_stub.set_obj('messages.timeout', 100)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('replace1, replace2, length', [
|
||||
|
@ -26,16 +26,12 @@ from qutebrowser.mainwindow import prompt as promptmod
|
||||
from qutebrowser.utils import usertypes
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(qapp, key_config_stub):
|
||||
key_config_stub.set_bindings_for('prompt', {})
|
||||
|
||||
|
||||
class TestFileCompletion:
|
||||
|
||||
@pytest.fixture
|
||||
def get_prompt(self, qtbot, config_stub):
|
||||
def get_prompt(self, qtbot, config_stub, key_config_stub):
|
||||
"""Get a function to display a prompt with a path."""
|
||||
config_stub.val.bindings.default = {}
|
||||
def _get_prompt_func(path):
|
||||
question = usertypes.Question()
|
||||
question.title = "test"
|
||||
@ -48,7 +44,6 @@ class TestFileCompletion:
|
||||
assert prompt._lineedit.text() == path
|
||||
|
||||
return prompt
|
||||
config_stub.data = {'ui': {'prompt-filebrowser': 'true'}}
|
||||
return _get_prompt_func
|
||||
|
||||
@pytest.mark.parametrize('steps, where, subfolder', [
|
||||
|
@ -33,36 +33,8 @@ class TestTabWidget:
|
||||
|
||||
"""Tests for TabWidget."""
|
||||
|
||||
CONFIG = {
|
||||
'fonts': {
|
||||
'tabbar': QFont(),
|
||||
},
|
||||
'tabs': {
|
||||
'show-switching-delay': 800,
|
||||
'movable': True,
|
||||
'position': 0,
|
||||
'select-on-remove': 1,
|
||||
'show': 'always',
|
||||
'show-favicons': True,
|
||||
'favicon-scale': 1.0,
|
||||
'padding': configtypes.PaddingValues(0, 0, 5, 5),
|
||||
'indicator-width': 3,
|
||||
'indicator-padding': configtypes.PaddingValues(2, 2, 0, 4),
|
||||
'title-format': '{index}: {title}',
|
||||
'title-format-pinned': '{index}',
|
||||
'pinned-width': 43,
|
||||
'title-alignment': Qt.AlignLeft,
|
||||
},
|
||||
'colors': {
|
||||
'tabs.bg.bar': QColor(),
|
||||
'tabs.bg.selected.even': QColor(),
|
||||
'tabs.fg.selected.even': QColor(),
|
||||
}
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def widget(self, qtbot, monkeypatch, config_stub):
|
||||
config_stub.data = self.CONFIG
|
||||
w = tabwidget.TabWidget(0)
|
||||
qtbot.addWidget(w)
|
||||
monkeypatch.setattr(tabwidget.objects, 'backend',
|
||||
|
@ -27,9 +27,6 @@ from qutebrowser.misc import cmdhistory
|
||||
|
||||
HISTORY = ['first', 'second', 'third', 'fourth', 'fifth']
|
||||
|
||||
CONFIG_NOT_PRIVATE = {'general': {'private-browsing': False}}
|
||||
CONFIG_PRIVATE = {'general': {'private-browsing': True}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hist():
|
||||
@ -146,34 +143,27 @@ def test_previtem_index_error(hist):
|
||||
def test_append_private_mode(hist, config_stub):
|
||||
"""Test append in private mode."""
|
||||
hist._private = True
|
||||
# We want private_browsing set to True
|
||||
config_stub.data = CONFIG_PRIVATE
|
||||
config_stub.val.content.private_browsing = True
|
||||
hist.append('new item')
|
||||
assert hist.history == HISTORY
|
||||
|
||||
|
||||
def test_append(hist, config_stub):
|
||||
def test_append(hist):
|
||||
"""Test append outside private mode."""
|
||||
# Private mode is disabled (private_browsing is set to False)
|
||||
config_stub.data = CONFIG_NOT_PRIVATE
|
||||
hist.append('new item')
|
||||
assert 'new item' in hist.history
|
||||
hist.history.remove('new item')
|
||||
assert hist.history == HISTORY
|
||||
|
||||
|
||||
def test_append_empty_history(hist, config_stub):
|
||||
def test_append_empty_history(hist):
|
||||
"""Test append when .history is empty."""
|
||||
# Disable private mode
|
||||
config_stub.data = CONFIG_NOT_PRIVATE
|
||||
hist.history = []
|
||||
hist.append('item')
|
||||
assert hist[0] == 'item'
|
||||
|
||||
|
||||
def test_append_double(hist, config_stub):
|
||||
# Disable private mode
|
||||
config_stub.data = CONFIG_NOT_PRIVATE
|
||||
def test_append_double(hist):
|
||||
hist.append('fifth')
|
||||
# assert that the new 'fifth' is not added
|
||||
assert hist.history[-2:] == ['fourth', 'fifth']
|
||||
|
@ -35,11 +35,6 @@ from qutebrowser.utils import usertypes
|
||||
def patch_things(config_stub, monkeypatch, stubs):
|
||||
monkeypatch.setattr(editormod.guiprocess, 'QProcess',
|
||||
stubs.fake_qprocess())
|
||||
config_stub.data = {
|
||||
'general': {'editor': [''], 'editor-encoding': 'utf-8'},
|
||||
'input': {},
|
||||
}
|
||||
monkeypatch.setattr(editormod, 'config', config_stub)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -59,23 +54,16 @@ class TestArg:
|
||||
editor: The ExternalEditor instance to test.
|
||||
"""
|
||||
|
||||
@pytest.mark.parametrize('args', [[], ['foo'], ['foo', 'bar']])
|
||||
def test_start_no_placeholder(self, config_stub, editor, args):
|
||||
"""Test starting editor without arguments."""
|
||||
config_stub.data['general']['editor'] = ['bin'] + args
|
||||
editor.edit("")
|
||||
editor._proc._proc.start.assert_called_with("bin", args)
|
||||
|
||||
def test_placeholder(self, config_stub, editor):
|
||||
"""Test starting editor with placeholder argument."""
|
||||
config_stub.data['general']['editor'] = ['bin', 'foo', '{}', 'bar']
|
||||
config_stub.val.editor.command = ['bin', 'foo', '{}', 'bar']
|
||||
editor.edit("")
|
||||
editor._proc._proc.start.assert_called_with(
|
||||
"bin", ["foo", editor._file.name, "bar"])
|
||||
|
||||
def test_placeholder_inline(self, config_stub, editor):
|
||||
"""Test starting editor with placeholder arg inside of another arg."""
|
||||
config_stub.data['general']['editor'] = ['bin', 'foo{}', 'bar']
|
||||
config_stub.val.editor.command = ['bin', 'foo{}', 'bar']
|
||||
editor.edit("")
|
||||
editor._proc._proc.start.assert_called_with(
|
||||
"bin", ["foo" + editor._file.name, "bar"])
|
||||
|
@ -111,14 +111,14 @@ class TestFullscreenNotification:
|
||||
({'a': 'fullscreen --leave'}, "Press a to exit fullscreen."),
|
||||
({}, "Page is now fullscreen."),
|
||||
])
|
||||
def test_text(self, qtbot, key_config_stub, bindings, text):
|
||||
key_config_stub.set_bindings_for('normal', bindings)
|
||||
def test_text(self, qtbot, config_stub, key_config_stub, bindings, text):
|
||||
config_stub.val.bindings.default = {}
|
||||
config_stub.val.bindings.commands = {'normal': bindings}
|
||||
w = miscwidgets.FullscreenNotification()
|
||||
qtbot.add_widget(w)
|
||||
assert w.text() == text
|
||||
|
||||
def test_timeout(self, qtbot, key_config_stub):
|
||||
key_config_stub.set_bindings_for('normal', {})
|
||||
w = miscwidgets.FullscreenNotification()
|
||||
qtbot.add_widget(w)
|
||||
with qtbot.waitSignal(w.destroyed):
|
||||
|
@ -178,7 +178,7 @@ class TestSaveAll:
|
||||
])
|
||||
def test_get_session_name(config_stub, sess_man, arg, config, current,
|
||||
expected):
|
||||
config_stub.data = {'general': {'session-default-name': config}}
|
||||
config_stub.val.session_default_name = config
|
||||
sess_man._current = current
|
||||
assert sess_man._get_session_name(arg) == expected
|
||||
|
||||
|
@ -90,23 +90,12 @@ def fake_dns(monkeypatch):
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def urlutils_config_stub(config_stub, monkeypatch):
|
||||
"""Initialize the given config_stub.
|
||||
|
||||
Args:
|
||||
stub: The ConfigStub provided by the config_stub fixture.
|
||||
auto_search: The value auto-search should have.
|
||||
"""
|
||||
config_stub.data = {
|
||||
'general': {'auto-search': True},
|
||||
'searchengines': {
|
||||
'test': 'http://www.qutebrowser.org/?q={}',
|
||||
'test-with-dash': 'http://www.example.org/?q={}',
|
||||
'DEFAULT': 'http://www.example.com/?q={}',
|
||||
},
|
||||
def init_config(config_stub):
|
||||
config_stub.val.url.searchengines = {
|
||||
'test': 'http://www.qutebrowser.org/?q={}',
|
||||
'test-with-dash': 'http://www.example.org/?q={}',
|
||||
'DEFAULT': 'http://www.example.com/?q={}',
|
||||
}
|
||||
monkeypatch.setattr(urlutils, 'config', config_stub)
|
||||
return config_stub
|
||||
|
||||
|
||||
class TestFuzzyUrl:
|
||||
@ -284,7 +273,7 @@ def test_special_urls(url, special):
|
||||
('stripped ', 'www.example.com', 'q=stripped'),
|
||||
('test-with-dash testfoo', 'www.example.org', 'q=testfoo'),
|
||||
])
|
||||
def test_get_search_url(urlutils_config_stub, url, host, query):
|
||||
def test_get_search_url(url, host, query):
|
||||
"""Test _get_search_url().
|
||||
|
||||
Args:
|
||||
@ -298,7 +287,7 @@ def test_get_search_url(urlutils_config_stub, url, host, query):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('url', ['\n', ' ', '\n '])
|
||||
def test_get_search_url_invalid(urlutils_config_stub, url):
|
||||
def test_get_search_url_invalid(url):
|
||||
with pytest.raises(ValueError):
|
||||
urlutils._get_search_url(url)
|
||||
|
||||
@ -348,8 +337,8 @@ def test_get_search_url_invalid(urlutils_config_stub, url):
|
||||
(False, True, False, 'This is a URL without autosearch'),
|
||||
])
|
||||
@pytest.mark.parametrize('auto_search', ['dns', 'naive', 'never'])
|
||||
def test_is_url(urlutils_config_stub, fake_dns, is_url, is_url_no_autosearch,
|
||||
uses_dns, url, auto_search):
|
||||
def test_is_url(config_stub, fake_dns,
|
||||
is_url, is_url_no_autosearch, uses_dns, url, auto_search):
|
||||
"""Test is_url().
|
||||
|
||||
Args:
|
||||
@ -366,7 +355,7 @@ def test_is_url(urlutils_config_stub, fake_dns, is_url, is_url_no_autosearch,
|
||||
qtutils.version_check('5.6.1')):
|
||||
pytest.xfail("Qt behavior changed")
|
||||
|
||||
urlutils_config_stub.data['general']['auto-search'] = auto_search
|
||||
config_stub.val.url.auto_search = auto_search
|
||||
if auto_search == 'dns':
|
||||
if uses_dns:
|
||||
fake_dns.answer = True
|
||||
|
@ -346,12 +346,12 @@ class TestKeyEventToString:
|
||||
def test_only_key(self, fake_keyevent_factory):
|
||||
"""Test with a simple key pressed."""
|
||||
evt = fake_keyevent_factory(key=Qt.Key_A)
|
||||
assert utils.keyevent_to_string(evt) == 'A'
|
||||
assert utils.keyevent_to_string(evt) == 'a'
|
||||
|
||||
def test_key_and_modifier(self, fake_keyevent_factory):
|
||||
"""Test with key and modifier pressed."""
|
||||
evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
|
||||
expected = 'Meta+A' if sys.platform == 'darwin' else 'Ctrl+A'
|
||||
expected = 'meta+a' if sys.platform == 'darwin' else 'ctrl+a'
|
||||
assert utils.keyevent_to_string(evt) == expected
|
||||
|
||||
def test_key_and_modifiers(self, fake_keyevent_factory):
|
||||
@ -359,13 +359,13 @@ class TestKeyEventToString:
|
||||
evt = fake_keyevent_factory(
|
||||
key=Qt.Key_A, modifiers=(Qt.ControlModifier | Qt.AltModifier |
|
||||
Qt.MetaModifier | Qt.ShiftModifier))
|
||||
assert utils.keyevent_to_string(evt) == 'Ctrl+Alt+Meta+Shift+A'
|
||||
assert utils.keyevent_to_string(evt) == 'ctrl+alt+meta+shift+a'
|
||||
|
||||
def test_mac(self, monkeypatch, fake_keyevent_factory):
|
||||
"""Test with a simulated mac."""
|
||||
monkeypatch.setattr(sys, 'platform', 'darwin')
|
||||
evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
|
||||
assert utils.keyevent_to_string(evt) == 'Meta+A'
|
||||
assert utils.keyevent_to_string(evt) == 'meta+a'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('keystr, expected', [
|
||||
@ -886,7 +886,6 @@ class TestOpenFile:
|
||||
|
||||
@pytest.mark.not_frozen
|
||||
def test_cmdline_without_argument(self, caplog, config_stub):
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
executable = shlex.quote(sys.executable)
|
||||
cmdline = '{} -c pass'.format(executable)
|
||||
utils.open_file('/foo/bar', cmdline)
|
||||
@ -896,7 +895,6 @@ class TestOpenFile:
|
||||
|
||||
@pytest.mark.not_frozen
|
||||
def test_cmdline_with_argument(self, caplog, config_stub):
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
executable = shlex.quote(sys.executable)
|
||||
cmdline = '{} -c pass {{}} raboof'.format(executable)
|
||||
utils.open_file('/foo/bar', cmdline)
|
||||
@ -908,14 +906,13 @@ class TestOpenFile:
|
||||
def test_setting_override(self, caplog, config_stub):
|
||||
executable = shlex.quote(sys.executable)
|
||||
cmdline = '{} -c pass'.format(executable)
|
||||
config_stub.data = {'general': {'default-open-dispatcher': cmdline}}
|
||||
config_stub.val.downloads.open_dispatcher = cmdline
|
||||
utils.open_file('/foo/bar')
|
||||
result = caplog.records[0].message
|
||||
result = caplog.records[1].message
|
||||
assert re.match(
|
||||
r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
|
||||
|
||||
def test_system_default_application(self, caplog, config_stub, mocker):
|
||||
config_stub.data = {'general': {'default-open-dispatcher': ''}}
|
||||
m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={},
|
||||
new_callable=mocker.Mock)
|
||||
utils.open_file('/foo/bar')
|
||||
|
Loading…
Reference in New Issue
Block a user