Add ordered yaml load/dump

This commit is contained in:
Anthony Sottile 2014-03-23 20:06:03 -07:00
parent c695ee9a9a
commit 2699026908
2 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,35 @@
from pre_commit.ordereddict import OrderedDict
from pre_commit.yaml_extensions import ordered_dump
from pre_commit.yaml_extensions import ordered_load
def test_ordered_load():
ret = ordered_load(
'a: herp\n'
'c: derp\n'
'd: darp\n'
'b: harp\n'
)
# Original behavior
assert ret == {'a': 'herp', 'b': 'harp', 'c': 'derp', 'd': 'darp'}
# Ordered behavior
assert (
ret.items() ==
[('a', 'herp'), ('c', 'derp'), ('d', 'darp'), ('b', 'harp')]
)
def test_ordered_dump():
ret = ordered_dump(
OrderedDict(
(('a', 'herp'), ('c', 'derp'), ('b', 'harp'), ('d', 'darp'))
),
default_flow_style=False,
)
assert ret == (
'a: herp\n'
'c: derp\n'
'b: harp\n'
'd: darp\n'
)