Skip to content

Commit

Permalink
Merge 84cc48f into 9d676bf
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Apr 23, 2018
2 parents 9d676bf + 84cc48f commit f8395bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions oyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def map_constructor(loader, node):

pyyaml.add_representer(dict, map_representer)
pyyaml.add_representer(OrderedDict, map_representer)
pyyaml.add_representer(dict, map_representer, Dumper=pyyaml.dumper.SafeDumper)
pyyaml.add_representer(OrderedDict, map_representer, Dumper=pyyaml.dumper.SafeDumper)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='oyaml',
version='0.3',
version='0.4',
description='Ordered YAML: drop-in replacement for PyYAML which preserves dict ordering',
long_description=open('README.rst').read(),
author='Wim Glenn',
Expand Down
9 changes: 7 additions & 2 deletions test_oyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from types import GeneratorType

import pytest
from yaml.representer import RepresenterError

import oyaml as yaml

Expand All @@ -23,6 +22,12 @@ def test_dump_all():
assert yaml.dump_all(documents=[data, {}]) == '{x: 1, z: 3, y: 2}\n--- {}\n'


def test_dump_and_safe_dump_match():
mydict = {'x': 1, 'z': 2, 'y': 3}
# don't know if mydict is ordered in the implementation or not (but don't care)
assert yaml.dump(mydict) == yaml.safe_dump(mydict)


def test_safe_dump_all():
assert yaml.safe_dump_all(documents=[data, {}]) == '{x: 1, z: 3, y: 2}\n--- {}\n'

Expand Down Expand Up @@ -60,7 +65,7 @@ class MyOrderedDict(OrderedDict):

data = MyOrderedDict([('x', 1), ('y', 2)])
assert '!!python/object/apply:test_oyaml.MyOrderedDict' in yaml.dump(data)
with pytest.raises(RepresenterError) as cm:
with pytest.raises(yaml.pyyaml.representer.RepresenterError) as cm:
yaml.safe_dump(data)
assert str(cm.value) == "cannot represent an object: MyOrderedDict([('x', 1), ('y', 2)])"

Expand Down

0 comments on commit f8395bd

Please sign in to comment.