Add more config tests
This commit is contained in:
parent
d511c5436d
commit
05017c83d6
@ -23,12 +23,12 @@ import types
|
|||||||
import unittest.mock
|
import unittest.mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from PyQt5.QtCore import QObject
|
from PyQt5.QtCore import QObject, QUrl
|
||||||
from PyQt5.QtGui import QColor
|
from PyQt5.QtGui import QColor
|
||||||
|
|
||||||
from qutebrowser.config import (config, configdata, configexc, configfiles,
|
from qutebrowser.config import (config, configdata, configexc, configfiles,
|
||||||
configutils)
|
configutils)
|
||||||
from qutebrowser.utils import usertypes
|
from qutebrowser.utils import usertypes, urlmatch
|
||||||
from qutebrowser.misc import objects
|
from qutebrowser.misc import objects
|
||||||
|
|
||||||
|
|
||||||
@ -410,6 +410,14 @@ class TestConfig:
|
|||||||
"""Test conf.get() with a QColor (where get/get_obj is different)."""
|
"""Test conf.get() with a QColor (where get/get_obj is different)."""
|
||||||
assert conf.get('colors.completion.category.fg') == QColor('white')
|
assert conf.get('colors.completion.category.fg') == QColor('white')
|
||||||
|
|
||||||
|
def test_get_for_url(self, conf):
|
||||||
|
"""Test conf.get() with an URL/pattern."""
|
||||||
|
pattern = urlmatch.UrlPattern('*://example.com')
|
||||||
|
name = 'content.javascript.enabled'
|
||||||
|
conf.set_obj(name, False, pattern=pattern)
|
||||||
|
assert conf.get(name, url=QUrl('https://example.com/')) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('value', [{}, {'normal': {'a': 'nop'}}])
|
@pytest.mark.parametrize('value', [{}, {'normal': {'a': 'nop'}}])
|
||||||
def test_get_bindings(self, config_stub, conf, value):
|
def test_get_bindings(self, config_stub, conf, value):
|
||||||
"""Test conf.get() with bindings which have missing keys."""
|
"""Test conf.get() with bindings which have missing keys."""
|
||||||
@ -514,6 +522,30 @@ class TestConfig:
|
|||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
conf._maybe_copy(set())
|
conf._maybe_copy(set())
|
||||||
|
|
||||||
|
def test_copy_non_mutable(self, conf, mocker):
|
||||||
|
"""Make sure no copies are done for non-mutable types."""
|
||||||
|
spy = mocker.spy(config.copy, 'deepcopy')
|
||||||
|
conf.get_mutable_obj('content.plugins')
|
||||||
|
assert not spy.called
|
||||||
|
|
||||||
|
def test_copy_mutable(self, conf, mocker):
|
||||||
|
"""Make sure mutable types are only copied once."""
|
||||||
|
spy = mocker.spy(config.copy, 'deepcopy')
|
||||||
|
conf.get_mutable_obj('bindings.commands')
|
||||||
|
spy.assert_called_once()
|
||||||
|
|
||||||
|
def test_get_obj_for_pattern(self, conf):
|
||||||
|
pattern = urlmatch.UrlPattern('*://example.com')
|
||||||
|
name = 'content.javascript.enabled'
|
||||||
|
conf.set_obj(name, False, pattern=pattern)
|
||||||
|
assert conf.get_obj_for_pattern(name, pattern=pattern) is False
|
||||||
|
|
||||||
|
def test_get_obj_for_pattern_no_match(self, conf):
|
||||||
|
pattern = urlmatch.UrlPattern('*://example.com')
|
||||||
|
name = 'content.javascript.enabled'
|
||||||
|
value = conf.get_obj_for_pattern(name, pattern=pattern)
|
||||||
|
assert value is configutils.UNSET
|
||||||
|
|
||||||
def test_get_str(self, conf):
|
def test_get_str(self, conf):
|
||||||
assert conf.get_str('content.plugins') == 'false'
|
assert conf.get_str('content.plugins') == 'false'
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ from PyQt5.QtCore import QUrl
|
|||||||
|
|
||||||
from qutebrowser.config import configcommands, configutils
|
from qutebrowser.config import configcommands, configutils
|
||||||
from qutebrowser.commands import cmdexc
|
from qutebrowser.commands import cmdexc
|
||||||
from qutebrowser.utils import usertypes
|
from qutebrowser.utils import usertypes, urlmatch
|
||||||
from qutebrowser.misc import objects
|
from qutebrowser.misc import objects
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +86,24 @@ class TestSet:
|
|||||||
assert config_stub.get(option) == new_value
|
assert config_stub.get(option) == new_value
|
||||||
assert yaml_value(option) == (configutils.UNSET if temp else new_value)
|
assert yaml_value(option) == (configutils.UNSET if temp else new_value)
|
||||||
|
|
||||||
|
def test_set_with_pattern(self, monkeypatch, commands, config_stub):
|
||||||
|
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit)
|
||||||
|
option = 'content.javascript.enabled'
|
||||||
|
|
||||||
|
commands.set(0, option, 'false', url='*://example.com')
|
||||||
|
pattern = urlmatch.UrlPattern('*://example.com')
|
||||||
|
|
||||||
|
assert config_stub.get(option)
|
||||||
|
assert not config_stub.get_obj_for_pattern(option, pattern=pattern)
|
||||||
|
|
||||||
|
def test_set_invalid_pattern(self, monkeypatch, commands):
|
||||||
|
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit)
|
||||||
|
option = 'content.javascript.enabled'
|
||||||
|
|
||||||
|
with pytest.raises(cmdexc.CommandError,
|
||||||
|
match='Error while parsing :/: No scheme given'):
|
||||||
|
commands.set(0, option, 'false', url=':/')
|
||||||
|
|
||||||
@pytest.mark.parametrize('temp', [True, False])
|
@pytest.mark.parametrize('temp', [True, False])
|
||||||
def test_set_temp_override(self, commands, config_stub, yaml_value, temp):
|
def test_set_temp_override(self, commands, config_stub, yaml_value, temp):
|
||||||
"""Invoking :set twice.
|
"""Invoking :set twice.
|
||||||
|
Loading…
Reference in New Issue
Block a user