diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 632773b7f..f6b1d5a9f 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -895,4 +895,7 @@ def yaml_dump(data, f=None): """ yaml_data = yaml.dump(data, f, Dumper=YamlDumper, default_flow_style=False, encoding='utf-8', allow_unicode=True) - return yaml_data.decode('utf-8') + if yaml_data is None: + return None + else: + return yaml_data.decode('utf-8') diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index d5585c06e..4bec8f57c 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -938,9 +938,22 @@ def test_expand_windows_drive(path, expected): assert utils.expand_windows_drive(path) == expected -def test_yaml_load(): - assert utils.yaml_load("[1, 2]") == [1, 2] +class TestYaml: + def test_load(self): + assert utils.yaml_load("[1, 2]") == [1, 2] -def test_yaml_dump(): - assert utils.yaml_dump([1, 2]) == '- 1\n- 2\n' + def test_load_file(self, tmpdir): + tmpfile = tmpdir / 'foo.yml' + tmpfile.write('[1, 2]') + with tmpfile.open(encoding='utf-8') as f: + assert utils.yaml_load(f) == [1, 2] + + def test_dump(self): + assert utils.yaml_dump([1, 2]) == '- 1\n- 2\n' + + def test_dump_file(self, tmpdir): + tmpfile = tmpdir / 'foo.yml' + with tmpfile.open('w', encoding='utf-8') as f: + utils.yaml_dump([1, 2], f) + assert tmpfile.read() == '- 1\n- 2\n'