Make utils.yaml_dump return str
This commit is contained in:
parent
05dc94ccc4
commit
dfee857466
@ -889,6 +889,10 @@ def yaml_load(f):
|
|||||||
|
|
||||||
|
|
||||||
def yaml_dump(data, f=None):
|
def yaml_dump(data, f=None):
|
||||||
"""Wrapper over yaml.dump using the C dumper if possible."""
|
"""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)
|
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')
|
||||||
|
@ -531,7 +531,7 @@ class TestList:
|
|||||||
|
|
||||||
@hypothesis.given(val=strategies.lists(strategies.just('foo')))
|
@hypothesis.given(val=strategies.lists(strategies.just('foo')))
|
||||||
def test_hypothesis_text(self, klass, val):
|
def test_hypothesis_text(self, klass, val):
|
||||||
text = utils.yaml_dump(val).decode('utf-8')
|
text = utils.yaml_dump(val)
|
||||||
try:
|
try:
|
||||||
klass().from_str(text)
|
klass().from_str(text)
|
||||||
except configexc.ValidationError:
|
except configexc.ValidationError:
|
||||||
@ -746,7 +746,7 @@ class TestInt:
|
|||||||
|
|
||||||
@hypothesis.given(val=strategies.integers())
|
@hypothesis.given(val=strategies.integers())
|
||||||
def test_hypothesis_text(self, klass, val):
|
def test_hypothesis_text(self, klass, val):
|
||||||
text = utils.yaml_dump(val).decode('utf-8')
|
text = utils.yaml_dump(val)
|
||||||
try:
|
try:
|
||||||
klass().from_str(text)
|
klass().from_str(text)
|
||||||
except configexc.ValidationError:
|
except configexc.ValidationError:
|
||||||
@ -800,7 +800,7 @@ class TestFloat:
|
|||||||
@hypothesis.given(val=strategies.one_of(strategies.floats(),
|
@hypothesis.given(val=strategies.one_of(strategies.floats(),
|
||||||
strategies.integers()))
|
strategies.integers()))
|
||||||
def test_hypothesis_text(self, klass, val):
|
def test_hypothesis_text(self, klass, val):
|
||||||
text = utils.yaml_dump(val).decode('utf-8')
|
text = utils.yaml_dump(val)
|
||||||
try:
|
try:
|
||||||
klass().from_str(text)
|
klass().from_str(text)
|
||||||
except configexc.ValidationError:
|
except configexc.ValidationError:
|
||||||
@ -1305,7 +1305,7 @@ class TestDict:
|
|||||||
@hypothesis.given(val=strategies.dictionaries(strategies.booleans(),
|
@hypothesis.given(val=strategies.dictionaries(strategies.booleans(),
|
||||||
strategies.booleans()))
|
strategies.booleans()))
|
||||||
def test_hypothesis_text(self, klass, val):
|
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())
|
d = klass(keytype=configtypes.Bool(), valtype=configtypes.Bool())
|
||||||
try:
|
try:
|
||||||
d.from_str(text)
|
d.from_str(text)
|
||||||
|
@ -943,4 +943,4 @@ def test_yaml_load():
|
|||||||
|
|
||||||
|
|
||||||
def test_yaml_dump():
|
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'
|
||||||
|
Loading…
Reference in New Issue
Block a user