Handle files correctly in utils.yaml_dump
This commit is contained in:
parent
001312ca82
commit
6733e92b50
@ -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')
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user