1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2007-2011 Edgewall Software
6
# This software is licensed as described in the file COPYING, which
7
# you should have received as part of this distribution. The terms
8
# are also available at http://babel.edgewall.org/wiki/License.
10
# This software consists of voluntary contributions made by many
11
# individuals. For the exact contribution history, see the revision
12
# history and logs, available at http://babel.edgewall.org/log/.
17
from babel import localedata
20
class MergeResolveTestCase(unittest.TestCase):
22
def test_merge_items(self):
23
d = {1: 'foo', 3: 'baz'}
24
localedata.merge(d, {1: 'Foo', 2: 'Bar'})
25
self.assertEqual({1: 'Foo', 2: 'Bar', 3: 'baz'}, d)
27
def test_merge_nested_dict(self):
28
d1 = {'x': {'a': 1, 'b': 2, 'c': 3}}
29
d2 = {'x': {'a': 1, 'b': 12, 'd': 14}}
30
localedata.merge(d1, d2)
32
'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14}
35
def test_merge_nested_dict_no_overlap(self):
36
d1 = {'x': {'a': 1, 'b': 2}}
37
d2 = {'y': {'a': 11, 'b': 12}}
38
localedata.merge(d1, d2)
40
'x': {'a': 1, 'b': 2},
41
'y': {'a': 11, 'b': 12}
44
def test_merge_with_alias_and_resolve(self):
45
alias = localedata.Alias('x')
47
'x': {'a': 1, 'b': 2, 'c': 3},
51
'x': {'a': 1, 'b': 12, 'd': 14},
52
'y': {'b': 22, 'e': 25}
54
localedata.merge(d1, d2)
56
'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14},
57
'y': (alias, {'b': 22, 'e': 25})
59
d = localedata.LocaleDataDict(d1)
61
'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14},
62
'y': {'a': 1, 'b': 22, 'c': 3, 'd': 14, 'e': 25}
67
assert localedata.load('en_US')['languages']['sv'] == 'Swedish'
68
assert localedata.load('en_US') is localedata.load('en_US')
72
d = {1: 'foo', 3: 'baz'}
73
localedata.merge(d, {1: 'Foo', 2: 'Bar'})
74
assert d == {1: 'Foo', 2: 'Bar', 3: 'baz'}