Fix config tests for new Command type
This commit is contained in:
parent
2577b2c5e3
commit
2a40401398
@ -310,13 +310,14 @@ class FakeCommand:
|
|||||||
"""A simple command stub which has a description."""
|
"""A simple command stub which has a description."""
|
||||||
|
|
||||||
def __init__(self, name='', desc='', hide=False, debug=False,
|
def __init__(self, name='', desc='', hide=False, debug=False,
|
||||||
deprecated=False, completion=None):
|
deprecated=False, completion=None, maxsplit=None):
|
||||||
self.desc = desc
|
self.desc = desc
|
||||||
self.name = name
|
self.name = name
|
||||||
self.hide = hide
|
self.hide = hide
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.deprecated = deprecated
|
self.deprecated = deprecated
|
||||||
self.completion = completion
|
self.completion = completion
|
||||||
|
self.maxsplit = maxsplit
|
||||||
|
|
||||||
|
|
||||||
class FakeTimer(QObject):
|
class FakeTimer(QObject):
|
||||||
|
@ -19,18 +19,23 @@
|
|||||||
"""Tests for qutebrowser.config.configdata."""
|
"""Tests for qutebrowser.config.configdata."""
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import types
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# To run cmdutils.register decorators
|
# To run cmdutils.register decorators
|
||||||
from qutebrowser import app
|
from qutebrowser import app
|
||||||
from qutebrowser.config import configdata, configtypes
|
from qutebrowser.config import config, configdata, configtypes
|
||||||
from qutebrowser.utils import usertypes
|
from qutebrowser.utils import usertypes
|
||||||
|
|
||||||
|
|
||||||
def test_init():
|
def test_init(monkeypatch):
|
||||||
"""Test reading the default yaml file and validating the values."""
|
"""Test reading the default yaml file and validating the values."""
|
||||||
|
# FIXME:conf use some kind of config_stub here
|
||||||
|
ns = types.SimpleNamespace()
|
||||||
|
ns.aliases = {}
|
||||||
|
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||||
configdata.init()
|
configdata.init()
|
||||||
assert isinstance(configdata.DATA, dict)
|
assert isinstance(configdata.DATA, dict)
|
||||||
assert 'ignore_case' in configdata.DATA
|
assert 'ignore_case' in configdata.DATA
|
||||||
|
@ -27,6 +27,7 @@ import collections
|
|||||||
import itertools
|
import itertools
|
||||||
import warnings
|
import warnings
|
||||||
import inspect
|
import inspect
|
||||||
|
import types
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -206,6 +207,14 @@ class TestAll:
|
|||||||
elif issubclass(member, configtypes.BaseType):
|
elif issubclass(member, configtypes.BaseType):
|
||||||
yield member
|
yield member
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def patch(self, monkeypatch):
|
||||||
|
"""Patch aliases so Command works."""
|
||||||
|
# FIXME:conf use some kind of config_stub here
|
||||||
|
ns = types.SimpleNamespace()
|
||||||
|
ns.aliases = {}
|
||||||
|
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||||
|
|
||||||
@pytest.fixture(params=list(gen_classes()))
|
@pytest.fixture(params=list(gen_classes()))
|
||||||
def klass(self, request):
|
def klass(self, request):
|
||||||
return request.param
|
return request.param
|
||||||
@ -1011,13 +1020,18 @@ class TestCommand:
|
|||||||
'cmd1': stubs.FakeCommand(desc="desc 1"),
|
'cmd1': stubs.FakeCommand(desc="desc 1"),
|
||||||
'cmd2': stubs.FakeCommand(desc="desc 2")})
|
'cmd2': stubs.FakeCommand(desc="desc 2")})
|
||||||
monkeypatch.setattr(configtypes, 'cmdutils', cmd_utils)
|
monkeypatch.setattr(configtypes, 'cmdutils', cmd_utils)
|
||||||
|
# FIXME:conf use some kind of config_stub here
|
||||||
|
ns = types.SimpleNamespace()
|
||||||
|
ns.aliases = {'alias': 'cmd1'}
|
||||||
|
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||||
|
monkeypatch.setattr('qutebrowser.commands.runners.cmdutils', cmd_utils)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def klass(self):
|
def klass(self):
|
||||||
return configtypes.Command
|
return configtypes.Command
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', ['cmd1', 'cmd2', 'cmd1 foo bar',
|
@pytest.mark.parametrize('val', ['cmd1', 'cmd2', 'cmd1 foo bar',
|
||||||
'cmd2 baz fish'])
|
'cmd2 baz fish', 'alias foo'])
|
||||||
def test_to_py_valid(self, klass, val):
|
def test_to_py_valid(self, klass, val):
|
||||||
expected = None if not val else val
|
expected = None if not val else val
|
||||||
assert klass().to_py(val) == expected
|
assert klass().to_py(val) == expected
|
||||||
@ -1523,7 +1537,7 @@ class TestDirectory:
|
|||||||
os_mock.path.expandvars.assert_called_once_with('$HOME/foobar')
|
os_mock.path.expandvars.assert_called_once_with('$HOME/foobar')
|
||||||
|
|
||||||
def test_to_py_invalid_encoding(self, klass, os_mock,
|
def test_to_py_invalid_encoding(self, klass, os_mock,
|
||||||
unicode_encode_err):
|
unicode_encode_err):
|
||||||
"""Test to_py with an invalid encoding, e.g. LC_ALL=C."""
|
"""Test to_py with an invalid encoding, e.g. LC_ALL=C."""
|
||||||
os_mock.path.isdir.side_effect = unicode_encode_err
|
os_mock.path.isdir.side_effect = unicode_encode_err
|
||||||
os_mock.path.isabs.side_effect = unicode_encode_err
|
os_mock.path.isabs.side_effect = unicode_encode_err
|
||||||
|
Loading…
Reference in New Issue
Block a user