5d50ec612d
QSettings uses a plist file there.
113 lines
3.5 KiB
Python
113 lines
3.5 KiB
Python
# 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 sys
|
|
|
|
import pytest
|
|
|
|
from qutebrowser.config import configfiles
|
|
from qutebrowser.utils import objreg
|
|
|
|
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'
|
|
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
|
if 'foobar' in (old_data or ''): # pylint: disable=superfluous-parens
|
|
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,')
|
|
assert 'config_version: {}'.format(yaml.VERSION) in lines
|
|
|
|
if old_config is None and not insert:
|
|
assert 'global: {}' in lines
|
|
else:
|
|
assert 'global:' in lines
|
|
|
|
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
|
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
|
|
assert ' colors.hints.fg: magenta' in lines
|
|
if insert:
|
|
assert ' tabs.show: never' in lines
|
|
|
|
|
|
@pytest.fixture
|
|
def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir,
|
|
config_stub):
|
|
yield
|
|
objreg.delete('state-config')
|
|
objreg.delete('command-history')
|
|
|
|
|
|
def test_init(init_patch, config_tmpdir):
|
|
configfiles.init(config=None)
|
|
|
|
# Make sure qsettings land in a subdir
|
|
if sys.platform == 'linux':
|
|
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
|