PageRenderTime 78ms CodeModel.GetById 2ms app.highlight 70ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/regressiontests/defaultfilters/tests.py

https://code.google.com/p/mango-py/
Python | 530 lines | 487 code | 34 blank | 9 comment | 1 complexity | 2046e245bcbb877bb2a1b041af974117 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2import datetime
  3from django.utils import unittest
  4
  5from django.template.defaultfilters import *
  6
  7class DefaultFiltersTests(unittest.TestCase):
  8
  9    def test_floatformat(self):
 10        self.assertEqual(floatformat(7.7), u'7.7')
 11        self.assertEqual(floatformat(7.0), u'7')
 12        self.assertEqual(floatformat(0.7), u'0.7')
 13        self.assertEqual(floatformat(0.07), u'0.1')
 14        self.assertEqual(floatformat(0.007), u'0.0')
 15        self.assertEqual(floatformat(0.0), u'0')
 16        self.assertEqual(floatformat(7.7, 3), u'7.700')
 17        self.assertEqual(floatformat(6.000000, 3), u'6.000')
 18        self.assertEqual(floatformat(6.200000, 3), u'6.200')
 19        self.assertEqual(floatformat(6.200000, -3), u'6.200')
 20        self.assertEqual(floatformat(13.1031, -3), u'13.103')
 21        self.assertEqual(floatformat(11.1197, -2), u'11.12')
 22        self.assertEqual(floatformat(11.0000, -2), u'11')
 23        self.assertEqual(floatformat(11.000001, -2), u'11.00')
 24        self.assertEqual(floatformat(8.2798, 3), u'8.280')
 25        self.assertEqual(floatformat(u'foo'), u'')
 26        self.assertEqual(floatformat(13.1031, u'bar'), u'13.1031')
 27        self.assertEqual(floatformat(18.125, 2), u'18.13')
 28        self.assertEqual(floatformat(u'foo', u'bar'), u'')
 29        self.assertEqual(floatformat(u'żCómo esta usted?'), u'')
 30        self.assertEqual(floatformat(None), u'')
 31
 32        # Check that we're not converting to scientific notation.
 33        self.assertEqual(floatformat(0, 6), u'0.000000')
 34        self.assertEqual(floatformat(0, 7), u'0.0000000')
 35        self.assertEqual(floatformat(0, 10), u'0.0000000000')
 36        self.assertEqual(floatformat(0.000000000000000000015, 20),
 37                                     u'0.00000000000000000002')
 38
 39        pos_inf = float(1e30000)
 40        self.assertEqual(floatformat(pos_inf), unicode(pos_inf))
 41
 42        neg_inf = float(-1e30000)
 43        self.assertEqual(floatformat(neg_inf), unicode(neg_inf))
 44
 45        nan = pos_inf / pos_inf
 46        self.assertEqual(floatformat(nan), unicode(nan))
 47
 48        class FloatWrapper(object):
 49            def __init__(self, value):
 50                self.value = value
 51            def __float__(self):
 52                return self.value
 53
 54        self.assertEqual(floatformat(FloatWrapper(11.000001), -2), u'11.00')
 55
 56    # This fails because of Python's float handling. Floats with many zeroes
 57    # after the decimal point should be passed in as another type such as
 58    # unicode or Decimal.
 59    @unittest.expectedFailure
 60    def test_floatformat_fail(self):
 61        self.assertEqual(floatformat(1.00000000000000015, 16), u'1.0000000000000002')
 62
 63    def test_addslashes(self):
 64        self.assertEqual(addslashes(u'"double quotes" and \'single quotes\''),
 65                          u'\\"double quotes\\" and \\\'single quotes\\\'')
 66
 67        self.assertEqual(addslashes(ur'\ : backslashes, too'),
 68                          u'\\\\ : backslashes, too')
 69
 70    def test_capfirst(self):
 71        self.assertEqual(capfirst(u'hello world'), u'Hello world')
 72
 73    def test_escapejs(self):
 74        self.assertEqual(escapejs(u'"double quotes" and \'single quotes\''),
 75            u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027')
 76        self.assertEqual(escapejs(ur'\ : backslashes, too'),
 77            u'\\u005C : backslashes, too')
 78        self.assertEqual(escapejs(u'and lots of whitespace: \r\n\t\v\f\b'),
 79            u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008')
 80        self.assertEqual(escapejs(ur'<script>and this</script>'),
 81            u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E')
 82        self.assertEqual(
 83            escapejs(u'paragraph separator:\u2029and line separator:\u2028'),
 84            u'paragraph separator:\\u2029and line separator:\\u2028')
 85
 86    def test_fix_ampersands(self):
 87        self.assertEqual(fix_ampersands(u'Jack & Jill & Jeroboam'),
 88                          u'Jack &amp; Jill &amp; Jeroboam')
 89
 90    def test_linenumbers(self):
 91        self.assertEqual(linenumbers(u'line 1\nline 2'),
 92                          u'1. line 1\n2. line 2')
 93        self.assertEqual(linenumbers(u'\n'.join([u'x'] * 10)),
 94                          u'01. x\n02. x\n03. x\n04. x\n05. x\n06. x\n07. '\
 95                          u'x\n08. x\n09. x\n10. x')
 96
 97    def test_lower(self):
 98        self.assertEqual(lower('TEST'), u'test')
 99
100        # uppercase E umlaut
101        self.assertEqual(lower(u'\xcb'), u'\xeb')
102
103    def test_make_list(self):
104        self.assertEqual(make_list('abc'), [u'a', u'b', u'c'])
105        self.assertEqual(make_list(1234), [u'1', u'2', u'3', u'4'])
106
107    def test_slugify(self):
108        self.assertEqual(slugify(' Jack & Jill like numbers 1,2,3 and 4 and'\
109            ' silly characters ?%.$!/'),
110            u'jack-jill-like-numbers-123-and-4-and-silly-characters')
111
112        self.assertEqual(slugify(u"Un \xe9l\xe9phant \xe0 l'or\xe9e du bois"),
113                          u'un-elephant-a-loree-du-bois')
114
115    def test_stringformat(self):
116        self.assertEqual(stringformat(1, u'03d'), u'001')
117        self.assertEqual(stringformat(1, u'z'), u'')
118
119    def test_title(self):
120        self.assertEqual(title('a nice title, isn\'t it?'),
121                          u"A Nice Title, Isn't It?")
122        self.assertEqual(title(u'discoth\xe8que'), u'Discoth\xe8que')
123
124    def test_truncatewords(self):
125        self.assertEqual(
126            truncatewords(u'A sentence with a few words in it', 1), u'A ...')
127        self.assertEqual(
128            truncatewords(u'A sentence with a few words in it', 5),
129            u'A sentence with a few ...')
130        self.assertEqual(
131            truncatewords(u'A sentence with a few words in it', 100),
132            u'A sentence with a few words in it')
133        self.assertEqual(
134            truncatewords(u'A sentence with a few words in it',
135            'not a number'), u'A sentence with a few words in it')
136
137    def test_truncatewords_html(self):
138        self.assertEqual(truncatewords_html(
139            u'<p>one <a href="#">two - three <br>four</a> five</p>', 0), u'')
140        self.assertEqual(truncatewords_html(u'<p>one <a href="#">two - '\
141            u'three <br>four</a> five</p>', 2),
142            u'<p>one <a href="#">two ...</a></p>')
143        self.assertEqual(truncatewords_html(
144            u'<p>one <a href="#">two - three <br>four</a> five</p>', 4),
145            u'<p>one <a href="#">two - three <br>four ...</a></p>')
146        self.assertEqual(truncatewords_html(
147            u'<p>one <a href="#">two - three <br>four</a> five</p>', 5),
148            u'<p>one <a href="#">two - three <br>four</a> five</p>')
149        self.assertEqual(truncatewords_html(
150            u'<p>one <a href="#">two - three <br>four</a> five</p>', 100),
151            u'<p>one <a href="#">two - three <br>four</a> five</p>')
152        self.assertEqual(truncatewords_html(
153            u'\xc5ngstr\xf6m was here', 1), u'\xc5ngstr\xf6m ...')
154
155    def test_upper(self):
156        self.assertEqual(upper(u'Mixed case input'), u'MIXED CASE INPUT')
157        # lowercase e umlaut
158        self.assertEqual(upper(u'\xeb'), u'\xcb')
159
160    def test_urlencode(self):
161        self.assertEqual(urlencode(u'fran\xe7ois & jill'),
162                          u'fran%C3%A7ois%20%26%20jill')
163        self.assertEqual(urlencode(1), u'1')
164
165    def test_iriencode(self):
166        self.assertEqual(iriencode(u'S\xf8r-Tr\xf8ndelag'),
167                          u'S%C3%B8r-Tr%C3%B8ndelag')
168        self.assertEqual(iriencode(urlencode(u'fran\xe7ois & jill')),
169                          u'fran%C3%A7ois%20%26%20jill')
170
171    def test_urlizetrunc(self):
172        self.assertEqual(urlizetrunc(u'http://short.com/', 20), u'<a href='\
173            u'"http://short.com/" rel="nofollow">http://short.com/</a>')
174
175        self.assertEqual(urlizetrunc(u'http://www.google.co.uk/search?hl=en'\
176            u'&q=some+long+url&btnG=Search&meta=', 20), u'<a href="http://'\
177            u'www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&'\
178            u'meta=" rel="nofollow">http://www.google...</a>')
179
180        self.assertEqual(urlizetrunc('http://www.google.co.uk/search?hl=en'\
181            u'&q=some+long+url&btnG=Search&meta=', 20), u'<a href="http://'\
182            u'www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search'\
183            u'&meta=" rel="nofollow">http://www.google...</a>')
184
185        # Check truncating of URIs which are the exact length
186        uri = 'http://31characteruri.com/test/'
187        self.assertEqual(len(uri), 31)
188
189        self.assertEqual(urlizetrunc(uri, 31),
190            u'<a href="http://31characteruri.com/test/" rel="nofollow">'\
191            u'http://31characteruri.com/test/</a>')
192
193        self.assertEqual(urlizetrunc(uri, 30),
194            u'<a href="http://31characteruri.com/test/" rel="nofollow">'\
195            u'http://31characteruri.com/t...</a>')
196
197        self.assertEqual(urlizetrunc(uri, 2),
198            u'<a href="http://31characteruri.com/test/"'\
199            u' rel="nofollow">...</a>')
200
201    def test_urlize(self):
202        # Check normal urlize
203        self.assertEqual(urlize('http://google.com'),
204            u'<a href="http://google.com" rel="nofollow">http://google.com</a>')
205        self.assertEqual(urlize('http://google.com/'),
206            u'<a href="http://google.com/" rel="nofollow">http://google.com/</a>')
207        self.assertEqual(urlize('www.google.com'),
208            u'<a href="http://www.google.com" rel="nofollow">www.google.com</a>')
209        self.assertEqual(urlize('djangoproject.org'),
210            u'<a href="http://djangoproject.org" rel="nofollow">djangoproject.org</a>')
211        self.assertEqual(urlize('info@djangoproject.org'),
212            u'<a href="mailto:info@djangoproject.org">info@djangoproject.org</a>')
213
214        # Check urlize with https addresses
215        self.assertEqual(urlize('https://google.com'),
216            u'<a href="https://google.com" rel="nofollow">https://google.com</a>')
217
218    def test_wordcount(self):
219        self.assertEqual(wordcount(''), 0)
220        self.assertEqual(wordcount(u'oneword'), 1)
221        self.assertEqual(wordcount(u'lots of words'), 3)
222
223        self.assertEqual(wordwrap(u'this is a long paragraph of text that '\
224            u'really needs to be wrapped I\'m afraid', 14),
225            u"this is a long\nparagraph of\ntext that\nreally needs\nto be "\
226            u"wrapped\nI'm afraid")
227
228        self.assertEqual(wordwrap(u'this is a short paragraph of text.\n  '\
229            u'But this line should be indented', 14),
230            u'this is a\nshort\nparagraph of\ntext.\n  But this\nline '\
231            u'should be\nindented')
232
233        self.assertEqual(wordwrap(u'this is a short paragraph of text.\n  '\
234            u'But this line should be indented',15), u'this is a short\n'\
235            u'paragraph of\ntext.\n  But this line\nshould be\nindented')
236
237    def test_rjust(self):
238        self.assertEqual(ljust(u'test', 10), u'test      ')
239        self.assertEqual(ljust(u'test', 3), u'test')
240        self.assertEqual(rjust(u'test', 10), u'      test')
241        self.assertEqual(rjust(u'test', 3), u'test')
242
243    def test_center(self):
244        self.assertEqual(center(u'test', 6), u' test ')
245
246    def test_cut(self):
247        self.assertEqual(cut(u'a string to be mangled', 'a'),
248                          u' string to be mngled')
249        self.assertEqual(cut(u'a string to be mangled', 'ng'),
250                          u'a stri to be maled')
251        self.assertEqual(cut(u'a string to be mangled', 'strings'),
252                          u'a string to be mangled')
253
254    def test_force_escape(self):
255        self.assertEqual(
256            force_escape(u'<some html & special characters > here'),
257            u'&lt;some html &amp; special characters &gt; here')
258        self.assertEqual(
259            force_escape(u'<some html & special characters > here ?ŀŁ'),
260            u'&lt;some html &amp; special characters &gt; here'\
261            u' \u0110\xc5\u20ac\xa3')
262
263    def test_linebreaks(self):
264        self.assertEqual(linebreaks(u'line 1'), u'<p>line 1</p>')
265        self.assertEqual(linebreaks(u'line 1\nline 2'),
266                          u'<p>line 1<br />line 2</p>')
267
268    def test_removetags(self):
269        self.assertEqual(removetags(u'some <b>html</b> with <script>alert'\
270            u'("You smell")</script> disallowed <img /> tags', 'script img'),
271            u'some <b>html</b> with alert("You smell") disallowed  tags')
272        self.assertEqual(striptags(u'some <b>html</b> with <script>alert'\
273            u'("You smell")</script> disallowed <img /> tags'),
274            u'some html with alert("You smell") disallowed  tags')
275
276    def test_dictsort(self):
277        sorted_dicts = dictsort([{'age': 23, 'name': 'Barbara-Ann'},
278                                 {'age': 63, 'name': 'Ra Ra Rasputin'},
279                                 {'name': 'Jonny B Goode', 'age': 18}], 'age')
280
281        self.assertEqual([sorted(dict.items()) for dict in sorted_dicts],
282            [[('age', 18), ('name', 'Jonny B Goode')],
283             [('age', 23), ('name', 'Barbara-Ann')],
284             [('age', 63), ('name', 'Ra Ra Rasputin')]])
285
286    def test_dictsortreversed(self):
287        sorted_dicts = dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},
288                                         {'age': 63, 'name': 'Ra Ra Rasputin'},
289                                         {'name': 'Jonny B Goode', 'age': 18}],
290                                        'age')
291
292        self.assertEqual([sorted(dict.items()) for dict in sorted_dicts],
293            [[('age', 63), ('name', 'Ra Ra Rasputin')],
294             [('age', 23), ('name', 'Barbara-Ann')],
295             [('age', 18), ('name', 'Jonny B Goode')]])
296
297    def test_first(self):
298        self.assertEqual(first([0,1,2]), 0)
299        self.assertEqual(first(u''), u'')
300        self.assertEqual(first(u'test'), u't')
301
302    def test_join(self):
303        self.assertEqual(join([0,1,2], u'glue'), u'0glue1glue2')
304
305    def test_length(self):
306        self.assertEqual(length(u'1234'), 4)
307        self.assertEqual(length([1,2,3,4]), 4)
308        self.assertEqual(length_is([], 0), True)
309        self.assertEqual(length_is([], 1), False)
310        self.assertEqual(length_is('a', 1), True)
311        self.assertEqual(length_is(u'a', 10), False)
312
313    def test_slice(self):
314        self.assertEqual(slice_(u'abcdefg', u'0'), u'')
315        self.assertEqual(slice_(u'abcdefg', u'1'), u'a')
316        self.assertEqual(slice_(u'abcdefg', u'-1'), u'abcdef')
317        self.assertEqual(slice_(u'abcdefg', u'1:2'), u'b')
318        self.assertEqual(slice_(u'abcdefg', u'1:3'), u'bc')
319        self.assertEqual(slice_(u'abcdefg', u'0::2'), u'aceg')
320
321    def test_unordered_list(self):
322        self.assertEqual(unordered_list([u'item 1', u'item 2']),
323            u'\t<li>item 1</li>\n\t<li>item 2</li>')
324        self.assertEqual(unordered_list([u'item 1', [u'item 1.1']]),
325            u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>')
326
327        self.assertEqual(
328            unordered_list([u'item 1', [u'item 1.1', u'item1.2'], u'item 2']),
329            u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t\t<li>item1.2'\
330            u'</li>\n\t</ul>\n\t</li>\n\t<li>item 2</li>')
331
332        self.assertEqual(
333            unordered_list([u'item 1', [u'item 1.1', [u'item 1.1.1',
334                                                      [u'item 1.1.1.1']]]]),
335            u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1\n\t\t<ul>\n\t\t\t<li>'\
336            u'item 1.1.1\n\t\t\t<ul>\n\t\t\t\t<li>item 1.1.1.1</li>\n\t\t\t'\
337            u'</ul>\n\t\t\t</li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>')
338
339        self.assertEqual(unordered_list(
340            ['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]),
341            u'\t<li>States\n\t<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>'\
342            u'Lawrence</li>\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>'\
343            u'\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>')
344
345        class ULItem(object):
346            def __init__(self, title):
347              self.title = title
348            def __unicode__(self):
349                return u'ulitem-%s' % str(self.title)
350
351        a = ULItem('a')
352        b = ULItem('b')
353        self.assertEqual(unordered_list([a,b]),
354                          u'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>')
355
356        # Old format for unordered lists should still work
357        self.assertEqual(unordered_list([u'item 1', []]), u'\t<li>item 1</li>')
358
359        self.assertEqual(unordered_list([u'item 1', [[u'item 1.1', []]]]),
360            u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>')
361
362        self.assertEqual(unordered_list([u'item 1', [[u'item 1.1', []],
363            [u'item 1.2', []]]]), u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1'\
364            u'</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>')
365
366        self.assertEqual(unordered_list(['States', [['Kansas', [['Lawrence',
367            []], ['Topeka', []]]], ['Illinois', []]]]), u'\t<li>States\n\t'\
368            u'<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>Lawrence</li>'\
369            u'\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>'\
370            u'Illinois</li>\n\t</ul>\n\t</li>')
371
372    def test_add(self):
373        self.assertEqual(add(u'1', u'2'), 3)
374
375    def test_get_digit(self):
376        self.assertEqual(get_digit(123, 1), 3)
377        self.assertEqual(get_digit(123, 2), 2)
378        self.assertEqual(get_digit(123, 3), 1)
379        self.assertEqual(get_digit(123, 4), 0)
380        self.assertEqual(get_digit(123, 0), 123)
381        self.assertEqual(get_digit(u'xyz', 0), u'xyz')
382
383    def test_date(self):
384        # real testing of date() is in dateformat.py
385        self.assertEqual(date(datetime.datetime(2005, 12, 29), u"d F Y"),
386                          u'29 December 2005')
387        self.assertEqual(date(datetime.datetime(2005, 12, 29), ur'jS o\f F'),
388                          u'29th of December')
389
390    def test_time(self):
391        # real testing of time() is done in dateformat.py
392        self.assertEqual(time(datetime.time(13), u"h"), u'01')
393        self.assertEqual(time(datetime.time(0), u"h"), u'12')
394
395    def test_timesince(self):
396        # real testing is done in timesince.py, where we can provide our own 'now'
397        self.assertEqual(
398            timesince(datetime.datetime.now() - datetime.timedelta(1)),
399            u'1 day')
400
401        self.assertEqual(
402            timesince(datetime.datetime(2005, 12, 29),
403                      datetime.datetime(2005, 12, 30)),
404            u'1 day')
405
406    def test_timeuntil(self):
407        self.assertEqual(
408            timeuntil(datetime.datetime.now() + datetime.timedelta(1)),
409            u'1 day')
410
411        self.assertEqual(timeuntil(datetime.datetime(2005, 12, 30),
412                                    datetime.datetime(2005, 12, 29)),
413                          u'1 day')
414
415    def test_default(self):
416        self.assertEqual(default(u"val", u"default"), u'val')
417        self.assertEqual(default(None, u"default"), u'default')
418        self.assertEqual(default(u'', u"default"), u'default')
419
420    def test_if_none(self):
421        self.assertEqual(default_if_none(u"val", u"default"), u'val')
422        self.assertEqual(default_if_none(None, u"default"), u'default')
423        self.assertEqual(default_if_none(u'', u"default"), u'')
424
425    def test_divisibleby(self):
426        self.assertEqual(divisibleby(4, 2), True)
427        self.assertEqual(divisibleby(4, 3), False)
428
429    def test_yesno(self):
430        self.assertEqual(yesno(True), u'yes')
431        self.assertEqual(yesno(False), u'no')
432        self.assertEqual(yesno(None), u'maybe')
433        self.assertEqual(yesno(True, u'certainly,get out of town,perhaps'),
434                          u'certainly')
435        self.assertEqual(yesno(False, u'certainly,get out of town,perhaps'),
436                          u'get out of town')
437        self.assertEqual(yesno(None, u'certainly,get out of town,perhaps'),
438                          u'perhaps')
439        self.assertEqual(yesno(None, u'certainly,get out of town'),
440                          u'get out of town')
441
442    def test_filesizeformat(self):
443        self.assertEqual(filesizeformat(1023), u'1023 bytes')
444        self.assertEqual(filesizeformat(1024), u'1.0 KB')
445        self.assertEqual(filesizeformat(10*1024), u'10.0 KB')
446        self.assertEqual(filesizeformat(1024*1024-1), u'1024.0 KB')
447        self.assertEqual(filesizeformat(1024*1024), u'1.0 MB')
448        self.assertEqual(filesizeformat(1024*1024*50), u'50.0 MB')
449        self.assertEqual(filesizeformat(1024*1024*1024-1), u'1024.0 MB')
450        self.assertEqual(filesizeformat(1024*1024*1024), u'1.0 GB')
451        self.assertEqual(filesizeformat(1024*1024*1024*1024), u'1.0 TB')
452        self.assertEqual(filesizeformat(1024*1024*1024*1024*1024), u'1.0 PB')
453        self.assertEqual(filesizeformat(1024*1024*1024*1024*1024*2000),
454                          u'2000.0 PB')
455        self.assertEqual(filesizeformat(complex(1,-1)), u'0 bytes')
456        self.assertEqual(filesizeformat(""), u'0 bytes')
457        self.assertEqual(filesizeformat(u"\N{GREEK SMALL LETTER ALPHA}"),
458                          u'0 bytes')
459
460    def test_localized_filesizeformat(self):
461        from django.utils.translation import activate, deactivate
462        old_localize = settings.USE_L10N
463        try:
464            activate('de')
465            settings.USE_L10N = True
466            self.assertEqual(filesizeformat(1023), u'1023 Bytes')
467            self.assertEqual(filesizeformat(1024), u'1,0 KB')
468            self.assertEqual(filesizeformat(10*1024), u'10,0 KB')
469            self.assertEqual(filesizeformat(1024*1024-1), u'1024,0 KB')
470            self.assertEqual(filesizeformat(1024*1024), u'1,0 MB')
471            self.assertEqual(filesizeformat(1024*1024*50), u'50,0 MB')
472            self.assertEqual(filesizeformat(1024*1024*1024-1), u'1024,0 MB')
473            self.assertEqual(filesizeformat(1024*1024*1024), u'1,0 GB')
474            self.assertEqual(filesizeformat(1024*1024*1024*1024), u'1,0 TB')
475            self.assertEqual(filesizeformat(1024*1024*1024*1024*1024),
476                              u'1,0 PB')
477            self.assertEqual(filesizeformat(1024*1024*1024*1024*1024*2000),
478                              u'2000,0 PB')
479            self.assertEqual(filesizeformat(complex(1,-1)), u'0 Bytes')
480            self.assertEqual(filesizeformat(""), u'0 Bytes')
481            self.assertEqual(filesizeformat(u"\N{GREEK SMALL LETTER ALPHA}"),
482                              u'0 Bytes')
483        finally:
484            deactivate()
485            settings.USE_L10N = old_localize
486
487    def test_pluralize(self):
488        self.assertEqual(pluralize(1), u'')
489        self.assertEqual(pluralize(0), u's')
490        self.assertEqual(pluralize(2), u's')
491        self.assertEqual(pluralize([1]), u'')
492        self.assertEqual(pluralize([]), u's')
493        self.assertEqual(pluralize([1,2,3]), u's')
494        self.assertEqual(pluralize(1,u'es'), u'')
495        self.assertEqual(pluralize(0,u'es'), u'es')
496        self.assertEqual(pluralize(2,u'es'), u'es')
497        self.assertEqual(pluralize(1,u'y,ies'), u'y')
498        self.assertEqual(pluralize(0,u'y,ies'), u'ies')
499        self.assertEqual(pluralize(2,u'y,ies'), u'ies')
500        self.assertEqual(pluralize(0,u'y,ies,error'), u'')
501
502    def test_phone2numeric(self):
503        self.assertEqual(phone2numeric(u'0800 flowers'), u'0800 3569377')
504
505    def test_non_string_input(self):
506        # Filters shouldn't break if passed non-strings
507        self.assertEqual(addslashes(123), u'123')
508        self.assertEqual(linenumbers(123), u'1. 123')
509        self.assertEqual(lower(123), u'123')
510        self.assertEqual(make_list(123), [u'1', u'2', u'3'])
511        self.assertEqual(slugify(123), u'123')
512        self.assertEqual(title(123), u'123')
513        self.assertEqual(truncatewords(123, 2), u'123')
514        self.assertEqual(upper(123), u'123')
515        self.assertEqual(urlencode(123), u'123')
516        self.assertEqual(urlize(123), u'123')
517        self.assertEqual(urlizetrunc(123, 1), u'123')
518        self.assertEqual(wordcount(123), 1)
519        self.assertEqual(wordwrap(123, 2), u'123')
520        self.assertEqual(ljust('123', 4), u'123 ')
521        self.assertEqual(rjust('123', 4), u' 123')
522        self.assertEqual(center('123', 5), u' 123 ')
523        self.assertEqual(center('123', 6), u' 123  ')
524        self.assertEqual(cut(123, '2'), u'13')
525        self.assertEqual(escape(123), u'123')
526        self.assertEqual(linebreaks(123), u'<p>123</p>')
527        self.assertEqual(linebreaksbr(123), u'123')
528        self.assertEqual(removetags(123, 'a'), u'123')
529        self.assertEqual(striptags(123), u'123')
530