Пример #1
0
    def test_deep_merge(self):
        a = {
            'first': {
                'second': {
                    'key': 'value',
                    'otherkey': 'othervalue'
                },
                'key': 'value'
            }
        }
        b = {
            'first': {
                'second': {
                    'otherkey': 'newvalue',
                    'yetanotherkey': 'yetanothervalue'
                }
            }
        }
        deep_merge(a, b)

        expected = {
            'first': {
                'second': {
                    'key': 'value',
                    'otherkey': 'newvalue',
                    'yetanotherkey': 'yetanothervalue'
                },
                'key': 'value'
            }
        }
        self.assertEqual(a, expected)
Пример #2
0
 def test_merge_list(self):
     # Lists are treated as opaque data and so no effort should be made to
     # combine them.
     a = {'key': ['original']}
     b = {'key': ['new']}
     deep_merge(a, b)
     self.assertEqual(a, {'key': ['new']})
Пример #3
0
    def test_simple_merge(self):
        a = {'key': 'value'}
        b = {'otherkey': 'othervalue'}
        deep_merge(a, b)

        expected = {'key': 'value', 'otherkey': 'othervalue'}
        self.assertEqual(a, expected)
Пример #4
0
    def test_merge_overrides_value(self):
        # The value from b is always taken, even when it's a different type
        a = {'key': 'original'}
        b = {'key': {'newkey': 'newvalue'}}
        deep_merge(a, b)
        self.assertEqual(a, {'key': {'newkey': 'newvalue'}})

        a = {'key': {'anotherkey': 'value'}}
        b = {'key': 'newvalue'}
        deep_merge(a, b)
        self.assertEqual(a, {'key': 'newvalue'})
Пример #5
0
    def test_merge_boolean(self):
        # The value from b is always taken
        a = {'key': False}
        b = {'key': True}
        deep_merge(a, b)
        self.assertEqual(a, {'key': True})

        a = {'key': True}
        b = {'key': False}
        deep_merge(a, b)
        self.assertEqual(a, {'key': False})
Пример #6
0
    def test_merge_number(self):
        # The value from b is always taken
        a = {'key': 10}
        b = {'key': 45}
        deep_merge(a, b)
        self.assertEqual(a, {'key': 45})

        a = {'key': 45}
        b = {'key': 10}
        deep_merge(a, b)
        self.assertEqual(a, {'key': 10})
Пример #7
0
 def call(self, context):
     deep_merge(self.source_copy, context)
     return self.source_copy
Пример #8
0
 def test_merge_none_deletes_from_base(self):
     a = {'key': 'value', 'other': 'value'}
     b = {'other': None}
     deep_merge(a, b)
     self.assertEqual(a, {'key': 'value'})
Пример #9
0
 def test_merge_when_no_extra(self):
     a = {'key': 'value'}
     b = None
     deep_merge(a, b)
     self.assertEqual(a, {'key': 'value'})
Пример #10
0
 def test_merge_string(self):
     a = {'key': 'value'}
     b = {'key': 'othervalue'}
     deep_merge(a, b)
     self.assertEqual(a, {'key': 'othervalue'})
Пример #11
0
 def call(initial_context, request_context):
     source_copy = clone(initial_context)
     deep_merge(source_copy, request_context)
     return source_copy