Mercurial > babel > old > babel-test
annotate babel/tests/support.py @ 530:85e1beadacb0
Update the copyright line.
author | jruigrok |
---|---|
date | Sat, 05 Mar 2011 15:22:28 +0000 |
parents | 53c68c594b5f |
children |
rev | line source |
---|---|
61
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
2 # |
530 | 3 # Copyright (C) 2007-2011 Edgewall Software |
61
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
5 # |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://babel.edgewall.org/wiki/License. |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
9 # |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://babel.edgewall.org/log/. |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
13 |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
14 import doctest |
420 | 15 import os |
16 from StringIO import StringIO | |
61
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
17 import unittest |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
18 |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
19 from babel import support |
420 | 20 from babel.messages import Catalog |
21 from babel.messages.mofile import write_mo | |
22 | |
23 class TranslationsTestCase(unittest.TestCase): | |
24 | |
25 def setUp(self): | |
26 # Use a locale which won't fail to run the tests | |
27 os.environ['LANG'] = 'en_US.UTF-8' | |
28 messages1 = [ | |
29 ('foo', {'string': 'Voh'}), | |
30 ('foo', {'string': 'VohCTX', 'context': 'foo'}), | |
31 (('foo1', 'foos1'), {'string': ('Voh1', 'Vohs1')}), | |
32 (('foo1', 'foos1'), {'string': ('VohCTX1', 'VohsCTX1'), 'context': 'foo'}), | |
33 ] | |
34 messages2 = [ | |
35 ('foo', {'string': 'VohD'}), | |
36 ('foo', {'string': 'VohCTXD', 'context': 'foo'}), | |
37 (('foo1', 'foos1'), {'string': ('VohD1', 'VohsD1')}), | |
38 (('foo1', 'foos1'), {'string': ('VohCTXD1', 'VohsCTXD1'), 'context': 'foo'}), | |
39 ] | |
40 catalog1 = Catalog(locale='en_GB', domain='messages') | |
41 catalog2 = Catalog(locale='en_GB', domain='messages1') | |
42 for ids, kwargs in messages1: | |
43 catalog1.add(ids, **kwargs) | |
44 for ids, kwargs in messages2: | |
45 catalog2.add(ids, **kwargs) | |
46 catalog1_fp = StringIO() | |
47 catalog2_fp = StringIO() | |
48 write_mo(catalog1_fp, catalog1) | |
49 catalog1_fp.seek(0) | |
50 write_mo(catalog2_fp, catalog2) | |
51 catalog2_fp.seek(0) | |
52 translations1 = support.Translations(catalog1_fp) | |
53 translations2 = support.Translations(catalog2_fp, domain='messages1') | |
54 self.translations = translations1.add(translations2, merge=False) | |
55 | |
56 def assertEqualTypeToo(self, expected, result): | |
57 self.assertEqual(expected, result) | |
58 assert type(expected) == type(result), "instance type's do not " + \ | |
59 "match: %r!=%r" % (type(expected), type(result)) | |
60 | |
61 def test_pgettext(self): | |
62 self.assertEqualTypeToo('Voh', self.translations.gettext('foo')) | |
63 self.assertEqualTypeToo('VohCTX', self.translations.pgettext('foo', | |
64 'foo')) | |
65 | |
66 def test_upgettext(self): | |
67 self.assertEqualTypeToo(u'Voh', self.translations.ugettext('foo')) | |
68 self.assertEqualTypeToo(u'VohCTX', self.translations.upgettext('foo', | |
69 'foo')) | |
70 | |
71 def test_lpgettext(self): | |
72 self.assertEqualTypeToo('Voh', self.translations.lgettext('foo')) | |
73 self.assertEqualTypeToo('VohCTX', self.translations.lpgettext('foo', | |
74 'foo')) | |
75 | |
76 def test_npgettext(self): | |
77 self.assertEqualTypeToo('Voh1', | |
78 self.translations.ngettext('foo1', 'foos1', 1)) | |
79 self.assertEqualTypeToo('Vohs1', | |
80 self.translations.ngettext('foo1', 'foos1', 2)) | |
81 self.assertEqualTypeToo('VohCTX1', | |
82 self.translations.npgettext('foo', 'foo1', | |
83 'foos1', 1)) | |
84 self.assertEqualTypeToo('VohsCTX1', | |
85 self.translations.npgettext('foo', 'foo1', | |
86 'foos1', 2)) | |
87 | |
88 def test_unpgettext(self): | |
89 self.assertEqualTypeToo(u'Voh1', | |
90 self.translations.ungettext('foo1', 'foos1', 1)) | |
91 self.assertEqualTypeToo(u'Vohs1', | |
92 self.translations.ungettext('foo1', 'foos1', 2)) | |
93 self.assertEqualTypeToo(u'VohCTX1', | |
94 self.translations.unpgettext('foo', 'foo1', | |
95 'foos1', 1)) | |
96 self.assertEqualTypeToo(u'VohsCTX1', | |
97 self.translations.unpgettext('foo', 'foo1', | |
98 'foos1', 2)) | |
99 | |
100 def test_lnpgettext(self): | |
101 self.assertEqualTypeToo('Voh1', | |
102 self.translations.lngettext('foo1', 'foos1', 1)) | |
103 self.assertEqualTypeToo('Vohs1', | |
104 self.translations.lngettext('foo1', 'foos1', 2)) | |
105 self.assertEqualTypeToo('VohCTX1', | |
106 self.translations.lnpgettext('foo', 'foo1', | |
107 'foos1', 1)) | |
108 self.assertEqualTypeToo('VohsCTX1', | |
109 self.translations.lnpgettext('foo', 'foo1', | |
110 'foos1', 2)) | |
111 | |
112 def test_dpgettext(self): | |
113 self.assertEqualTypeToo( | |
114 'VohD', self.translations.dgettext('messages1', 'foo')) | |
115 self.assertEqualTypeToo( | |
116 'VohCTXD', self.translations.dpgettext('messages1', 'foo', 'foo')) | |
117 | |
118 def test_dupgettext(self): | |
119 self.assertEqualTypeToo( | |
120 u'VohD', self.translations.dugettext('messages1', 'foo')) | |
121 self.assertEqualTypeToo( | |
122 u'VohCTXD', self.translations.dupgettext('messages1', 'foo', 'foo')) | |
123 | |
124 def test_ldpgettext(self): | |
125 self.assertEqualTypeToo( | |
126 'VohD', self.translations.ldgettext('messages1', 'foo')) | |
127 self.assertEqualTypeToo( | |
128 'VohCTXD', self.translations.ldpgettext('messages1', 'foo', 'foo')) | |
129 | |
130 def test_dnpgettext(self): | |
131 self.assertEqualTypeToo( | |
132 'VohD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 1)) | |
133 self.assertEqualTypeToo( | |
134 'VohsD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 2)) | |
135 self.assertEqualTypeToo( | |
136 'VohCTXD1', self.translations.dnpgettext('messages1', 'foo', 'foo1', | |
137 'foos1', 1)) | |
138 self.assertEqualTypeToo( | |
139 'VohsCTXD1', self.translations.dnpgettext('messages1', 'foo', 'foo1', | |
140 'foos1', 2)) | |
141 | |
142 def test_dunpgettext(self): | |
143 self.assertEqualTypeToo( | |
144 u'VohD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 1)) | |
145 self.assertEqualTypeToo( | |
146 u'VohsD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 2)) | |
147 self.assertEqualTypeToo( | |
148 u'VohCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1', | |
149 'foos1', 1)) | |
150 self.assertEqualTypeToo( | |
151 u'VohsCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1', | |
152 'foos1', 2)) | |
153 | |
154 def test_ldnpgettext(self): | |
155 self.assertEqualTypeToo( | |
156 'VohD1', self.translations.ldngettext('messages1', 'foo1', 'foos1', 1)) | |
157 self.assertEqualTypeToo( | |
158 'VohsD1', self.translations.ldngettext('messages1', 'foo1', 'foos1', 2)) | |
159 self.assertEqualTypeToo( | |
160 'VohCTXD1', self.translations.ldnpgettext('messages1', 'foo', 'foo1', | |
161 'foos1', 1)) | |
162 self.assertEqualTypeToo( | |
163 'VohsCTXD1', self.translations.ldnpgettext('messages1', 'foo', 'foo1', | |
164 'foos1', 2)) | |
61
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
165 |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
166 def suite(): |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
167 suite = unittest.TestSuite() |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
168 suite.addTest(doctest.DocTestSuite(support)) |
420 | 169 suite.addTest(unittest.makeSuite(TranslationsTestCase, 'test')) |
61
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
170 return suite |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
171 |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
172 if __name__ == '__main__': |
da7efa40a9e2
Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff
changeset
|
173 unittest.main(defaultTest='suite') |