@@ -141,18 +141,9 @@ class BaseFormattingTest(object):
141
141
# Utility functions for formatting tests
142
142
#
143
143
144
- def _test_formatfunc (self , format , value , out , func , ** format_opts ):
145
- self .assertEqual (
146
- func (format , value , ** format_opts ), out )
147
-
148
- def _test_format (self , format , value , out , ** format_opts ):
149
- with check_warnings (('' , DeprecationWarning )):
150
- self ._test_formatfunc (format , value , out ,
151
- func = locale .format , ** format_opts )
152
-
153
144
def _test_format_string (self , format , value , out , ** format_opts ):
154
- self ._test_formatfunc ( format , value , out ,
155
- func = locale .format_string , ** format_opts )
145
+ self .assertEqual (
146
+ locale .format_string ( format , value , ** format_opts ), out )
156
147
157
148
def _test_currency (self , value , out , ** format_opts ):
158
149
self .assertEqual (locale .currency (value , ** format_opts ), out )
@@ -166,44 +157,40 @@ def setUp(self):
166
157
self .sep = locale .localeconv ()['thousands_sep' ]
167
158
168
159
def test_grouping (self ):
169
- self ._test_format ("%f" , 1024 , grouping = 1 , out = '1%s024.000000' % self .sep )
170
- self ._test_format ("%f" , 102 , grouping = 1 , out = '102.000000' )
171
- self ._test_format ("%f" , - 42 , grouping = 1 , out = '-42.000000' )
172
- self ._test_format ("%+f" , - 42 , grouping = 1 , out = '-42.000000' )
160
+ self ._test_format_string ("%f" , 1024 , grouping = 1 , out = '1%s024.000000' % self .sep )
161
+ self ._test_format_string ("%f" , 102 , grouping = 1 , out = '102.000000' )
162
+ self ._test_format_string ("%f" , - 42 , grouping = 1 , out = '-42.000000' )
163
+ self ._test_format_string ("%+f" , - 42 , grouping = 1 , out = '-42.000000' )
173
164
174
165
def test_grouping_and_padding (self ):
175
- self ._test_format ("%20.f" , - 42 , grouping = 1 , out = '-42' .rjust (20 ))
166
+ self ._test_format_string ("%20.f" , - 42 , grouping = 1 , out = '-42' .rjust (20 ))
176
167
if self .sep :
177
- self ._test_format ("%+10.f" , - 4200 , grouping = 1 ,
168
+ self ._test_format_string ("%+10.f" , - 4200 , grouping = 1 ,
178
169
out = ('-4%s200' % self .sep ).rjust (10 ))
179
- self ._test_format ("%-10.f" , - 4200 , grouping = 1 ,
170
+ self ._test_format_string ("%-10.f" , - 4200 , grouping = 1 ,
180
171
out = ('-4%s200' % self .sep ).ljust (10 ))
181
172
182
173
def test_integer_grouping (self ):
183
- self ._test_format ("%d" , 4200 , grouping = True , out = '4%s200' % self .sep )
184
- self ._test_format ("%+d" , 4200 , grouping = True , out = '+4%s200' % self .sep )
185
- self ._test_format ("%+d" , - 4200 , grouping = True , out = '-4%s200' % self .sep )
174
+ self ._test_format_string ("%d" , 4200 , grouping = True , out = '4%s200' % self .sep )
175
+ self ._test_format_string ("%+d" , 4200 , grouping = True , out = '+4%s200' % self .sep )
176
+ self ._test_format_string ("%+d" , - 4200 , grouping = True , out = '-4%s200' % self .sep )
186
177
187
178
def test_integer_grouping_and_padding (self ):
188
- self ._test_format ("%10d" , 4200 , grouping = True ,
179
+ self ._test_format_string ("%10d" , 4200 , grouping = True ,
189
180
out = ('4%s200' % self .sep ).rjust (10 ))
190
- self ._test_format ("%-10d" , - 4200 , grouping = True ,
181
+ self ._test_format_string ("%-10d" , - 4200 , grouping = True ,
191
182
out = ('-4%s200' % self .sep ).ljust (10 ))
192
183
193
184
def test_simple (self ):
194
- self ._test_format ("%f" , 1024 , grouping = 0 , out = '1024.000000' )
195
- self ._test_format ("%f" , 102 , grouping = 0 , out = '102.000000' )
196
- self ._test_format ("%f" , - 42 , grouping = 0 , out = '-42.000000' )
197
- self ._test_format ("%+f" , - 42 , grouping = 0 , out = '-42.000000' )
185
+ self ._test_format_string ("%f" , 1024 , grouping = 0 , out = '1024.000000' )
186
+ self ._test_format_string ("%f" , 102 , grouping = 0 , out = '102.000000' )
187
+ self ._test_format_string ("%f" , - 42 , grouping = 0 , out = '-42.000000' )
188
+ self ._test_format_string ("%+f" , - 42 , grouping = 0 , out = '-42.000000' )
198
189
199
190
def test_padding (self ):
200
- self ._test_format ("%20.f" , - 42 , grouping = 0 , out = '-42' .rjust (20 ))
201
- self ._test_format ("%+10.f" , - 4200 , grouping = 0 , out = '-4200' .rjust (10 ))
202
- self ._test_format ("%-10.f" , 4200 , grouping = 0 , out = '4200' .ljust (10 ))
203
-
204
- def test_format_deprecation (self ):
205
- with self .assertWarns (DeprecationWarning ):
206
- locale .format ("%-10.f" , 4200 , grouping = True )
191
+ self ._test_format_string ("%20.f" , - 42 , grouping = 0 , out = '-42' .rjust (20 ))
192
+ self ._test_format_string ("%+10.f" , - 4200 , grouping = 0 , out = '-4200' .rjust (10 ))
193
+ self ._test_format_string ("%-10.f" , 4200 , grouping = 0 , out = '4200' .ljust (10 ))
207
194
208
195
def test_complex_formatting (self ):
209
196
# Spaces in formatting string
@@ -230,20 +217,9 @@ def test_complex_formatting(self):
230
217
out = 'int 1%s000 float 1%s000.00 str str' %
231
218
(self .sep , self .sep ))
232
219
233
-
234
- class TestFormatPatternArg (unittest .TestCase ):
235
- # Test handling of pattern argument of format
236
-
237
- def test_onlyOnePattern (self ):
238
- with check_warnings (('' , DeprecationWarning )):
239
- # Issue 2522: accept exactly one % pattern, and no extra chars.
240
- self .assertRaises (ValueError , locale .format , "%f\n " , 'foo' )
241
- self .assertRaises (ValueError , locale .format , "%f\r " , 'foo' )
242
- self .assertRaises (ValueError , locale .format , "%f\r \n " , 'foo' )
243
- self .assertRaises (ValueError , locale .format , " %f" , 'foo' )
244
- self .assertRaises (ValueError , locale .format , "%fg" , 'foo' )
245
- self .assertRaises (ValueError , locale .format , "%^g" , 'foo' )
246
- self .assertRaises (ValueError , locale .format , "%f%%" , 'foo' )
220
+ self ._test_format_string ("total=%i%%" , 100 , out = 'total=100%' )
221
+ self ._test_format_string ("newline: %i\n " , 3 , out = 'newline: 3\n ' )
222
+ self ._test_format_string ("extra: %ii" , 3 , out = 'extra: 3i' )
247
223
248
224
249
225
class TestLocaleFormatString (unittest .TestCase ):
@@ -292,45 +268,45 @@ class TestCNumberFormatting(CCookedTest, BaseFormattingTest):
292
268
# Test number formatting with a cooked "C" locale.
293
269
294
270
def test_grouping (self ):
295
- self ._test_format ("%.2f" , 12345.67 , grouping = True , out = '12345.67' )
271
+ self ._test_format_string ("%.2f" , 12345.67 , grouping = True , out = '12345.67' )
296
272
297
273
def test_grouping_and_padding (self ):
298
- self ._test_format ("%9.2f" , 12345.67 , grouping = True , out = ' 12345.67' )
274
+ self ._test_format_string ("%9.2f" , 12345.67 , grouping = True , out = ' 12345.67' )
299
275
300
276
301
277
class TestFrFRNumberFormatting (FrFRCookedTest , BaseFormattingTest ):
302
278
# Test number formatting with a cooked "fr_FR" locale.
303
279
304
280
def test_decimal_point (self ):
305
- self ._test_format ("%.2f" , 12345.67 , out = '12345,67' )
281
+ self ._test_format_string ("%.2f" , 12345.67 , out = '12345,67' )
306
282
307
283
def test_grouping (self ):
308
- self ._test_format ("%.2f" , 345.67 , grouping = True , out = '345,67' )
309
- self ._test_format ("%.2f" , 12345.67 , grouping = True , out = '12 345,67' )
284
+ self ._test_format_string ("%.2f" , 345.67 , grouping = True , out = '345,67' )
285
+ self ._test_format_string ("%.2f" , 12345.67 , grouping = True , out = '12 345,67' )
310
286
311
287
def test_grouping_and_padding (self ):
312
- self ._test_format ("%6.2f" , 345.67 , grouping = True , out = '345,67' )
313
- self ._test_format ("%7.2f" , 345.67 , grouping = True , out = ' 345,67' )
314
- self ._test_format ("%8.2f" , 12345.67 , grouping = True , out = '12 345,67' )
315
- self ._test_format ("%9.2f" , 12345.67 , grouping = True , out = '12 345,67' )
316
- self ._test_format ("%10.2f" , 12345.67 , grouping = True , out = ' 12 345,67' )
317
- self ._test_format ("%-6.2f" , 345.67 , grouping = True , out = '345,67' )
318
- self ._test_format ("%-7.2f" , 345.67 , grouping = True , out = '345,67 ' )
319
- self ._test_format ("%-8.2f" , 12345.67 , grouping = True , out = '12 345,67' )
320
- self ._test_format ("%-9.2f" , 12345.67 , grouping = True , out = '12 345,67' )
321
- self ._test_format ("%-10.2f" , 12345.67 , grouping = True , out = '12 345,67 ' )
288
+ self ._test_format_string ("%6.2f" , 345.67 , grouping = True , out = '345,67' )
289
+ self ._test_format_string ("%7.2f" , 345.67 , grouping = True , out = ' 345,67' )
290
+ self ._test_format_string ("%8.2f" , 12345.67 , grouping = True , out = '12 345,67' )
291
+ self ._test_format_string ("%9.2f" , 12345.67 , grouping = True , out = '12 345,67' )
292
+ self ._test_format_string ("%10.2f" , 12345.67 , grouping = True , out = ' 12 345,67' )
293
+ self ._test_format_string ("%-6.2f" , 345.67 , grouping = True , out = '345,67' )
294
+ self ._test_format_string ("%-7.2f" , 345.67 , grouping = True , out = '345,67 ' )
295
+ self ._test_format_string ("%-8.2f" , 12345.67 , grouping = True , out = '12 345,67' )
296
+ self ._test_format_string ("%-9.2f" , 12345.67 , grouping = True , out = '12 345,67' )
297
+ self ._test_format_string ("%-10.2f" , 12345.67 , grouping = True , out = '12 345,67 ' )
322
298
323
299
def test_integer_grouping (self ):
324
- self ._test_format ("%d" , 200 , grouping = True , out = '200' )
325
- self ._test_format ("%d" , 4200 , grouping = True , out = '4 200' )
300
+ self ._test_format_string ("%d" , 200 , grouping = True , out = '200' )
301
+ self ._test_format_string ("%d" , 4200 , grouping = True , out = '4 200' )
326
302
327
303
def test_integer_grouping_and_padding (self ):
328
- self ._test_format ("%4d" , 4200 , grouping = True , out = '4 200' )
329
- self ._test_format ("%5d" , 4200 , grouping = True , out = '4 200' )
330
- self ._test_format ("%10d" , 4200 , grouping = True , out = '4 200' .rjust (10 ))
331
- self ._test_format ("%-4d" , 4200 , grouping = True , out = '4 200' )
332
- self ._test_format ("%-5d" , 4200 , grouping = True , out = '4 200' )
333
- self ._test_format ("%-10d" , 4200 , grouping = True , out = '4 200' .ljust (10 ))
304
+ self ._test_format_string ("%4d" , 4200 , grouping = True , out = '4 200' )
305
+ self ._test_format_string ("%5d" , 4200 , grouping = True , out = '4 200' )
306
+ self ._test_format_string ("%10d" , 4200 , grouping = True , out = '4 200' .rjust (10 ))
307
+ self ._test_format_string ("%-4d" , 4200 , grouping = True , out = '4 200' )
308
+ self ._test_format_string ("%-5d" , 4200 , grouping = True , out = '4 200' )
309
+ self ._test_format_string ("%-10d" , 4200 , grouping = True , out = '4 200' .ljust (10 ))
334
310
335
311
def test_currency (self ):
336
312
euro = '\u20ac '
0 commit comments