mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-09 17:55:48 +00:00
0892db6fa7
git-subtree-dir: SpiffWorkflow git-subtree-split: 63db3e45947ec66b8d0efc2c74064004f8ff482c
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
from SpiffWorkflow.util.deep_merge import DeepMerge
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
|
|
|
from .TaskSpecTest import TaskSpecTest
|
|
|
|
|
|
class DeepMergeTest(TaskSpecTest):
|
|
CORRELATE = DeepMerge
|
|
|
|
def testBasicMerge(self):
|
|
"""
|
|
Tests that we can merge one dictionary into another dictionary deeply
|
|
and that dot-notation is correctly parsed and processed.
|
|
"""
|
|
a = {"fruit": {"apples": "tasty"}}
|
|
b = {"fruit": {"oranges": "also tasty"}}
|
|
c = DeepMerge.merge(a, b)
|
|
self.assertEqual({"fruit":
|
|
{"apples": "tasty",
|
|
"oranges": "also tasty"
|
|
}
|
|
}, c)
|
|
|
|
|
|
def testOutOfOrderMerge(self):
|
|
a = {"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}}]}
|
|
b = {"foods": [{"fruit": {"oranges": "also tasty", "apples": "tasty"}},
|
|
{"canned meats": {"spam": "nope."}}]}
|
|
c = DeepMerge.merge(a, b)
|
|
self.assertEqual({"foods": [
|
|
{"fruit":
|
|
{"apples": "tasty",
|
|
"oranges": "also tasty"
|
|
}
|
|
},
|
|
{"canned meats":
|
|
{"spam": "nope."}
|
|
}
|
|
]}, c)
|
|
|
|
def testMixOfArrayTypes(self):
|
|
a = {"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}},
|
|
{"canned_meats":["spam", "more spam"]}]}
|
|
b = {"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}},
|
|
{"canned_meats":["wonderful spam", "spam", "more spam"]}]}
|
|
|
|
c = DeepMerge.merge(a, b)
|
|
|
|
self.assertEqual({"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}},
|
|
{"canned_meats":["spam", "more spam", "wonderful spam"]}]}, c)
|
|
|
|
def testRemovingItemsFromArrays(self):
|
|
a = {"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}},
|
|
{"canned_meats":["spam", "more spam"]}]}
|
|
b = {"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}}]}
|
|
|
|
c = DeepMerge.merge(a, b)
|
|
|
|
self.assertEqual({"foods": [{"fruit": {"apples": "tasty", "oranges": "also tasty"}}]}, c)
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(DeepMergeTest)
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|