Beispiel #1
0
    def test_can_merge_values_into_a_default_dict(self):
        def subdict(**kwargs):
            subdict = coll.defaultdict(int)
            for key, value in kwargs.items():
                subdict[key] = value
            return subdict

        a = {'a': {'a': 1, 'b': subdict()}}
        b = {'a': {'b': {'c': 5}}}
        ans = {'a': {'a': 1, 'b': subdict(c=5)}}
        assert config.merge(a, b) == ans
        assert config.merge(b, a) == ans
Beispiel #2
0
 def test_will_preserve_a_default_dict(self):
     a = {'a': {'a': 1}}
     b = {'a': {'b': coll.defaultdict(int)}}
     ans = {'a': {'a': 1, 'b': coll.defaultdict(int)}}
     assert config.merge(a, b) == ans
     assert config.merge(b, a) == ans
Beispiel #3
0
 def will_merge_both_directions(self):
     a = {'a': {'a': {'c': 1}}}
     b = {'a': {'a': {'d': 1}, 'b': 3}}
     assert config.merge(a, b) == {'a': {'a': {'c': 1}, 'b': 3}}
     assert config.merge(b, a) == {'a': {'a': {'c': 1}, 'b': 3}}
Beispiel #4
0
 def test_converts_value_to_str(self):
     a = {'a': {'a': u'1'}}
     b = {'a': {'b': u'2'}}
     val = config.merge(a, b)
     self.assertTrue(isinstance(val['a']['b'], str))
Beispiel #5
0
 def test_can_recursively_merge(self):
     a = {'a': {'a': 1}, 'c': 3}
     b = {'a': {'b': 2}, 'd': [1, 2, 3]}
     val = config.merge(a, b)
     ans = {'a': {'a': 1, 'b': 2}, 'c': 3, 'd': [1, 2, 3]}
     self.assertEquals(ans, val)
Beispiel #6
0
 def test_can_merge_two_dicts(self):
     a = {'c': 3}
     b = {'d': [1, 2, 3]}
     val = config.merge(a, b)
     ans = {'c': 3, 'd': [1, 2, 3]}
     self.assertEquals(ans, val)