Mercurial > babel > mirror
annotate babel/tests/support.py @ 599:33c8c68b96c7 trunk
change constructor for babel.support.Translations to __init__(fp=None, domain=None) as its super class gettext.GNUTranslations uses "fp" as well (even if "fileobj" is a better name)
author | fschwarz |
---|---|
date | Mon, 20 Aug 2012 19:34:42 +0000 |
parents | 838ba3796ad6 |
children | 60f716236946 |
rev | line source |
---|---|
61
9d13b9a5d727
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 -*- |
9d13b9a5d727
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
9d13b9a5d727
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. |
9d13b9a5d727
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 # |
9d13b9a5d727
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 |
9d13b9a5d727
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 |
9d13b9a5d727
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. |
9d13b9a5d727
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 # |
9d13b9a5d727
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 |
9d13b9a5d727
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 |
9d13b9a5d727
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/. |
9d13b9a5d727
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 |
9d13b9a5d727
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 |
596
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
15 import inspect |
420 | 16 import os |
17 from StringIO import StringIO | |
61
9d13b9a5d727
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 import unittest |
9d13b9a5d727
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 |
9d13b9a5d727
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
|
20 from babel import support |
420 | 21 from babel.messages import Catalog |
22 from babel.messages.mofile import write_mo | |
23 | |
24 class TranslationsTestCase(unittest.TestCase): | |
25 | |
26 def setUp(self): | |
27 # Use a locale which won't fail to run the tests | |
28 os.environ['LANG'] = 'en_US.UTF-8' | |
29 messages1 = [ | |
30 ('foo', {'string': 'Voh'}), | |
31 ('foo', {'string': 'VohCTX', 'context': 'foo'}), | |
32 (('foo1', 'foos1'), {'string': ('Voh1', 'Vohs1')}), | |
33 (('foo1', 'foos1'), {'string': ('VohCTX1', 'VohsCTX1'), 'context': 'foo'}), | |
34 ] | |
35 messages2 = [ | |
36 ('foo', {'string': 'VohD'}), | |
37 ('foo', {'string': 'VohCTXD', 'context': 'foo'}), | |
38 (('foo1', 'foos1'), {'string': ('VohD1', 'VohsD1')}), | |
39 (('foo1', 'foos1'), {'string': ('VohCTXD1', 'VohsCTXD1'), 'context': 'foo'}), | |
40 ] | |
41 catalog1 = Catalog(locale='en_GB', domain='messages') | |
42 catalog2 = Catalog(locale='en_GB', domain='messages1') | |
43 for ids, kwargs in messages1: | |
44 catalog1.add(ids, **kwargs) | |
45 for ids, kwargs in messages2: | |
46 catalog2.add(ids, **kwargs) | |
47 catalog1_fp = StringIO() | |
48 catalog2_fp = StringIO() | |
49 write_mo(catalog1_fp, catalog1) | |
50 catalog1_fp.seek(0) | |
51 write_mo(catalog2_fp, catalog2) | |
52 catalog2_fp.seek(0) | |
53 translations1 = support.Translations(catalog1_fp) | |
54 translations2 = support.Translations(catalog2_fp, domain='messages1') | |
55 self.translations = translations1.add(translations2, merge=False) | |
56 | |
57 def assertEqualTypeToo(self, expected, result): | |
58 self.assertEqual(expected, result) | |
59 assert type(expected) == type(result), "instance type's do not " + \ | |
60 "match: %r!=%r" % (type(expected), type(result)) | |
61 | |
62 def test_pgettext(self): | |
63 self.assertEqualTypeToo('Voh', self.translations.gettext('foo')) | |
64 self.assertEqualTypeToo('VohCTX', self.translations.pgettext('foo', | |
65 'foo')) | |
66 | |
67 def test_upgettext(self): | |
68 self.assertEqualTypeToo(u'Voh', self.translations.ugettext('foo')) | |
69 self.assertEqualTypeToo(u'VohCTX', self.translations.upgettext('foo', | |
70 'foo')) | |
71 | |
72 def test_lpgettext(self): | |
73 self.assertEqualTypeToo('Voh', self.translations.lgettext('foo')) | |
74 self.assertEqualTypeToo('VohCTX', self.translations.lpgettext('foo', | |
75 'foo')) | |
76 | |
77 def test_npgettext(self): | |
78 self.assertEqualTypeToo('Voh1', | |
79 self.translations.ngettext('foo1', 'foos1', 1)) | |
80 self.assertEqualTypeToo('Vohs1', | |
81 self.translations.ngettext('foo1', 'foos1', 2)) | |
82 self.assertEqualTypeToo('VohCTX1', | |
83 self.translations.npgettext('foo', 'foo1', | |
84 'foos1', 1)) | |
85 self.assertEqualTypeToo('VohsCTX1', | |
86 self.translations.npgettext('foo', 'foo1', | |
87 'foos1', 2)) | |
88 | |
89 def test_unpgettext(self): | |
90 self.assertEqualTypeToo(u'Voh1', | |
91 self.translations.ungettext('foo1', 'foos1', 1)) | |
92 self.assertEqualTypeToo(u'Vohs1', | |
93 self.translations.ungettext('foo1', 'foos1', 2)) | |
94 self.assertEqualTypeToo(u'VohCTX1', | |
95 self.translations.unpgettext('foo', 'foo1', | |
96 'foos1', 1)) | |
97 self.assertEqualTypeToo(u'VohsCTX1', | |
98 self.translations.unpgettext('foo', 'foo1', | |
99 'foos1', 2)) | |
100 | |
101 def test_lnpgettext(self): | |
102 self.assertEqualTypeToo('Voh1', | |
103 self.translations.lngettext('foo1', 'foos1', 1)) | |
104 self.assertEqualTypeToo('Vohs1', | |
105 self.translations.lngettext('foo1', 'foos1', 2)) | |
106 self.assertEqualTypeToo('VohCTX1', | |
107 self.translations.lnpgettext('foo', 'foo1', | |
108 'foos1', 1)) | |
109 self.assertEqualTypeToo('VohsCTX1', | |
110 self.translations.lnpgettext('foo', 'foo1', | |
111 'foos1', 2)) | |
112 | |
113 def test_dpgettext(self): | |
114 self.assertEqualTypeToo( | |
115 'VohD', self.translations.dgettext('messages1', 'foo')) | |
116 self.assertEqualTypeToo( | |
117 'VohCTXD', self.translations.dpgettext('messages1', 'foo', 'foo')) | |
118 | |
119 def test_dupgettext(self): | |
120 self.assertEqualTypeToo( | |
121 u'VohD', self.translations.dugettext('messages1', 'foo')) | |
122 self.assertEqualTypeToo( | |
123 u'VohCTXD', self.translations.dupgettext('messages1', 'foo', 'foo')) | |
124 | |
125 def test_ldpgettext(self): | |
126 self.assertEqualTypeToo( | |
127 'VohD', self.translations.ldgettext('messages1', 'foo')) | |
128 self.assertEqualTypeToo( | |
129 'VohCTXD', self.translations.ldpgettext('messages1', 'foo', 'foo')) | |
130 | |
131 def test_dnpgettext(self): | |
132 self.assertEqualTypeToo( | |
133 'VohD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 1)) | |
134 self.assertEqualTypeToo( | |
135 'VohsD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 2)) | |
136 self.assertEqualTypeToo( | |
137 'VohCTXD1', self.translations.dnpgettext('messages1', 'foo', 'foo1', | |
138 'foos1', 1)) | |
139 self.assertEqualTypeToo( | |
140 'VohsCTXD1', self.translations.dnpgettext('messages1', 'foo', 'foo1', | |
141 'foos1', 2)) | |
142 | |
143 def test_dunpgettext(self): | |
144 self.assertEqualTypeToo( | |
145 u'VohD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 1)) | |
146 self.assertEqualTypeToo( | |
147 u'VohsD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 2)) | |
148 self.assertEqualTypeToo( | |
149 u'VohCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1', | |
150 'foos1', 1)) | |
151 self.assertEqualTypeToo( | |
152 u'VohsCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1', | |
153 'foos1', 2)) | |
154 | |
155 def test_ldnpgettext(self): | |
156 self.assertEqualTypeToo( | |
157 'VohD1', self.translations.ldngettext('messages1', 'foo1', 'foos1', 1)) | |
158 self.assertEqualTypeToo( | |
159 'VohsD1', self.translations.ldngettext('messages1', 'foo1', 'foos1', 2)) | |
160 self.assertEqualTypeToo( | |
161 'VohCTXD1', self.translations.ldnpgettext('messages1', 'foo', 'foo1', | |
162 'foos1', 1)) | |
163 self.assertEqualTypeToo( | |
164 'VohsCTXD1', self.translations.ldnpgettext('messages1', 'foo', 'foo1', | |
165 'foos1', 2)) | |
61
9d13b9a5d727
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 |
559
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
167 |
596
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
168 class NullTranslationsTestCase(unittest.TestCase): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
169 def setUp(self): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
170 fp = StringIO() |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
171 write_mo(fp, Catalog(locale='de')) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
172 fp.seek(0) |
599
33c8c68b96c7
change constructor for babel.support.Translations to __init__(fp=None, domain=None) as its super class gettext.GNUTranslations uses "fp" as well (even if "fileobj" is a better name)
fschwarz
parents:
598
diff
changeset
|
173 self.translations = support.Translations(fp=fp) |
596
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
174 self.null_translations = support.NullTranslations(fp=fp) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
175 |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
176 def method_names(self): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
177 return [name for name in dir(self.translations) if 'gettext' in name] |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
178 |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
179 def test_same_methods(self): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
180 for name in self.method_names(): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
181 if not hasattr(self.null_translations, name): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
182 self.fail('NullTranslations does not provide method %r' % name) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
183 |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
184 def test_method_signature_compatibility(self): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
185 for name in self.method_names(): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
186 translations_method = getattr(self.translations, name) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
187 null_method = getattr(self.null_translations, name) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
188 signature = inspect.getargspec |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
189 self.assertEqual(signature(translations_method), |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
190 signature(null_method)) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
191 |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
192 def test_same_return_values(self): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
193 data = { |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
194 'message': u'foo', 'domain': u'domain', 'context': 'tests', |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
195 'singular': u'bar', 'plural': u'baz', 'num': 1, |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
196 'msgid1': u'bar', 'msgid2': u'baz', 'n': 1, |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
197 } |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
198 for name in self.method_names(): |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
199 method = getattr(self.translations, name) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
200 null_method = getattr(self.null_translations, name) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
201 signature = inspect.getargspec(method) |
598
838ba3796ad6
fix tests on Python 2.4, named tuples are not available there
fschwarz
parents:
596
diff
changeset
|
202 parameter_names = [name for name in signature[0] if name != 'self'] |
596
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
203 values = [data[name] for name in parameter_names] |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
204 self.assertEqual(method(*values), null_method(*values)) |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
205 |
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
206 |
559
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
207 class LazyProxyTestCase(unittest.TestCase): |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
208 def test_proxy_caches_result_of_function_call(self): |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
209 self.counter = 0 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
210 def add_one(): |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
211 self.counter += 1 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
212 return self.counter |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
213 proxy = support.LazyProxy(add_one) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
214 self.assertEqual(1, proxy.value) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
215 self.assertEqual(1, proxy.value) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
216 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
217 def test_can_disable_proxy_cache(self): |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
218 self.counter = 0 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
219 def add_one(): |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
220 self.counter += 1 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
221 return self.counter |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
222 proxy = support.LazyProxy(add_one, enable_cache=False) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
223 self.assertEqual(1, proxy.value) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
224 self.assertEqual(2, proxy.value) |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
225 |
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
226 |
61
9d13b9a5d727
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
|
227 def suite(): |
9d13b9a5d727
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
|
228 suite = unittest.TestSuite() |
9d13b9a5d727
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
|
229 suite.addTest(doctest.DocTestSuite(support)) |
420 | 230 suite.addTest(unittest.makeSuite(TranslationsTestCase, 'test')) |
596
f63a07d648b6
add babel.support.NullTranslations class similar to gettext.NullTranslations but with all of Babel's new *gettext methods (#277)
fschwarz
parents:
559
diff
changeset
|
231 suite.addTest(unittest.makeSuite(NullTranslationsTestCase, 'test')) |
559
8831b754f81e
Allow disabling cache behaviour in LazyProxy (fixes #208, initial patch Pedro Algarvio)
fschwarz
parents:
530
diff
changeset
|
232 suite.addTest(unittest.makeSuite(LazyProxyTestCase, 'test')) |
61
9d13b9a5d727
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
|
233 return suite |
9d13b9a5d727
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
|
234 |
9d13b9a5d727
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
|
235 if __name__ == '__main__': |
9d13b9a5d727
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
|
236 unittest.main(defaultTest='suite') |