Skip to content

Commit eb41d9c

Browse files
committed
Improved coverage by adding a dump/load to stream test
1 parent 60835e0 commit eb41d9c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

yamlable/tests/test_yamlable.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from copy import copy
2+
from io import StringIO
23
from typing import Dict, Any
34

45
import pytest
@@ -56,12 +57,25 @@ def from_yaml_dict(cls: 'Type[Y]', dct: Dict, yaml_tag: str) -> Y:
5657
y = f.dumps_yaml()
5758
assert y == "!yamlable/yaml.tests.Foo {a: 1, b: hello}\n"
5859

60+
# dump io
61+
class MemorizingStringIO(StringIO):
62+
""" A StringIO object that memorizes its buffer when it is closed (as opposed to the standard StringIO) """
63+
def close(self):
64+
self.value = self.getvalue()
65+
super(StringIO, self).close()
66+
s = MemorizingStringIO()
67+
f.dump_yaml(s)
68+
assert s.value == y
69+
5970
# dump pyyaml
6071
assert dump(f) == y
6172

6273
# load
6374
assert f == Foo.loads_yaml(y)
6475

76+
# load io
77+
assert f == Foo.load_yaml(StringIO(y))
78+
6579
# load pyyaml
6680
assert f == load(y)
6781

0 commit comments

Comments
 (0)