tests: Clean up test_config
This commit is contained in:
parent
cfbd02eaba
commit
5bdeacd772
@ -51,72 +51,54 @@ class TestConfigParser:
|
||||
cfg.read(None, None)
|
||||
return self.Objects(cp=cp, cfg=cfg)
|
||||
|
||||
def test_simple(self, objects):
|
||||
"""Test a simple option which is not transformed."""
|
||||
objects.cp.read_dict({'general': {'ignore-case': 'false'}})
|
||||
@pytest.mark.parametrize('config, section, option, value', [
|
||||
# Simple option without transformation
|
||||
({'general': {'ignore-case': 'false'}},
|
||||
'general', 'ignore-case', False),
|
||||
# Transformed section with old name
|
||||
({'permissions': {'allow-plugins': 'true'}},
|
||||
'content', 'allow-plugins', True),
|
||||
# Transformed section with new name
|
||||
({'content': {'allow-plugins': 'true'}},
|
||||
'content', 'allow-plugins', True),
|
||||
# Transformed option with old name
|
||||
({'colors': {'tab.fg.odd': 'pink'}},
|
||||
'colors', 'tabs.fg.odd', QColor('pink')),
|
||||
# Transformed option with new name
|
||||
({'colors': {'tabs.fg.odd': 'pink'}},
|
||||
'colors', 'tabs.fg.odd', QColor('pink')),
|
||||
])
|
||||
def test_get(self, objects, config, section, option, value):
|
||||
objects.cp.read_dict(config)
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
assert not objects.cfg.get('general', 'ignore-case')
|
||||
assert objects.cfg.get(section, option) == value
|
||||
|
||||
def test_transformed_section_old(self, objects):
|
||||
"""Test a transformed section with the old name."""
|
||||
objects.cp.read_dict({'permissions': {'allow-plugins': 'true'}})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
assert objects.cfg.get('content', 'allow-plugins')
|
||||
|
||||
def test_transformed_section_new(self, objects):
|
||||
"""Test a transformed section with the new name."""
|
||||
objects.cp.read_dict({'content': {'allow-plugins': 'true'}})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
assert objects.cfg.get('content', 'allow-plugins')
|
||||
|
||||
def test_transformed_option_old(self, objects):
|
||||
"""Test a transformed option with the old name."""
|
||||
objects.cp.read_dict({'colors': {'tab.fg.odd': 'pink'}})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
actual = objects.cfg.get('colors', 'tabs.fg.odd').name()
|
||||
expected = QColor('pink').name()
|
||||
assert actual == expected
|
||||
|
||||
def test_transformed_option_new(self, objects):
|
||||
"""Test a transformed section with the new name."""
|
||||
objects.cp.read_dict({'colors': {'tabs.fg.odd': 'pink'}})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
actual = objects.cfg.get('colors', 'tabs.fg.odd').name()
|
||||
expected = QColor('pink').name()
|
||||
assert actual == expected
|
||||
|
||||
def test_invalid_value(self, objects):
|
||||
"""Test setting an invalid value."""
|
||||
objects.cp.read_dict({'general': {'ignore-case': 'invalid'}})
|
||||
@pytest.mark.parametrize('config', [
|
||||
{'general': {'ignore-case': 'invalid'}},
|
||||
{'general': {'ignore-case': 'smart',
|
||||
'private-browsing': '${ignore-case}'}},
|
||||
])
|
||||
def test_failing_validation(self, objects, config):
|
||||
objects.cp.read_dict(config)
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
with pytest.raises(configexc.ValidationError):
|
||||
objects.cfg._validate_all()
|
||||
|
||||
def test_invalid_value_interpolated(self, objects):
|
||||
"""Test setting an invalid interpolated value."""
|
||||
objects.cp.read_dict({'general': {
|
||||
'ignore-case': 'smart', 'private-browsing': '${ignore-case}'}})
|
||||
@pytest.mark.parametrize('config, sect1, opt1, sect2, opt2', [
|
||||
# Same section
|
||||
({'general': {'ignore-case': 'false',
|
||||
'private-browsing': '${ignore-case}'}},
|
||||
'general', 'ignore-case', 'general', 'private-browsing'),
|
||||
# Across sections
|
||||
({'general': {'ignore-case': '${network:do-not-track}'},
|
||||
'network': {'do-not-track': 'false'}},
|
||||
'general', 'ignore-case', 'network', 'do-not-track'),
|
||||
])
|
||||
def test_interpolation(self, objects, config, sect1, opt1, sect2, opt2):
|
||||
objects.cp.read_dict(config)
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
with pytest.raises(configexc.ValidationError):
|
||||
objects.cfg._validate_all()
|
||||
|
||||
def test_interpolation(self, objects):
|
||||
"""Test setting an interpolated value."""
|
||||
objects.cp.read_dict({'general': {
|
||||
'ignore-case': 'false', 'private-browsing': '${ignore-case}'}})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
assert not objects.cfg.get('general', 'ignore-case')
|
||||
assert not objects.cfg.get('general', 'private-browsing')
|
||||
|
||||
def test_interpolation_cross_section(self, objects):
|
||||
"""Test setting an interpolated value from another section."""
|
||||
objects.cp.read_dict({
|
||||
'general': {'ignore-case': '${network:do-not-track}'},
|
||||
'network': {'do-not-track': 'false'},
|
||||
})
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
assert not objects.cfg.get('general', 'ignore-case')
|
||||
assert not objects.cfg.get('network', 'do-not-track')
|
||||
assert not objects.cfg.get(sect1, opt1)
|
||||
assert not objects.cfg.get(sect2, opt2)
|
||||
|
||||
def test_invalid_interpolation(self, objects):
|
||||
"""Test an invalid interpolation."""
|
||||
@ -125,37 +107,32 @@ class TestConfigParser:
|
||||
with pytest.raises(configparser.InterpolationError):
|
||||
objects.cfg._validate_all()
|
||||
|
||||
def test_invalid_interpolation_syntax(self, objects):
|
||||
"""Test an invalid interpolation syntax."""
|
||||
objects.cp.read_dict({'general': {'ignore-case': '${'}})
|
||||
with pytest.raises(configexc.InterpolationSyntaxError):
|
||||
@pytest.mark.parametrize('config, exception', [
|
||||
# Invalid interpolation syntax
|
||||
({'general': {'ignore-case': '${'}},
|
||||
configexc.InterpolationSyntaxError),
|
||||
# Invalid section
|
||||
({'foo': {'bar': 'baz'}}, configexc.NoSectionError),
|
||||
# Invalid option
|
||||
({'general': {'bar': 'baz'}}, configexc.NoOptionError),
|
||||
])
|
||||
def test_invalid_from_cp(self, objects, config, exception):
|
||||
objects.cp.read_dict(config)
|
||||
with pytest.raises(exception):
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
|
||||
def test_invalid_section(self, objects):
|
||||
"""Test an invalid section."""
|
||||
objects.cp.read_dict({'foo': {'bar': 'baz'}})
|
||||
with pytest.raises(configexc.NoSectionError):
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
|
||||
def test_invalid_option(self, objects):
|
||||
"""Test an invalid option."""
|
||||
objects.cp.read_dict({'general': {'bar': 'baz'}})
|
||||
with pytest.raises(configexc.NoOptionError):
|
||||
objects.cfg._from_cp(objects.cp)
|
||||
|
||||
def test_invalid_section_relaxed(self, objects):
|
||||
"""Test an invalid section with relaxed=True."""
|
||||
objects.cp.read_dict({'foo': {'bar': 'baz'}})
|
||||
@pytest.mark.parametrize('config, sect, opt, exception', [
|
||||
# Invalid section
|
||||
({'foo': {'bar': 'baz'}}, 'foo', 'bar', configexc.NoSectionError),
|
||||
# Invalid option
|
||||
({'general': {'bar': 'baz'}}, 'general', 'baz',
|
||||
configexc.NoOptionError),
|
||||
])
|
||||
def test_invalid_relaxed(self, objects, config, sect, opt, exception):
|
||||
objects.cp.read_dict(config)
|
||||
objects.cfg._from_cp(objects.cp, relaxed=True)
|
||||
with pytest.raises(configexc.NoSectionError):
|
||||
objects.cfg.get('foo', 'bar')
|
||||
|
||||
def test_invalid_option_relaxed(self, objects):
|
||||
"""Test an invalid option with relaxed=True."""
|
||||
objects.cp.read_dict({'general': {'bar': 'baz'}})
|
||||
objects.cfg._from_cp(objects.cp, relaxed=True)
|
||||
with pytest.raises(configexc.NoOptionError):
|
||||
objects.cfg.get('general', 'bar')
|
||||
with pytest.raises(exception):
|
||||
objects.cfg.get(sect, opt)
|
||||
|
||||
def test_fallback(self, objects):
|
||||
"""Test getting an option with fallback.
|
||||
|
Loading…
Reference in New Issue
Block a user