Tests and improvements for ConfigContainer
This commit is contained in:
parent
4495e721d8
commit
2b9b54cf6b
@ -519,11 +519,7 @@ class ConfigContainer:
|
|||||||
if configdata.is_valid_prefix(name):
|
if configdata.is_valid_prefix(name):
|
||||||
return ConfigContainer(config=self._config, prefix=name)
|
return ConfigContainer(config=self._config, prefix=name)
|
||||||
|
|
||||||
try:
|
return self._config.get(name)
|
||||||
return self._config.get(name)
|
|
||||||
except configexc.NoOptionError as e:
|
|
||||||
# If it's not a valid prefix - re-raise to improve error text.
|
|
||||||
raise configexc.NoOptionError(name)
|
|
||||||
|
|
||||||
def __setattr__(self, attr, value):
|
def __setattr__(self, attr, value):
|
||||||
"""Set the given option in the config."""
|
"""Set the given option in the config."""
|
||||||
|
@ -395,6 +395,36 @@ class TestConfig:
|
|||||||
assert conf.dump_userconfig() == '<Default configuration>'
|
assert conf.dump_userconfig() == '<Default configuration>'
|
||||||
|
|
||||||
|
|
||||||
|
class TestContainer:
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def container(self, config_stub):
|
||||||
|
return config.ConfigContainer(config_stub)
|
||||||
|
|
||||||
|
def test_getattr_invalid_private(self, container):
|
||||||
|
"""Make sure an invalid _attribute doesn't try getting a container."""
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
container._foo
|
||||||
|
|
||||||
|
def test_getattr_prefix(self, container):
|
||||||
|
new_container = container.tabs
|
||||||
|
assert new_container._prefix == 'tabs'
|
||||||
|
new_container = new_container.favicons
|
||||||
|
assert new_container._prefix == 'tabs.favicons'
|
||||||
|
|
||||||
|
def test_getattr_option(self, container):
|
||||||
|
assert container.tabs.show == 'always'
|
||||||
|
|
||||||
|
def test_getattr_invalid(self, container):
|
||||||
|
with pytest.raises(configexc.NoOptionError) as excinfo:
|
||||||
|
container.tabs.foobar
|
||||||
|
assert excinfo.value.option == 'tabs.foobar'
|
||||||
|
|
||||||
|
def test_setattr_option(self, config_stub, container):
|
||||||
|
container.content.cookies.store = False
|
||||||
|
assert config_stub._values['content.cookies.store'] is False
|
||||||
|
|
||||||
|
|
||||||
class StyleObj(QObject):
|
class StyleObj(QObject):
|
||||||
|
|
||||||
def __init__(self, stylesheet=None, parent=None):
|
def __init__(self, stylesheet=None, parent=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user