From 81d6406e14a1c5aa26dab632a8424b2af452710c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 2 Jul 2017 15:21:25 +0200 Subject: [PATCH] Update test_stylesheet --- tests/helpers/stubs.py | 4 +++- tests/unit/config/test_style.py | 40 +++++++++------------------------ 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index cb9e55607..b8f9698ec 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -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 diff --git a/tests/unit/config/test_style.py b/tests/unit/config/test_style.py index 36c811b65..caa444ae9 100644 --- a/tests/unit/config/test_style.py +++ b/tests/unit/config/test_style.py @@ -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