summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-12-18 15:35:12 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-12-18 20:12:23 +0100
commit64baebcf08b994b40f66830d46f807de430ffde3 (patch)
tree49bd8e205c21effb03dc8a8d94f13b05ba6c438a
parentda52706ab5c50fc4b2241bf4fc6fe5ebc5e03416 (diff)
downloadqutebrowser-64baebcf08b994b40f66830d46f807de430ffde3.tar.gz
qutebrowser-64baebcf08b994b40f66830d46f807de430ffde3.zip
config: Allow to set completions for FormatString
-rw-r--r--qutebrowser/config/configtypes.py17
-rw-r--r--tests/unit/config/test_configtypes.py16
2 files changed, 29 insertions, 4 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py
index d48c02250..be1f7edcf 100644
--- a/qutebrowser/config/configtypes.py
+++ b/qutebrowser/config/configtypes.py
@@ -1530,12 +1530,19 @@ class Directory(BaseType):
class FormatString(BaseType):
- """A string with placeholders."""
+ """A string with placeholders.
+
+ Attributes:
+ fields: Which replacements are allowed in the format string.
+ completions: completions to be used, or None
+ """
def __init__(self, fields: typing.Iterable[str],
- none_ok: bool = False) -> None:
+ none_ok: bool = False,
+ completions: _Completions = None) -> None:
super().__init__(none_ok)
self.fields = fields
+ self._completions = completions
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
@@ -1554,6 +1561,12 @@ class FormatString(BaseType):
return value
+ def complete(self) -> _Completions:
+ if self._completions is not None:
+ return self._completions
+ else:
+ return super().complete()
+
def __repr__(self) -> str:
return utils.get_repr(self, none_ok=self.none_ok, fields=self.fields)
diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py
index e7b483dd8..55d225a7e 100644
--- a/tests/unit/config/test_configtypes.py
+++ b/tests/unit/config/test_configtypes.py
@@ -1838,8 +1838,12 @@ class TestDirectory:
class TestFormatString:
@pytest.fixture
- def typ(self):
- return configtypes.FormatString(fields=('foo', 'bar'))
+ def klass(self):
+ return configtypes.FormatString
+
+ @pytest.fixture
+ def typ(self, klass):
+ return klass(fields=('foo', 'bar'))
@pytest.mark.parametrize('val', [
'foo bar baz',
@@ -1857,6 +1861,14 @@ class TestFormatString:
with pytest.raises(configexc.ValidationError):
typ.to_py(val)
+ @pytest.mark.parametrize('value', [
+ None,
+ ['one', 'two'],
+ [('1', 'one'), ('2', 'two')],
+ ])
+ def test_complete(self, klass, value):
+ assert klass(fields=('foo'), completions=value).complete() == value
+
class TestShellCommand: