Add test_configfiles.py
This commit is contained in:
parent
e72b0fc89d
commit
54adf3898a
99
tests/unit/config/test_configfiles.py
Normal file
99
tests/unit/config/test_configfiles.py
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
# Copyright 2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Tests for qutebrowser.config.configfiles."""
|
||||||
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from qutebrowser.config import configfiles
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QSettings
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('old_data, insert, new_data', [
|
||||||
|
(None, False, '[general]\n\n[geometry]\n\n'),
|
||||||
|
('[general]\nfooled = true', False, '[general]\n\n[geometry]\n\n'),
|
||||||
|
('[general]\nfoobar = 42', False,
|
||||||
|
'[general]\nfoobar = 42\n\n[geometry]\n\n'),
|
||||||
|
(None, True, '[general]\nnewval = 23\n\n[geometry]\n\n'),
|
||||||
|
])
|
||||||
|
def test_state_config(fake_save_manager, data_tmpdir,
|
||||||
|
old_data, insert, new_data):
|
||||||
|
statefile = data_tmpdir / 'state'
|
||||||
|
if old_data is not None:
|
||||||
|
statefile.write_text(old_data, 'utf-8')
|
||||||
|
|
||||||
|
state = configfiles.StateConfig()
|
||||||
|
|
||||||
|
if insert:
|
||||||
|
state['general']['newval'] = '23'
|
||||||
|
if 'foobar' in (old_data or ''):
|
||||||
|
assert state['general']['foobar'] == '42'
|
||||||
|
|
||||||
|
state._save()
|
||||||
|
|
||||||
|
assert statefile.read_text('utf-8') == new_data
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('old_config', [
|
||||||
|
None,
|
||||||
|
'global:\n colors.hints.fg: magenta',
|
||||||
|
])
|
||||||
|
@pytest.mark.parametrize('insert', [True, False])
|
||||||
|
def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
||||||
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
|
if old_config is not None:
|
||||||
|
autoconfig.write_text(old_config, 'utf-8')
|
||||||
|
|
||||||
|
yaml = configfiles.YamlConfig()
|
||||||
|
yaml.load()
|
||||||
|
|
||||||
|
if insert:
|
||||||
|
yaml.values['tabs.show'] = 'never'
|
||||||
|
|
||||||
|
yaml._save()
|
||||||
|
|
||||||
|
text = autoconfig.read_text('utf-8')
|
||||||
|
lines = text.splitlines()
|
||||||
|
print(lines)
|
||||||
|
|
||||||
|
assert lines[0].startswith('# DO NOT edit this file by hand,')
|
||||||
|
|
||||||
|
if old_config is None and not insert:
|
||||||
|
assert lines[3] == 'global: {}'
|
||||||
|
else:
|
||||||
|
assert lines[3] == 'global:'
|
||||||
|
|
||||||
|
if 'magenta' in (old_config or ''):
|
||||||
|
assert ' colors.hints.fg: magenta' in lines
|
||||||
|
if insert:
|
||||||
|
assert ' tabs.show: never' in lines
|
||||||
|
|
||||||
|
|
||||||
|
def test_init(qapp, fake_save_manager, config_tmpdir, data_tmpdir,
|
||||||
|
config_stub):
|
||||||
|
configfiles.init(config=None)
|
||||||
|
|
||||||
|
# Make sure qsettings land in a subdir
|
||||||
|
settings = QSettings()
|
||||||
|
settings.setValue("hello", "world")
|
||||||
|
settings.sync()
|
||||||
|
assert (config_tmpdir / 'qsettings').exists()
|
||||||
|
|
||||||
|
# Lots of other stuff is tested in test_config.py in test_init
|
Loading…
Reference in New Issue
Block a user