Update test_stylesheet

This commit is contained in:
Florian Bruhin 2017-07-02 15:21:25 +02:00
parent a5c8a52dd5
commit 81d6406e14
2 changed files with 14 additions and 30 deletions

View File

@ -30,7 +30,7 @@ from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
from PyQt5.QtWidgets import QCommonStyle, QLineEdit, QWidget, QTabBar
from qutebrowser.browser import browsertab, history
from qutebrowser.config import configexc
from qutebrowser.config import configexc, configdata
from qutebrowser.utils import usertypes, utils
from qutebrowser.mainwindow import mainwindow
@ -425,6 +425,8 @@ class ConfigStub(QObject):
def __init__(self, parent=None):
super().__init__(parent)
if configdata.DATA is None:
configdata.init()
self.data = {}
self.val = None

View File

@ -22,30 +22,14 @@ import logging
import pytest
from PyQt5.QtCore import QObject
from PyQt5.QtGui import QColor
from qutebrowser.config import style
@pytest.mark.parametrize('template, expected', [
("{{ color['completion.bg'] }}", "black"),
("{{ color['completion.fg'] }}", "red"),
("{{ font['completion'] }}", "foo"),
("{{ config.get('foo', 'bar') }}", "baz"),
])
def test_get_stylesheet(config_stub, template, expected):
config_stub.data = {
'colors': {
'completion.bg': 'black',
'completion.fg': 'red',
},
'fonts': {
'completion': 'foo',
},
'foo': {'bar': 'baz'},
}
rendered = style.get_stylesheet(template)
assert rendered == expected
def test_get_stylesheet(config_stub):
config_stub.val.colors.completion.bg = 'magenta'
rendered = style.get_stylesheet("{{ conf.colors.completion.bg }}")
assert rendered == 'magenta'
class Obj(QObject):
@ -61,27 +45,25 @@ class Obj(QObject):
@pytest.mark.parametrize('delete', [True, False])
def test_set_register_stylesheet(delete, qtbot, config_stub, caplog):
config_stub.data = {'fonts': {'foo': 'bar'}, 'colors': {}}
obj = Obj("{{ font['foo'] }}")
config_stub.val.colors.completion.fg = 'magenta'
obj = Obj("{{ conf.colors.completion.fg }}")
with caplog.at_level(9): # VDEBUG
style.set_register_stylesheet(obj)
assert len(caplog.records) == 1
assert caplog.records[0].message == 'stylesheet for Obj: bar'
assert caplog.records[0].message == 'stylesheet for Obj: magenta'
assert obj.rendered_stylesheet == 'bar'
assert obj.rendered_stylesheet == 'magenta'
if delete:
with qtbot.waitSignal(obj.destroyed):
obj.deleteLater()
config_stub.data = {'fonts': {'foo': 'baz'}, 'colors': {}}
style.get_stylesheet.cache_clear()
config_stub.changed.emit('fonts', 'foo')
config_stub.val.colors.completion.fg = 'yellow'
if delete:
expected = 'bar'
expected = 'magenta'
else:
expected = 'baz'
expected = 'yellow'
assert obj.rendered_stylesheet == expected