diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-03-21 17:18:18 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-03-21 17:18:18 +0100 |
commit | 9ac44a0873d51d63150b0f1dc1d009b206577a29 (patch) | |
tree | 44fc2ecbdba2a6a63544097d7b9f63d8f87d5aae /_test/test_yamlobject.py | |
parent | c8568f99215aaa910953287f63a25459e3800dfc (diff) | |
download | ruamel.yaml-9ac44a0873d51d63150b0f1dc1d009b206577a29.tar.gz |
update for mypy --strict, prepare de-inheritance (Loader/Dumper)0.14.0
Diffstat (limited to '_test/test_yamlobject.py')
-rw-r--r-- | _test/test_yamlobject.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/_test/test_yamlobject.py b/_test/test_yamlobject.py new file mode 100644 index 0000000..a5e06d8 --- /dev/null +++ b/_test/test_yamlobject.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +import pytest # NOQA +import ruamel.yaml + +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA + + +class Monster(ruamel.yaml.YAMLObject): + yaml_tag = u'!Monster' + + def __init__(self, name, hp, ac, attacks): + self.name = name + self.hp = hp + self.ac = ac + self.attacks = attacks + + def __repr__(self): + return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % ( + self.__class__.__name__, self.name, self.hp, self.ac, self.attacks) + + +def test_monster(): + data = ruamel.yaml.load(dedent("""\ + --- !Monster + name: Cave spider + hp: [2,6] # 2d6 + ac: 16 + attacks: [BITE, HURT] + """), Loader=ruamel.yaml.Loader) + # normal dump, keys will be sorted + assert ruamel.yaml.dump(data) == dedent("""\ + !Monster + ac: 16 + attacks: [BITE, HURT] + hp: [2, 6] + name: Cave spider + """) |