diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 95d3c9468..632773b7f 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -889,6 +889,10 @@ def yaml_load(f): def yaml_dump(data, f=None): - """Wrapper over yaml.dump using the C dumper if possible.""" - return yaml.dump(data, f, Dumper=YamlDumper, default_flow_style=False, - encoding='utf-8', allow_unicode=True) + """Wrapper over yaml.dump using the C dumper if possible. + + Also returns a str instead of bytes. + """ + yaml_data = yaml.dump(data, f, Dumper=YamlDumper, default_flow_style=False, + encoding='utf-8', allow_unicode=True) + return yaml_data.decode('utf-8') diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 4f20cb818..ce4e052db 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -531,7 +531,7 @@ class TestList: @hypothesis.given(val=strategies.lists(strategies.just('foo'))) def test_hypothesis_text(self, klass, val): - text = utils.yaml_dump(val).decode('utf-8') + text = utils.yaml_dump(val) try: klass().from_str(text) except configexc.ValidationError: @@ -746,7 +746,7 @@ class TestInt: @hypothesis.given(val=strategies.integers()) def test_hypothesis_text(self, klass, val): - text = utils.yaml_dump(val).decode('utf-8') + text = utils.yaml_dump(val) try: klass().from_str(text) except configexc.ValidationError: @@ -800,7 +800,7 @@ class TestFloat: @hypothesis.given(val=strategies.one_of(strategies.floats(), strategies.integers())) def test_hypothesis_text(self, klass, val): - text = utils.yaml_dump(val).decode('utf-8') + text = utils.yaml_dump(val) try: klass().from_str(text) except configexc.ValidationError: @@ -1305,7 +1305,7 @@ class TestDict: @hypothesis.given(val=strategies.dictionaries(strategies.booleans(), strategies.booleans())) def test_hypothesis_text(self, klass, val): - text = utils.yaml_dump(val).decode('utf-8') + text = utils.yaml_dump(val) d = klass(keytype=configtypes.Bool(), valtype=configtypes.Bool()) try: d.from_str(text) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index aff5b49b4..d5585c06e 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -943,4 +943,4 @@ def test_yaml_load(): def test_yaml_dump(): - assert utils.yaml_dump([1, 2]) == b'- 1\n- 2\n' + assert utils.yaml_dump([1, 2]) == '- 1\n- 2\n'