From c6897608720cf6f975bd1f3386ac568d1d4f4a99 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 6 Oct 2018 19:18:43 +0200 Subject: [PATCH] Sort keys in configtypes.Dict.to_str Otherwise, we get inconsistent output between runs on Python 3.5 --- qutebrowser/config/configtypes.py | 2 +- tests/unit/completion/test_models.py | 4 ++-- tests/unit/config/test_configtypes.py | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 3fd58093c..5503ea4f3 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1295,7 +1295,7 @@ class Dict(BaseType): if not value: # An empty Dict is treated just like None -> empty string return '' - return json.dumps(value) + return json.dumps(value, sort_keys=True) def to_doc(self, value, indent=0): if not value: diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index bace2f6f6..c820147e5 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -844,8 +844,8 @@ def test_setting_option_completion(qtmodeltester, config_stub, "Options": [ ('aliases', 'Aliases for commands.', '{"q": "quit"}'), ('bindings.commands', 'Default keybindings', ( - '{"normal": {"": "quit", "ZQ": "quit", ' - '"I": "invalid", "d": "scroll down"}}')), + '{"normal": {"": "quit", "I": "invalid", ' + '"ZQ": "quit", "d": "scroll down"}}')), ('completion.open_categories', 'Which categories to show (in ' 'which order) in the :open completion.', '["searchengines", "quickmarks", "bookmarks", "history"]'), diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 7b3efc10c..b2775de2f 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -1703,6 +1703,11 @@ class TestDict: value = typ.from_obj({'1': '2'}) assert value == {'1': 2} + def test_to_str(self, klass): + typ = klass(keytype=configtypes.String(), valtype=configtypes.String()) + d = {'a': 'b', 'c': 'd'} + assert typ.to_str(d) == '{"a": "b", "c": "d"}' + def unrequired_class(**kwargs): return configtypes.File(required=False, **kwargs)