Package pytils :: Package test :: Package templatetags :: Module test_numeral
[hide private]

Source Code for Module pytils.test.templatetags.test_numeral

 1  # -*- coding: utf-8 -*- 
 2  # pytils - simple processing for russian strings 
 3  # Copyright (C) 2006-2007  Yury Yurevich 
 4  # 
 5  # http://www.pyobject.ru/projects/pytils/ 
 6  # 
 7  # This program is free software; you can redistribute it and/or 
 8  # modify it under the terms of the GNU General Public License 
 9  # as published by the Free Software Foundation, version 2 
10  # of the License. 
11  # 
12  # This program is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU General Public License for more details. 
16  """ 
17  Unit tests for pytils' numeral templatetags for Django web framework 
18  """ 
19   
20  __id__ = __revision__ = "$Id: test_numeral.py 102 2007-07-12 12:33:36Z the.pythy $" 
21  __url__ = "$URL: https://pythy.googlecode.com/svn/tags/pytils/0_2_2/pytils/test/templatetags/test_numeral.py $" 
22   
23  from pytils.test.templatetags import helpers 
24   
25 -class NumeralDefaultTestCase(helpers.TemplateTagTestCase):
26
27 - def testLoad(self):
28 self.check_template_tag('load_tag', '{% load pytils_numeral %}', {}, '')
29
30 - def testChoosePluralFilter(self):
31 self.check_template_tag('choose_plural', 32 '{% load pytils_numeral %}{{ val|choose_plural:"гвоздь,гвоздя,гвоздей" }}', 33 {'val': 10}, 34 'гвоздей')
35
36 - def testGetPluralFilter(self):
37 self.check_template_tag('get_plural', 38 '{% load pytils_numeral %}{{ val|get_plural:"гвоздь,гвоздя,гвоздей" }}', 39 {'val': 10}, 40 '10 гвоздей') 41 self.check_template_tag('get_plural', 42 '{% load pytils_numeral %}{{ val|get_plural:"гвоздь,гвоздя,гвоздей" }}', 43 {'val': 0}, 44 '0 гвоздей') 45 self.check_template_tag('get_plural', 46 '{% load pytils_numeral %}{{ val|get_plural:"гвоздь,гвоздя,гвоздей,нет гвоздей" }}', 47 {'val': 0}, 48 'нет гвоздей')
49
50 - def testRublesFilter(self):
51 self.check_template_tag('rubles', 52 '{% load pytils_numeral %}{{ val|rubles }}', 53 {'val': 10.1}, 54 'десять рублей десять копеек')
55
56 - def testInWordsFilter(self):
57 self.check_template_tag('in_words', 58 '{% load pytils_numeral %}{{ val|in_words }}', 59 {'val': 21}, 60 'двадцать один') 61 62 self.check_template_tag('in_words', 63 '{% load pytils_numeral %}{{ val|in_words:"NEUTER" }}', 64 {'val': 21}, 65 'двадцать одно')
66
67 - def testSumStringTag(self):
68 self.check_template_tag('sum_string', 69 '{% load pytils_numeral %}{% sum_string val "MALE" "пример,пример,примеров" %}', 70 {'val': 21}, 71 'двадцать один пример') 72 self.check_template_tag('sum_string', 73 '{% load pytils_numeral %}{% sum_string val male variants %}', 74 { 75 'val': 21, 76 'male':'MALE', 77 'variants': ('пример','пример','примеров') 78 }, 79 'двадцать один пример')
80 81 # без отладки, если ошибка -- по умолчанию пустая строка
82 - def testChoosePluralError(self):
83 self.check_template_tag('choose_plural_error', 84 '{% load pytils_numeral %}{{ val|choose_plural:"вариант" }}', 85 {'val': 1}, 86 '')
87 88 89 if __name__ == '__main__': 90 import unittest 91 unittest.main() 92