mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 16:44:42 +04:00
Add ordered yaml load/dump
This commit is contained in:
parent
c695ee9a9a
commit
2699026908
2 changed files with 63 additions and 0 deletions
35
tests/yaml_extensions_test.py
Normal file
35
tests/yaml_extensions_test.py
Normal 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'
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue