2014-12-15 22:06:11 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
2016-01-04 07:12:39 +01:00
|
|
|
# Copyright 2014-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-12-15 22:06:11 +01:00
|
|
|
|
|
|
|
# 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.config."""
|
|
|
|
|
2015-02-20 09:09:35 +01:00
|
|
|
import os
|
|
|
|
import os.path
|
2014-12-15 22:06:11 +01:00
|
|
|
import configparser
|
2015-12-01 22:40:58 +01:00
|
|
|
import collections
|
2015-12-11 07:49:33 +01:00
|
|
|
import shutil
|
2015-02-20 09:09:35 +01:00
|
|
|
from unittest import mock
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-02-20 09:09:35 +01:00
|
|
|
from PyQt5.QtCore import QObject
|
2014-12-15 22:06:11 +01:00
|
|
|
from PyQt5.QtGui import QColor
|
2015-04-04 17:02:32 +02:00
|
|
|
import pytest
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-11 07:49:33 +01:00
|
|
|
import qutebrowser
|
2015-04-09 21:19:37 +02:00
|
|
|
from qutebrowser.config import config, configexc, configdata
|
|
|
|
from qutebrowser.config.parsers import keyconf
|
|
|
|
from qutebrowser.commands import runners
|
2015-02-22 19:13:51 +01:00
|
|
|
from qutebrowser.utils import objreg, standarddir
|
2014-12-15 22:06:11 +01:00
|
|
|
|
|
|
|
|
2015-04-04 17:05:44 +02:00
|
|
|
class TestConfigParser:
|
2014-12-15 22:06:11 +01:00
|
|
|
|
|
|
|
"""Test reading of ConfigParser."""
|
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
Objects = collections.namedtuple('Objects', ['cp', 'cfg'])
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def objects(self):
|
|
|
|
cp = configparser.ConfigParser(interpolation=None,
|
|
|
|
comment_prefixes='#')
|
|
|
|
cp.optionxform = lambda opt: opt # be case-insensitive
|
2015-12-11 07:09:09 +01:00
|
|
|
cfg = config.ConfigManager()
|
|
|
|
cfg.read(None, None)
|
2015-12-01 22:40:58 +01:00
|
|
|
return self.Objects(cp=cp, cfg=cfg)
|
|
|
|
|
|
|
|
def test_simple(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test a simple option which is not transformed."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'ignore-case': 'false'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert not objects.cfg.get('general', 'ignore-case')
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_transformed_section_old(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test a transformed section with the old name."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'permissions': {'allow-plugins': 'true'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert objects.cfg.get('content', 'allow-plugins')
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_transformed_section_new(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test a transformed section with the new name."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'content': {'allow-plugins': 'true'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert objects.cfg.get('content', 'allow-plugins')
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_transformed_option_old(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test a transformed option with the old name."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'colors': {'tab.fg.odd': 'pink'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
actual = objects.cfg.get('colors', 'tabs.fg.odd').name()
|
2015-04-05 20:30:31 +02:00
|
|
|
expected = QColor('pink').name()
|
|
|
|
assert actual == expected
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_transformed_option_new(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test a transformed section with the new name."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'colors': {'tabs.fg.odd': 'pink'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
actual = objects.cfg.get('colors', 'tabs.fg.odd').name()
|
2015-04-05 20:30:31 +02:00
|
|
|
expected = QColor('pink').name()
|
|
|
|
assert actual == expected
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_value(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test setting an invalid value."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'ignore-case': 'invalid'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.ValidationError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._validate_all()
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_value_interpolated(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test setting an invalid interpolated value."""
|
2016-07-12 17:31:32 +02:00
|
|
|
objects.cp.read_dict({'general': {
|
|
|
|
'ignore-case': 'smart', 'private-browsing': '${ignore-case}'}})
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.ValidationError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._validate_all()
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_interpolation(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test setting an interpolated value."""
|
2016-07-12 17:31:32 +02:00
|
|
|
objects.cp.read_dict({'general': {
|
|
|
|
'ignore-case': 'false', 'private-browsing': '${ignore-case}'}})
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert not objects.cfg.get('general', 'ignore-case')
|
2016-07-12 17:31:32 +02:00
|
|
|
assert not objects.cfg.get('general', 'private-browsing')
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_interpolation_cross_section(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test setting an interpolated value from another section."""
|
2016-04-27 18:30:54 +02:00
|
|
|
objects.cp.read_dict({
|
|
|
|
'general': {'ignore-case': '${network:do-not-track}'},
|
|
|
|
'network': {'do-not-track': 'false'},
|
|
|
|
})
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert not objects.cfg.get('general', 'ignore-case')
|
|
|
|
assert not objects.cfg.get('network', 'do-not-track')
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_interpolation(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test an invalid interpolation."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'ignore-case': '${foo}'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configparser.InterpolationError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._validate_all()
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_interpolation_syntax(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test an invalid interpolation syntax."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'ignore-case': '${'}})
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.InterpolationSyntaxError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_section(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test an invalid section."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'foo': {'bar': 'baz'}})
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.NoSectionError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_option(self, objects):
|
2014-12-15 22:06:11 +01:00
|
|
|
"""Test an invalid option."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'bar': 'baz'}})
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.NoOptionError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg._from_cp(objects.cp)
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_section_relaxed(self, objects):
|
2015-03-23 07:58:28 +01:00
|
|
|
"""Test an invalid section with relaxed=True."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'foo': {'bar': 'baz'}})
|
|
|
|
objects.cfg._from_cp(objects.cp, relaxed=True)
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.NoSectionError):
|
2015-12-01 23:00:48 +01:00
|
|
|
objects.cfg.get('foo', 'bar')
|
2015-03-23 07:58:28 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_invalid_option_relaxed(self, objects):
|
2015-03-23 07:58:28 +01:00
|
|
|
"""Test an invalid option with relaxed=True."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'bar': 'baz'}})
|
|
|
|
objects.cfg._from_cp(objects.cp, relaxed=True)
|
2015-04-04 17:02:32 +02:00
|
|
|
with pytest.raises(configexc.NoOptionError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg.get('general', 'bar')
|
2015-03-23 07:58:28 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_fallback(self, objects):
|
2015-09-29 07:35:38 +02:00
|
|
|
"""Test getting an option with fallback.
|
|
|
|
|
|
|
|
This is done during interpolation in later Python 3.4 versions.
|
|
|
|
|
|
|
|
See https://github.com/The-Compiler/qutebrowser/issues/968
|
|
|
|
"""
|
2015-12-01 22:40:58 +01:00
|
|
|
assert objects.cfg.get('general', 'blabla', fallback='blub') == 'blub'
|
2015-09-29 07:35:38 +02:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_sectionproxy(self, objects):
|
2015-09-29 07:35:38 +02:00
|
|
|
"""Test getting an option via the section proxy."""
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cp.read_dict({'general': {'ignore-case': 'false'}})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
assert not objects.cfg['general'].get('ignore-case')
|
2015-09-29 07:35:38 +02:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
def test_sectionproxy_keyerror(self, objects):
|
2015-09-29 07:35:38 +02:00
|
|
|
"""Test getting an inexistent option via the section proxy."""
|
|
|
|
with pytest.raises(configexc.NoOptionError):
|
2015-12-01 22:40:58 +01:00
|
|
|
objects.cfg['general'].get('blahblahblub')
|
2015-09-29 07:35:38 +02:00
|
|
|
|
2015-12-11 07:53:14 +01:00
|
|
|
@pytest.mark.parametrize('old_sect, new_sect',
|
|
|
|
config.ConfigManager.RENAMED_SECTIONS.items())
|
|
|
|
def test_renamed_sections(self, old_sect, new_sect):
|
|
|
|
"""Make sure renamed sections don't exist anymore."""
|
|
|
|
assert old_sect not in configdata.DATA
|
|
|
|
assert new_sect in configdata.DATA
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('old_tuple, new_option',
|
2016-01-25 22:15:31 +01:00
|
|
|
sorted(config.ConfigManager.RENAMED_OPTIONS.items()))
|
2015-12-11 07:53:14 +01:00
|
|
|
def test_renamed_options(self, old_tuple, new_option):
|
|
|
|
"""Make sure renamed options exist under the new name."""
|
|
|
|
section, old_option = old_tuple
|
|
|
|
assert old_option not in configdata.DATA[section]
|
|
|
|
assert new_option in configdata.DATA[section]
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('section, option',
|
|
|
|
config.ConfigManager.DELETED_OPTIONS)
|
|
|
|
def test_deleted_options(self, section, option):
|
|
|
|
"""Make sure renamed options don't exist anymore."""
|
|
|
|
assert option not in configdata.DATA[section]
|
|
|
|
|
2016-07-14 16:58:54 +02:00
|
|
|
def test_config_reading_with_deleted_options(self, objects):
|
|
|
|
"""Test an invalid option with relaxed=True."""
|
|
|
|
objects.cp.read_dict({
|
|
|
|
'general': collections.OrderedDict(
|
|
|
|
[('wrap-search', 'true'), ('save-session', 'true')])
|
|
|
|
})
|
|
|
|
objects.cfg._from_cp(objects.cp)
|
|
|
|
with pytest.raises(configexc.NoOptionError):
|
|
|
|
objects.cfg.get('general', 'wrap-search')
|
|
|
|
assert objects.cfg.get('general', 'save-session')
|
|
|
|
|
2014-12-15 22:06:11 +01:00
|
|
|
|
2015-04-13 07:47:09 +02:00
|
|
|
class TestKeyConfigParser:
|
|
|
|
|
|
|
|
"""Test config.parsers.keyconf.KeyConfigParser."""
|
|
|
|
|
2016-08-09 14:23:31 +02:00
|
|
|
def test_cmd_binding(self, cmdline_test, config_stub):
|
2015-04-13 07:47:09 +02:00
|
|
|
"""Test various command bindings.
|
|
|
|
|
|
|
|
See https://github.com/The-Compiler/qutebrowser/issues/615
|
|
|
|
|
|
|
|
Args:
|
|
|
|
cmdline_test: A pytest fixture which provides testcases.
|
|
|
|
"""
|
2016-08-09 14:23:31 +02:00
|
|
|
config_stub.data = {'aliases': []}
|
2015-04-13 07:47:09 +02:00
|
|
|
kcp = keyconf.KeyConfigParser(None, None)
|
|
|
|
kcp._cur_section = 'normal'
|
|
|
|
if cmdline_test.valid:
|
|
|
|
kcp._read_command(cmdline_test.cmd)
|
|
|
|
else:
|
|
|
|
with pytest.raises(keyconf.KeyConfigError):
|
|
|
|
kcp._read_command(cmdline_test.cmd)
|
|
|
|
|
2015-05-25 01:26:52 +02:00
|
|
|
@pytest.mark.parametrize('rgx', [rgx for rgx, _repl
|
|
|
|
in configdata.CHANGED_KEY_COMMANDS])
|
|
|
|
def test_default_config_no_deprecated(self, rgx):
|
2015-05-13 08:26:19 +02:00
|
|
|
"""Make sure the default config contains no deprecated commands."""
|
2015-05-25 01:26:52 +02:00
|
|
|
for sect in configdata.KEY_DATA.values():
|
|
|
|
for command in sect:
|
|
|
|
assert rgx.match(command) is None
|
2015-05-13 08:26:19 +02:00
|
|
|
|
2015-05-13 10:41:23 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'old, new_expected',
|
|
|
|
[
|
|
|
|
('open -t about:blank', 'open -t'),
|
|
|
|
('open -w about:blank', 'open -w'),
|
|
|
|
('open -b about:blank', 'open -b'),
|
|
|
|
('open about:blank', None),
|
|
|
|
('open -t example.com', None),
|
2015-05-15 18:59:46 +02:00
|
|
|
|
2015-05-13 10:41:23 +02:00
|
|
|
('download-page', 'download'),
|
|
|
|
('cancel-download', 'download-cancel'),
|
2015-05-15 18:59:46 +02:00
|
|
|
|
2015-09-03 11:14:05 +02:00
|
|
|
('search ""', 'clear-keychain ;; search'),
|
|
|
|
("search ''", 'clear-keychain ;; search'),
|
|
|
|
("search", 'clear-keychain ;; search'),
|
2015-06-05 17:45:32 +02:00
|
|
|
("search ;; foobar", None),
|
2015-05-13 10:41:23 +02:00
|
|
|
('search "foo"', None),
|
2015-05-15 18:59:46 +02:00
|
|
|
|
2015-05-13 10:41:23 +02:00
|
|
|
('set-cmd-text "foo bar"', 'set-cmd-text foo bar'),
|
|
|
|
("set-cmd-text 'foo bar'", 'set-cmd-text foo bar'),
|
|
|
|
('set-cmd-text foo bar', None),
|
|
|
|
('set-cmd-text "foo bar "', 'set-cmd-text -s foo bar'),
|
|
|
|
("set-cmd-text 'foo bar '", 'set-cmd-text -s foo bar'),
|
2015-05-15 18:59:46 +02:00
|
|
|
|
2015-05-13 10:45:20 +02:00
|
|
|
('hint links rapid', 'hint --rapid links tab-bg'),
|
|
|
|
('hint links rapid-win', 'hint --rapid links window'),
|
2015-05-15 18:59:46 +02:00
|
|
|
|
|
|
|
('scroll -50 0', 'scroll left'),
|
|
|
|
('scroll 0 50', 'scroll down'),
|
|
|
|
('scroll 0 -50', 'scroll up'),
|
|
|
|
('scroll 50 0', 'scroll right'),
|
|
|
|
('scroll -50 10', 'scroll-px -50 10'),
|
|
|
|
('scroll 50 50', 'scroll-px 50 50'),
|
|
|
|
('scroll 0 0', 'scroll-px 0 0'),
|
|
|
|
('scroll 23 42', 'scroll-px 23 42'),
|
2015-09-03 11:14:05 +02:00
|
|
|
|
|
|
|
('search ;; clear-keychain', 'clear-keychain ;; search'),
|
|
|
|
('search;;clear-keychain', 'clear-keychain ;; search'),
|
|
|
|
('search;;foo', None),
|
|
|
|
('leave-mode', 'clear-keychain ;; leave-mode'),
|
|
|
|
('leave-mode ;; foo', None),
|
2015-11-04 00:01:27 +01:00
|
|
|
|
|
|
|
('download-remove --all', 'download-clear'),
|
2016-08-01 18:19:34 +02:00
|
|
|
|
|
|
|
('hint links fill ":open {hint-url}"',
|
2016-08-09 17:28:14 +02:00
|
|
|
'hint links fill :open {hint-url}'),
|
2016-08-01 18:19:34 +02:00
|
|
|
('hint links fill ":open -t {hint-url}"',
|
|
|
|
'hint links fill :open -t {hint-url}'),
|
2016-08-07 02:36:13 +02:00
|
|
|
|
|
|
|
('yank-selected', 'yank selection'),
|
|
|
|
('yank-selected --sel', 'yank selection --sel'),
|
|
|
|
('yank-selected -p', 'yank selection -s'),
|
|
|
|
|
|
|
|
('yank -t', 'yank title'),
|
|
|
|
('yank -ts', 'yank title -s'),
|
|
|
|
('yank -d', 'yank domain'),
|
|
|
|
('yank -ds', 'yank domain -s'),
|
|
|
|
('yank -p', 'yank pretty-url'),
|
|
|
|
('yank -ps', 'yank pretty-url -s'),
|
2016-08-07 13:14:46 +02:00
|
|
|
|
2016-08-07 00:46:23 +02:00
|
|
|
('paste', 'open {clipboard}'),
|
|
|
|
('paste -t', 'open -t {clipboard}'),
|
|
|
|
('paste -ws', 'open -w {primary}'),
|
2015-05-13 10:41:23 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_migrations(self, old, new_expected):
|
|
|
|
"""Make sure deprecated commands get migrated correctly."""
|
|
|
|
if new_expected is None:
|
|
|
|
new_expected = old
|
|
|
|
new = old
|
|
|
|
for rgx, repl in configdata.CHANGED_KEY_COMMANDS:
|
|
|
|
if rgx.match(new):
|
|
|
|
new = rgx.sub(repl, new)
|
|
|
|
break
|
|
|
|
assert new == new_expected
|
|
|
|
|
2015-04-13 07:47:09 +02:00
|
|
|
|
2016-07-16 12:47:12 +02:00
|
|
|
@pytest.mark.usefixtures('config_tmpdir')
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-04-04 17:05:44 +02:00
|
|
|
class TestDefaultConfig:
|
2015-01-04 13:34:05 +01:00
|
|
|
|
|
|
|
"""Test validating of the default config."""
|
|
|
|
|
2015-08-09 20:47:50 +02:00
|
|
|
@pytest.mark.usefixtures('qapp')
|
2015-01-04 13:34:05 +01:00
|
|
|
def test_default_config(self):
|
|
|
|
"""Test validating of the default config."""
|
2015-12-11 07:09:09 +01:00
|
|
|
conf = config.ConfigManager()
|
2015-12-11 22:17:49 +01:00
|
|
|
conf.read(None, None)
|
2015-01-04 13:34:05 +01:00
|
|
|
conf._validate_all()
|
|
|
|
|
2015-04-09 21:19:37 +02:00
|
|
|
def test_default_key_config(self):
|
|
|
|
"""Test validating of the default key config."""
|
|
|
|
# We import qutebrowser.app so the cmdutils.register decorators run.
|
2016-07-11 13:18:31 +02:00
|
|
|
import qutebrowser.app # pylint: disable=unused-variable
|
2015-04-09 21:19:37 +02:00
|
|
|
conf = keyconf.KeyConfigParser(None, None)
|
|
|
|
runner = runners.CommandRunner(win_id=0)
|
|
|
|
for sectname in configdata.KEY_DATA:
|
|
|
|
for cmd in conf.get_bindings_for(sectname).values():
|
2016-06-12 21:03:04 +02:00
|
|
|
runner.parse(cmd)
|
2015-04-09 21:19:37 +02:00
|
|
|
|
2015-12-11 07:49:33 +01:00
|
|
|
def test_upgrade_version(self):
|
|
|
|
"""Fail when the qutebrowser version changed.
|
|
|
|
|
|
|
|
The aim of this is to remind us to add a new file to old_configs.
|
|
|
|
|
|
|
|
If the config file of the current release didn't change compared to the
|
|
|
|
last one in old_configs, just increment the version here.
|
|
|
|
|
|
|
|
If it did change, place a new qutebrowser-vx.y.z.conf in old_configs
|
|
|
|
and then increment the version.
|
|
|
|
"""
|
2016-07-27 12:31:30 +02:00
|
|
|
assert qutebrowser.__version__ == '0.8.1'
|
2015-12-11 07:49:33 +01:00
|
|
|
|
|
|
|
@pytest.mark.parametrize('filename',
|
|
|
|
os.listdir(os.path.join(os.path.dirname(__file__), 'old_configs')),
|
|
|
|
ids=os.path.basename)
|
2015-12-11 18:16:46 +01:00
|
|
|
def test_old_config(self, qapp, tmpdir, filename):
|
2015-12-11 07:49:33 +01:00
|
|
|
"""Check if upgrading old configs works correctly."""
|
|
|
|
full_path = os.path.join(os.path.dirname(__file__), 'old_configs',
|
|
|
|
filename)
|
|
|
|
shutil.copy(full_path, str(tmpdir / 'qutebrowser.conf'))
|
|
|
|
conf = config.ConfigManager()
|
|
|
|
conf.read(str(tmpdir), 'qutebrowser.conf')
|
|
|
|
|
2015-01-04 13:34:05 +01:00
|
|
|
|
2015-08-11 19:36:27 +02:00
|
|
|
@pytest.mark.integration
|
2015-04-04 17:05:44 +02:00
|
|
|
class TestConfigInit:
|
2015-02-20 09:09:35 +01:00
|
|
|
|
|
|
|
"""Test initializing of the config."""
|
|
|
|
|
2015-04-04 17:02:32 +02:00
|
|
|
@pytest.yield_fixture(autouse=True)
|
2016-07-08 19:30:17 +02:00
|
|
|
def patch(self, fake_args):
|
2015-02-20 09:09:35 +01:00
|
|
|
objreg.register('app', QObject())
|
|
|
|
objreg.register('save-manager', mock.MagicMock())
|
2016-07-08 19:30:17 +02:00
|
|
|
fake_args.relaxed_config = False
|
2015-08-11 21:22:36 +02:00
|
|
|
old_standarddir_args = standarddir._args
|
2015-04-04 17:02:32 +02:00
|
|
|
yield
|
2016-07-08 19:30:17 +02:00
|
|
|
objreg.delete('app')
|
|
|
|
objreg.delete('save-manager')
|
|
|
|
# registered by config.init()
|
|
|
|
objreg.delete('config')
|
|
|
|
objreg.delete('key-config')
|
|
|
|
objreg.delete('state-config')
|
2015-08-11 21:22:36 +02:00
|
|
|
standarddir._args = old_standarddir_args
|
2015-02-20 09:09:35 +01:00
|
|
|
|
2015-12-01 22:40:58 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def env(self, tmpdir):
|
|
|
|
conf_path = (tmpdir / 'config').ensure(dir=1)
|
|
|
|
data_path = (tmpdir / 'data').ensure(dir=1)
|
|
|
|
cache_path = (tmpdir / 'cache').ensure(dir=1)
|
|
|
|
env = {
|
|
|
|
'XDG_CONFIG_HOME': str(conf_path),
|
|
|
|
'XDG_DATA_HOME': str(data_path),
|
|
|
|
'XDG_CACHE_HOME': str(cache_path),
|
|
|
|
}
|
|
|
|
return env
|
|
|
|
|
2016-07-08 19:30:17 +02:00
|
|
|
def test_config_none(self, monkeypatch, env, fake_args):
|
2015-02-20 09:09:35 +01:00
|
|
|
"""Test initializing with config path set to None."""
|
2016-07-08 19:30:17 +02:00
|
|
|
fake_args.confdir = ''
|
|
|
|
fake_args.datadir = ''
|
|
|
|
fake_args.cachedir = ''
|
|
|
|
fake_args.basedir = None
|
2015-12-01 22:40:58 +01:00
|
|
|
for k, v in env.items():
|
2015-04-04 17:02:32 +02:00
|
|
|
monkeypatch.setenv(k, v)
|
2016-07-08 19:30:17 +02:00
|
|
|
standarddir.init(fake_args)
|
2015-04-04 17:02:32 +02:00
|
|
|
config.init()
|
2015-12-01 22:40:58 +01:00
|
|
|
assert not os.listdir(env['XDG_CONFIG_HOME'])
|