Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Jan 8, 2022
1 parent 34c0ab3 commit 9e960a5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_yaml_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import sys
import unittest
import logging
from ruamel.yaml import YAML

from jsonpatch import JsonPatch

from linkml_dataops.diffs.yaml_patch import YAMLPatch

inp = """\
# example
name:
# details
family: Smith # very common
given: Alice # one of the siblings
"""

yaml_patch = YAMLPatch()

class YamlPatchTestCase(unittest.TestCase):
"""
Tests yaml patching
"""

def test_patch(self):
"""
test patch works, preserving comments
"""
patch = JsonPatch([
{'op': 'add', 'path': '/foo', 'value': {'bar': 'baz'}},
{'op': 'remove', 'path': '/name/family'}
])
nu = yaml_patch.patchs(inp, patch)
assert '# example' in nu
assert '# details' in nu
assert '# one of the siblings' in nu
yaml=YAML()
obj = yaml.load(nu)
self.assertEqual(obj, {"name": {"given": "Alice"},
"foo": {"bar": "baz"}})






if __name__ == '__main__':
unittest.main()

0 comments on commit 9e960a5

Please sign in to comment.