From ecba175b16c53cdf1f0f527b2133ea830b410d77 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 15 Jun 2017 19:09:08 +0200 Subject: [PATCH] Test and fix configtypes to_str. --- qutebrowser/config/configtypes.py | 9 +++++++-- tests/unit/config/test_configdata.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 90d70eea6..eb4848fb4 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -171,7 +171,7 @@ class BaseType: Arguments: value: The value to check. """ - assert isinstance(value, str) + assert isinstance(value, str), value if not value and not self.none_ok: raise configexc.ValidationError(value, "may not be empty!") if any(ord(c) < 32 or ord(c) == 0x7f for c in value): @@ -233,7 +233,7 @@ class BaseType: """ if value is None: return '' - assert isinstance(value, str) + assert isinstance(value, str), value return value def complete(self): @@ -1141,6 +1141,11 @@ class ShellCommand(BaseType): "{}-placeholder.") return value + def to_str(self, value): + if not value: + return '' + return json.dumps(value) + class Proxy(BaseType): diff --git a/tests/unit/config/test_configdata.py b/tests/unit/config/test_configdata.py index aaaa9a401..c939c3d37 100644 --- a/tests/unit/config/test_configdata.py +++ b/tests/unit/config/test_configdata.py @@ -33,7 +33,9 @@ def test_init(): assert isinstance(configdata.DATA, dict) assert 'ignore_case' in configdata.DATA for option in configdata.DATA.values(): + # Make sure to_py and to_str work option.typ.to_py(option.default) + option.typ.to_str(option.default) def test_init_benchmark(benchmark):