Tests and improvements for ConfigContainer

This commit is contained in:
Florian Bruhin 2017-07-03 12:41:36 +02:00
parent 4495e721d8
commit 2b9b54cf6b
2 changed files with 31 additions and 5 deletions

View File

@ -519,11 +519,7 @@ class ConfigContainer:
if configdata.is_valid_prefix(name):
return ConfigContainer(config=self._config, prefix=name)
try:
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)
return self._config.get(name)
def __setattr__(self, attr, value):
"""Set the given option in the config."""

View File

@ -395,6 +395,36 @@ class TestConfig:
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):
def __init__(self, stylesheet=None, parent=None):