~ubuntu-branches/ubuntu/trusty/python-babel/trusty

« back to all changes in this revision

Viewing changes to tests/test_localedata.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-28 10:11:31 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131028101131-zwbmm8sc29iemmlr
Tags: 1.3-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/rules: Run the testsuite during builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright (C) 2007-2011 Edgewall Software
 
4
# All rights reserved.
 
5
#
 
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.
 
9
#
 
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/.
 
13
 
 
14
import doctest
 
15
import unittest
 
16
 
 
17
from babel import localedata
 
18
 
 
19
 
 
20
class MergeResolveTestCase(unittest.TestCase):
 
21
 
 
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)
 
26
 
 
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)
 
31
        self.assertEqual({
 
32
            'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14}
 
33
        }, d1)
 
34
 
 
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)
 
39
        self.assertEqual({
 
40
            'x': {'a': 1, 'b': 2},
 
41
            'y': {'a': 11, 'b': 12}
 
42
        }, d1)
 
43
 
 
44
    def test_merge_with_alias_and_resolve(self):
 
45
        alias = localedata.Alias('x')
 
46
        d1 = {
 
47
            'x': {'a': 1, 'b': 2, 'c': 3},
 
48
            'y': alias
 
49
        }
 
50
        d2 = {
 
51
            'x': {'a': 1, 'b': 12, 'd': 14},
 
52
            'y': {'b': 22, 'e': 25}
 
53
        }
 
54
        localedata.merge(d1, d2)
 
55
        self.assertEqual({
 
56
            'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14},
 
57
            'y': (alias, {'b': 22, 'e': 25})
 
58
        }, d1)
 
59
        d = localedata.LocaleDataDict(d1)
 
60
        self.assertEqual({
 
61
            'x': {'a': 1, 'b': 12, 'c': 3, 'd': 14},
 
62
            'y': {'a': 1, 'b': 22, 'c': 3, 'd': 14, 'e': 25}
 
63
        }, dict(d.items()))
 
64
 
 
65
 
 
66
def test_load():
 
67
    assert localedata.load('en_US')['languages']['sv'] == 'Swedish'
 
68
    assert localedata.load('en_US') is localedata.load('en_US')
 
69
 
 
70
 
 
71
def test_merge():
 
72
    d = {1: 'foo', 3: 'baz'}
 
73
    localedata.merge(d, {1: 'Foo', 2: 'Bar'})
 
74
    assert d == {1: 'Foo', 2: 'Bar', 3: 'baz'}