Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated i18n tests a little to handle test failures better and update…

…d Argentinian Spanish format strings. Thanks to Ramiro Morales. Refs #11637.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b5a4aef43d03c9f8ece64332e165730dd377b033 1 parent 7e44efb
Jannis Leidel authored
39  django/conf/locale/es_AR/formats.py
@@ -2,17 +2,28 @@
2 2
 # This file is distributed under the same license as the Django package.
3 3
 #
4 4
 
5  
-# DATE_FORMAT = 
6  
-# TIME_FORMAT = 
7  
-# DATETIME_FORMAT = 
8  
-# YEAR_MONTH_FORMAT = 
9  
-# MONTH_DAY_FORMAT = 
10  
-# SHORT_DATE_FORMAT = 
11  
-# SHORT_DATETIME_FORMAT = 
12  
-# FIRST_DAY_OF_WEEK = 
13  
-# DATE_INPUT_FORMATS = 
14  
-# TIME_INPUT_FORMATS = 
15  
-# DATETIME_INPUT_FORMATS = 
16  
-# DECIMAL_SEPARATOR = 
17  
-# THOUSAND_SEPARATOR = 
18  
-# NUMBER_GROUPING = 
  5
+DATE_FORMAT = 'j \de F \de Y'
  6
+TIME_FORMAT = 'H:i:s'
  7
+DATETIME_FORMAT = 'j \de F \de Y \a \l\a\s H:i'
  8
+YEAR_MONTH_FORMAT = 'F \de Y'
  9
+MONTH_DAY_FORMAT = 'j \de F'
  10
+SHORT_DATE_FORMAT = 'd/m/Y'
  11
+SHORT_DATETIME_FORMAT = 'd/m/Y H:i'
  12
+FIRST_DAY_OF_WEEK = 0 # 0: Sunday, 1: Monday
  13
+DATE_INPUT_FORMATS = (
  14
+    '%d/%m/%Y', # '31/12/2009'
  15
+    '%d/%m/%y', # '31/12/09'
  16
+)
  17
+TIME_INPUT_FORMATS = (
  18
+    '%H:%M:%S', # '14:30:59'
  19
+    '%H:%M',    # '14:30'
  20
+)
  21
+DATETIME_INPUT_FORMATS = (
  22
+    '%d/%m/%Y %H:%M:%S',
  23
+    '%d/%m/%Y %H:%M',
  24
+    '%d/%m/%y %H:%M:%S',
  25
+    '%d/%m/%y %H:%M',
  26
+)
  27
+DECIMAL_SEPARATOR = ','
  28
+THOUSAND_SEPARATOR = '.'
  29
+NUMBER_GROUPING = 3
13  tests/regressiontests/i18n/forms.py
... ...
@@ -0,0 +1,13 @@
  1
+from django import template, forms
  2
+from django.forms.extras import SelectDateWidget
  3
+
  4
+class I18nForm(forms.Form):
  5
+    decimal_field = forms.DecimalField()
  6
+    float_field = forms.FloatField()
  7
+    date_field = forms.DateField()
  8
+    datetime_field = forms.DateTimeField()
  9
+    time_field = forms.TimeField()
  10
+
  11
+class SelectDateForm(forms.Form):
  12
+    date_field = forms.DateField(widget=SelectDateWidget)
  13
+
461  tests/regressiontests/i18n/tests.py
... ...
@@ -1,7 +1,16 @@
1 1
 import sys
  2
+import decimal
  3
+import datetime
  4
+
  5
+from django.template import Template, Context
  6
+from django.conf import settings
  7
+from django.utils.formats import get_format, date_format, number_format, localize
  8
+from django.utils.numberformat import format
2 9
 from django.test import TestCase, client
3 10
 from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy
4 11
 
  12
+from forms import I18nForm, SelectDateForm, SelectDateWidget
  13
+
5 14
 class TranslationTests(TestCase):
6 15
 
7 16
     def test_lazy_objects(self):
@@ -12,10 +21,12 @@ def test_lazy_objects(self):
12 21
         d = {'name': 'Ringo'}
13 22
         self.assertEqual(u'Add Ringo', s % d)
14 23
         activate('de')
15  
-        self.assertEqual(u'Ringo hinzuf\xfcgen', s % d)
16  
-        activate('pl')
17  
-        self.assertEqual(u'Dodaj Ringo', s % d)
18  
-        deactivate()
  24
+        try:
  25
+            self.assertEqual(u'Ringo hinzuf\xfcgen', s % d)
  26
+            activate('pl')
  27
+            self.assertEqual(u'Dodaj Ringo', s % d)
  28
+        finally:
  29
+            deactivate()
19 30
 
20 31
         # It should be possible to compare *_lazy objects.
21 32
         s1 = ugettext_lazy('Add %(name)s')
@@ -43,14 +54,15 @@ def test_safe_status(self):
43 54
         s = mark_safe('Password')
44 55
         self.assertEqual(SafeString, type(s))
45 56
         activate('de')
46  
-        self.assertEqual(SafeUnicode, type(ugettext(s)))
47  
-        deactivate()
  57
+        try:
  58
+            self.assertEqual(SafeUnicode, type(ugettext(s)))
  59
+        finally:
  60
+            deactivate()
48 61
         self.assertEqual('aPassword', SafeString('a') + s)
49 62
         self.assertEqual('Passworda', s + SafeString('a'))
50 63
         self.assertEqual('Passworda', s + mark_safe('a'))
51 64
         self.assertEqual('aPassword', mark_safe('a') + s)
52 65
         self.assertEqual('as', mark_safe('a') + mark_safe('s'))
53  
-        #self.assertEqual(Password, print s)
54 66
 
55 67
     def test_maclines(self):
56 68
         """
@@ -62,237 +74,254 @@ def test_maclines(self):
62 74
         ca_translation._catalog[u'Mac\nEOF\n'] = u'Catalan Mac\nEOF\n'
63 75
         ca_translation._catalog[u'Win\nEOF\n'] = u'Catalan Win\nEOF\n'
64 76
         activate('ca')
65  
-        self.assertEqual(u'Catalan Mac\nEOF\n', ugettext(u'Mac\rEOF\r'))
66  
-        self.assertEqual(u'Catalan Win\nEOF\n', ugettext(u'Win\r\nEOF\r\n'))
67  
-        deactivate()
  77
+        try:
  78
+            self.assertEqual(u'Catalan Mac\nEOF\n', ugettext(u'Mac\rEOF\r'))
  79
+            self.assertEqual(u'Catalan Win\nEOF\n', ugettext(u'Win\r\nEOF\r\n'))
  80
+        finally:
  81
+            deactivate()
  82
+
  83
+class FormattingTests(TestCase):
  84
+
  85
+    def setUp(self):
  86
+        self._use_i18n = settings.USE_I18N
  87
+        self._use_l10n = settings.USE_L10N
  88
+        self._use_thousand_separator = settings.USE_THOUSAND_SEPARATOR
  89
+        self.n = decimal.Decimal('66666.666')
  90
+        self.f = 99999.999
  91
+        self.d = datetime.date(2009, 12, 31)
  92
+        self.dt = datetime.datetime(2009, 12, 31, 20, 50)
  93
+        self.ctxt = Context({
  94
+            'n': self.n,
  95
+            'd': self.d,
  96
+            'dt': self.dt,
  97
+            'f': self.f
  98
+        })
68 99
 
69  
-    def test_dates_and_numbers(self):
  100
+    def tearDown(self):
  101
+        # Restore defaults
  102
+        settings.USE_I18N = self._use_i18n
  103
+        settings.USE_L10N = self._use_l10n
  104
+        settings.USE_THOUSAND_SEPARATOR = self._use_thousand_separator
  105
+    
  106
+    def test_locale_independent(self):
70 107
         """
71 108
         Localization of dates and numbers
72 109
         """
73  
-        import datetime
74  
-        import decimal
75  
-        from django.conf import settings
76  
-        from django.utils.formats import get_format, date_format, number_format, localize
77  
-        from django.utils.numberformat import format
78  
-        from django import template, forms
79  
-        from django.forms.extras import SelectDateWidget
80  
-
81  
-        old_use_i18n = settings.USE_I18N
82  
-        old_use_l10n = settings.USE_L10N
83  
-        old_use_thousand_separator = settings.USE_THOUSAND_SEPARATOR
84  
-
85  
-        n = decimal.Decimal('66666.666')
86  
-        f = 99999.999
87  
-        d = datetime.date(2009, 12, 31)
88  
-        dt = datetime.datetime(2009, 12, 31, 20, 50)
89  
-        ctxt = template.Context({'n': n, 'd': d, 'dt': dt, 'f': f})
90  
-
91  
-        # Locale independent
92  
-
93  
-        class I18nForm(forms.Form):
94  
-            decimal_field = forms.DecimalField()
95  
-            float_field = forms.FloatField()
96  
-            date_field = forms.DateField()
97  
-            datetime_field = forms.DateTimeField()
98  
-            time_field = forms.TimeField()
99  
-
100  
-        class SelectDateForm(forms.Form):
101  
-            date_field = forms.DateField(widget=SelectDateWidget)
102  
-
103 110
         settings.USE_L10N = True
104 111
         settings.USE_THOUSAND_SEPARATOR = False
105  
-        self.assertEqual(u'66666.66', format(n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
106  
-        self.assertEqual(u'66666A6', format(n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
  112
+        self.assertEqual(u'66666.66', format(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
  113
+        self.assertEqual(u'66666A6', format(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
107 114
 
108 115
         settings.USE_THOUSAND_SEPARATOR = True
109  
-        self.assertEqual(u'66,666.66', format(n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
110  
-        self.assertEqual(u'6B6B6B6B6A6', format(n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
  116
+        self.assertEqual(u'66,666.66', format(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
  117
+        self.assertEqual(u'6B6B6B6B6A6', format(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
111 118
         self.assertEqual(u'-66666.6', format(-66666.666, decimal_sep='.', decimal_pos=1))
112 119
         self.assertEqual(u'-66666.0', format(int('-66666'), decimal_sep='.', decimal_pos=1))
113 120
 
114  
-        # Catalan locale with format i18n disabled translations will be used, but not formats
115  
-
  121
+    def test_l10n_disabled(self):
  122
+        """
  123
+        Catalan locale with format i18n disabled translations will be used,
  124
+        but not formats
  125
+        """
116 126
         settings.USE_L10N = False
117 127
         activate('ca')
118  
-        self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
119  
-        self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
120  
-        self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
121  
-        self.assertEqual(u'des. 31, 2009', date_format(d))
122  
-        self.assertEqual(u'desembre 2009', date_format(d, 'YEAR_MONTH_FORMAT'))
123  
-        self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(dt, 'SHORT_DATETIME_FORMAT'))
124  
-        self.assertEqual('No localizable', localize('No localizable'))
125  
-        self.assertEqual(decimal.Decimal('66666.666'), localize(n))
126  
-        self.assertEqual(99999.999, localize(f))
127  
-        self.assertEqual(datetime.date(2009, 12, 31), localize(d))
128  
-        self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), localize(dt))
129  
-        self.assertEqual(u'66666.666', template.Template('{{ n }}').render(ctxt))
130  
-        self.assertEqual(u'99999.999', template.Template('{{ f }}').render(ctxt))
131  
-        self.assertEqual(u'2009-12-31', template.Template('{{ d }}').render(ctxt))
132  
-        self.assertEqual(u'2009-12-31 20:50:00', template.Template('{{ dt }}').render(ctxt))
133  
-        self.assertEqual(u'66666.67', template.Template('{{ n|floatformat:2 }}').render(ctxt))
134  
-        self.assertEqual(u'100000.0', template.Template('{{ f|floatformat }}').render(ctxt))
135  
-        self.assertEqual(u'12/31/2009', template.Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(ctxt))
136  
-        self.assertEqual(u'12/31/2009 8:50 p.m.', template.Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(ctxt))
137  
-
138  
-        form = I18nForm({
139  
-            'decimal_field': u'66666,666',
140  
-            'float_field': u'99999,999',
141  
-            'date_field': u'31/12/2009',
142  
-            'datetime_field': u'31/12/2009 20:50',
143  
-            'time_field': u'20:50'
144  
-        })
145  
-        self.assertEqual(False, form.is_valid())
146  
-        self.assertEqual([u'Introdu\xefu un n\xfamero.'], form.errors['float_field'])
147  
-        self.assertEqual([u'Introdu\xefu un n\xfamero.'], form.errors['decimal_field'])
148  
-        self.assertEqual([u'Introdu\xefu una data v\xe0lida.'], form.errors['date_field'])
149  
-        self.assertEqual([u'Introdu\xefu una data/hora v\xe0lides.'], form.errors['datetime_field'])
150  
-
151  
-        form2 = SelectDateForm({
152  
-            'date_field_month': u'12',
153  
-            'date_field_day': u'31',
154  
-            'date_field_year': u'2009'
155  
-        })
156  
-        self.assertEqual(True, form2.is_valid())
157  
-        self.assertEqual(datetime.date(2009, 12, 31), form2.cleaned_data['date_field'])
158  
-        self.assertEqual(u'<select name="mydate_month" id="id_mydate_month">\n<option value="1">gener</option>\n<option value="2">febrer</option>\n<option value="3">mar\xe7</option>\n<option value="4">abril</option>\n<option value="5">maig</option>\n<option value="6">juny</option>\n<option value="7">juliol</option>\n<option value="8">agost</option>\n<option value="9">setembre</option>\n<option value="10">octubre</option>\n<option value="11">novembre</option>\n<option value="12" selected="selected">desembre</option>\n</select>\n<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>', SelectDateWidget().render('mydate', datetime.date(2009, 12, 31)))
159  
-        deactivate()
160  
-
161  
-        # Catalan locale
162  
-
  128
+        try:
  129
+            self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
  130
+            self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
  131
+            self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
  132
+            self.assertEqual(u'des. 31, 2009', date_format(self.d))
  133
+            self.assertEqual(u'desembre 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
  134
+            self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
  135
+            self.assertEqual('No localizable', localize('No localizable'))
  136
+            self.assertEqual(decimal.Decimal('66666.666'), localize(self.n))
  137
+            self.assertEqual(99999.999, localize(self.f))
  138
+            self.assertEqual(datetime.date(2009, 12, 31), localize(self.d))
  139
+            self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), localize(self.dt))
  140
+            self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))
  141
+            self.assertEqual(u'99999.999', Template('{{ f }}').render(self.ctxt))
  142
+            self.assertEqual(u'2009-12-31', Template('{{ d }}').render(self.ctxt))
  143
+            self.assertEqual(u'2009-12-31 20:50:00', Template('{{ dt }}').render(self.ctxt))
  144
+            self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
  145
+            self.assertEqual(u'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
  146
+            self.assertEqual(u'12/31/2009', Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(self.ctxt))
  147
+            self.assertEqual(u'12/31/2009 8:50 p.m.', Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(self.ctxt))
  148
+
  149
+            form = I18nForm({
  150
+                'decimal_field': u'66666,666',
  151
+                'float_field': u'99999,999',
  152
+                'date_field': u'31/12/2009',
  153
+                'datetime_field': u'31/12/2009 20:50',
  154
+                'time_field': u'20:50'
  155
+            })
  156
+            self.assertEqual(False, form.is_valid())
  157
+            self.assertEqual([u'Introdu\xefu un n\xfamero.'], form.errors['float_field'])
  158
+            self.assertEqual([u'Introdu\xefu un n\xfamero.'], form.errors['decimal_field'])
  159
+            self.assertEqual([u'Introdu\xefu una data v\xe0lida.'], form.errors['date_field'])
  160
+            self.assertEqual([u'Introdu\xefu una data/hora v\xe0lides.'], form.errors['datetime_field'])
  161
+
  162
+            form2 = SelectDateForm({
  163
+                'date_field_month': u'12',
  164
+                'date_field_day': u'31',
  165
+                'date_field_year': u'2009'
  166
+            })
  167
+            self.assertEqual(True, form2.is_valid())
  168
+            self.assertEqual(datetime.date(2009, 12, 31), form2.cleaned_data['date_field'])
  169
+            self.assertEqual(
  170
+                u'<select name="mydate_month" id="id_mydate_month">\n<option value="1">gener</option>\n<option value="2">febrer</option>\n<option value="3">mar\xe7</option>\n<option value="4">abril</option>\n<option value="5">maig</option>\n<option value="6">juny</option>\n<option value="7">juliol</option>\n<option value="8">agost</option>\n<option value="9">setembre</option>\n<option value="10">octubre</option>\n<option value="11">novembre</option>\n<option value="12" selected="selected">desembre</option>\n</select>\n<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>',
  171
+                SelectDateWidget().render('mydate', datetime.date(2009, 12, 31))
  172
+            )
  173
+        finally:
  174
+            deactivate()
  175
+
  176
+    def test_l10n_enabled(self):
  177
+        """
  178
+        Catalan locale
  179
+        """
163 180
         settings.USE_L10N = True
164 181
         activate('ca')
165  
-        self.assertEqual('j \de F \de Y', get_format('DATE_FORMAT'))
166  
-        self.assertEqual(1, get_format('FIRST_DAY_OF_WEEK'))
167  
-        self.assertEqual(',', get_format('DECIMAL_SEPARATOR'))
168  
-        self.assertEqual(u'31 de desembre de 2009', date_format(d))
169  
-        self.assertEqual(u'desembre del 2009', date_format(d, 'YEAR_MONTH_FORMAT'))
170  
-        self.assertEqual(u'31/12/2009 20:50', date_format(dt, 'SHORT_DATETIME_FORMAT'))
171  
-        self.assertEqual('No localizable', localize('No localizable'))
172  
-
173  
-        settings.USE_THOUSAND_SEPARATOR = True
174  
-        self.assertEqual(u'66.666,666', localize(n))
175  
-        self.assertEqual(u'99.999,999', localize(f))
176  
-
177  
-        settings.USE_THOUSAND_SEPARATOR = False
178  
-        self.assertEqual(u'66666,666', localize(n))
179  
-        self.assertEqual(u'99999,999', localize(f))
180  
-        self.assertEqual(u'31 de desembre de 2009', localize(d))
181  
-        self.assertEqual(u'31 de desembre de 2009 a les 20:50', localize(dt))
182  
-
183  
-        settings.USE_THOUSAND_SEPARATOR = True
184  
-        self.assertEqual(u'66.666,666', template.Template('{{ n }}').render(ctxt))
185  
-        self.assertEqual(u'99.999,999', template.Template('{{ f }}').render(ctxt))
186  
-
187  
-        settings.USE_THOUSAND_SEPARATOR = False
188  
-        self.assertEqual(u'66666,666', template.Template('{{ n }}').render(ctxt))
189  
-        self.assertEqual(u'99999,999', template.Template('{{ f }}').render(ctxt))
190  
-        self.assertEqual(u'31 de desembre de 2009', template.Template('{{ d }}').render(ctxt))
191  
-        self.assertEqual(u'31 de desembre de 2009 a les 20:50', template.Template('{{ dt }}').render(ctxt))
192  
-        self.assertEqual(u'66666,67', template.Template('{{ n|floatformat:2 }}').render(ctxt))
193  
-        self.assertEqual(u'100000,0', template.Template('{{ f|floatformat }}').render(ctxt))
194  
-        self.assertEqual(u'31/12/2009', template.Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(ctxt))
195  
-        self.assertEqual(u'31/12/2009 20:50', template.Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(ctxt))
196  
-
197  
-        form3 = I18nForm({
198  
-            'decimal_field': u'66666,666',
199  
-            'float_field': u'99999,999',
200  
-            'date_field': u'31/12/2009',
201  
-            'datetime_field': u'31/12/2009 20:50',
202  
-            'time_field': u'20:50'
203  
-        })
204  
-        self.assertEqual(True, form3.is_valid())
205  
-        self.assertEqual(decimal.Decimal('66666.666'), form3.cleaned_data['decimal_field'])
206  
-        self.assertEqual(99999.999, form3.cleaned_data['float_field'])
207  
-        self.assertEqual(datetime.date(2009, 12, 31), form3.cleaned_data['date_field'])
208  
-        self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), form3.cleaned_data['datetime_field'])
209  
-        self.assertEqual(datetime.time(20, 50), form3.cleaned_data['time_field'])
210  
-
211  
-        form4 = SelectDateForm({
212  
-            'date_field_month': u'12',
213  
-            'date_field_day': u'31',
214  
-            'date_field_year': u'2009'
215  
-        })
216  
-        self.assertEqual(True, form4.is_valid())
217  
-        self.assertEqual(datetime.date(2009, 12, 31), form4.cleaned_data['date_field'])
218  
-        self.assertEqual(u'<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_month" id="id_mydate_month">\n<option value="1">gener</option>\n<option value="2">febrer</option>\n<option value="3">mar\xe7</option>\n<option value="4">abril</option>\n<option value="5">maig</option>\n<option value="6">juny</option>\n<option value="7">juliol</option>\n<option value="8">agost</option>\n<option value="9">setembre</option>\n<option value="10">octubre</option>\n<option value="11">novembre</option>\n<option value="12" selected="selected">desembre</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>', SelectDateWidget().render('mydate', datetime.date(2009, 12, 31)))
219  
-        deactivate()
  182
+        try:
  183
+            self.assertEqual('j \de F \de Y', get_format('DATE_FORMAT'))
  184
+            self.assertEqual(1, get_format('FIRST_DAY_OF_WEEK'))
  185
+            self.assertEqual(',', get_format('DECIMAL_SEPARATOR'))
  186
+            self.assertEqual(u'31 de desembre de 2009', date_format(self.d))
  187
+            self.assertEqual(u'desembre del 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
  188
+            self.assertEqual(u'31/12/2009 20:50', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
  189
+            self.assertEqual('No localizable', localize('No localizable'))
  190
+
  191
+            settings.USE_THOUSAND_SEPARATOR = True
  192
+            self.assertEqual(u'66.666,666', localize(self.n))
  193
+            self.assertEqual(u'99.999,999', localize(self.f))
  194
+
  195
+            settings.USE_THOUSAND_SEPARATOR = False
  196
+            self.assertEqual(u'66666,666', localize(self.n))
  197
+            self.assertEqual(u'99999,999', localize(self.f))
  198
+            self.assertEqual(u'31 de desembre de 2009', localize(self.d))
  199
+            self.assertEqual(u'31 de desembre de 2009 a les 20:50', localize(self.dt))
  200
+
  201
+            settings.USE_THOUSAND_SEPARATOR = True
  202
+            self.assertEqual(u'66.666,666', Template('{{ n }}').render(self.ctxt))
  203
+            self.assertEqual(u'99.999,999', Template('{{ f }}').render(self.ctxt))
  204
+
  205
+            settings.USE_THOUSAND_SEPARATOR = False
  206
+            self.assertEqual(u'66666,666', Template('{{ n }}').render(self.ctxt))
  207
+            self.assertEqual(u'99999,999', Template('{{ f }}').render(self.ctxt))
  208
+            self.assertEqual(u'31 de desembre de 2009', Template('{{ d }}').render(self.ctxt))
  209
+            self.assertEqual(u'31 de desembre de 2009 a les 20:50', Template('{{ dt }}').render(self.ctxt))
  210
+            self.assertEqual(u'66666,67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
  211
+            self.assertEqual(u'100000,0', Template('{{ f|floatformat }}').render(self.ctxt))
  212
+            self.assertEqual(u'31/12/2009', Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(self.ctxt))
  213
+            self.assertEqual(u'31/12/2009 20:50', Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(self.ctxt))
  214
+
  215
+            form3 = I18nForm({
  216
+                'decimal_field': u'66666,666',
  217
+                'float_field': u'99999,999',
  218
+                'date_field': u'31/12/2009',
  219
+                'datetime_field': u'31/12/2009 20:50',
  220
+                'time_field': u'20:50'
  221
+            })
  222
+            self.assertEqual(True, form3.is_valid())
  223
+            self.assertEqual(decimal.Decimal('66666.666'), form3.cleaned_data['decimal_field'])
  224
+            self.assertEqual(99999.999, form3.cleaned_data['float_field'])
  225
+            self.assertEqual(datetime.date(2009, 12, 31), form3.cleaned_data['date_field'])
  226
+            self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), form3.cleaned_data['datetime_field'])
  227
+            self.assertEqual(datetime.time(20, 50), form3.cleaned_data['time_field'])
  228
+
  229
+            form4 = SelectDateForm({
  230
+                'date_field_month': u'12',
  231
+                'date_field_day': u'31',
  232
+                'date_field_year': u'2009'
  233
+            })
  234
+            self.assertEqual(True, form4.is_valid())
  235
+            self.assertEqual(datetime.date(2009, 12, 31), form4.cleaned_data['date_field'])
  236
+            self.assertEqual(
  237
+                u'<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_month" id="id_mydate_month">\n<option value="1">gener</option>\n<option value="2">febrer</option>\n<option value="3">mar\xe7</option>\n<option value="4">abril</option>\n<option value="5">maig</option>\n<option value="6">juny</option>\n<option value="7">juliol</option>\n<option value="8">agost</option>\n<option value="9">setembre</option>\n<option value="10">octubre</option>\n<option value="11">novembre</option>\n<option value="12" selected="selected">desembre</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>',
  238
+                SelectDateWidget().render('mydate', datetime.date(2009, 12, 31))
  239
+            )
  240
+        finally:
  241
+            deactivate()
220 242
 
221 243
         # English locale
222 244
 
223 245
         settings.USE_L10N = True
224 246
         activate('en')
225  
-        self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
226  
-        self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
227  
-        self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
228  
-        self.assertEqual(u'Dec. 31, 2009', date_format(d))
229  
-        self.assertEqual(u'December 2009', date_format(d, 'YEAR_MONTH_FORMAT'))
230  
-        self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(dt, 'SHORT_DATETIME_FORMAT'))
231  
-        self.assertEqual('No localizable', localize('No localizable'))
232  
-
233  
-        settings.USE_THOUSAND_SEPARATOR = True
234  
-        self.assertEqual(u'66,666.666', localize(n))
235  
-        self.assertEqual(u'99,999.999', localize(f))
236  
-
237  
-        settings.USE_THOUSAND_SEPARATOR = False
238  
-        self.assertEqual(u'66666.666', localize(n))
239  
-        self.assertEqual(u'99999.999', localize(f))
240  
-        self.assertEqual(u'Dec. 31, 2009', localize(d))
241  
-        self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', localize(dt))
242  
-
243  
-        settings.USE_THOUSAND_SEPARATOR = True
244  
-        self.assertEqual(u'66,666.666', template.Template('{{ n }}').render(ctxt))
245  
-        self.assertEqual(u'99,999.999', template.Template('{{ f }}').render(ctxt))
246  
-
247  
-        settings.USE_THOUSAND_SEPARATOR = False
248  
-        self.assertEqual(u'66666.666', template.Template('{{ n }}').render(ctxt))
249  
-        self.assertEqual(u'99999.999', template.Template('{{ f }}').render(ctxt))
250  
-        self.assertEqual(u'Dec. 31, 2009', template.Template('{{ d }}').render(ctxt))
251  
-        self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', template.Template('{{ dt }}').render(ctxt))
252  
-        self.assertEqual(u'66666.67', template.Template('{{ n|floatformat:2 }}').render(ctxt))
253  
-        self.assertEqual(u'100000.0', template.Template('{{ f|floatformat }}').render(ctxt))
254  
-        self.assertEqual(u'12/31/2009', template.Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(ctxt))
255  
-        self.assertEqual(u'12/31/2009 8:50 p.m.', template.Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(ctxt))
256  
-
257  
-        form5 = I18nForm({
258  
-            'decimal_field': u'66666.666',
259  
-            'float_field': u'99999.999',
260  
-            'date_field': u'12/31/2009',
261  
-            'datetime_field': u'12/31/2009 20:50',
262  
-            'time_field': u'20:50'
263  
-        })
264  
-        self.assertEqual(True, form5.is_valid())
265  
-        self.assertEqual(decimal.Decimal('66666.666'), form5.cleaned_data['decimal_field'])
266  
-        self.assertEqual(99999.999, form5.cleaned_data['float_field'])
267  
-        self.assertEqual(datetime.date(2009, 12, 31), form5.cleaned_data['date_field'])
268  
-        self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), form5.cleaned_data['datetime_field'])
269  
-        self.assertEqual(datetime.time(20, 50), form5.cleaned_data['time_field'])
270  
-
271  
-        form6 = SelectDateForm({
272  
-            'date_field_month': u'12',
273  
-            'date_field_day': u'31',
274  
-            'date_field_year': u'2009'
275  
-        })
276  
-        self.assertEqual(True, form6.is_valid())
277  
-        self.assertEqual(datetime.date(2009, 12, 31), form6.cleaned_data['date_field'])
278  
-        self.assertEqual(u'<select name="mydate_month" id="id_mydate_month">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12" selected="selected">December</option>\n</select>\n<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>', SelectDateWidget().render('mydate', datetime.date(2009, 12, 31)))
279  
-        deactivate()
280  
-
281  
-        # Check if sublocales fall back to the main locale
  247
+        try:
  248
+            self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
  249
+            self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
  250
+            self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
  251
+            self.assertEqual(u'Dec. 31, 2009', date_format(self.d))
  252
+            self.assertEqual(u'December 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
  253
+            self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
  254
+            self.assertEqual('No localizable', localize('No localizable'))
  255
+
  256
+            settings.USE_THOUSAND_SEPARATOR = True
  257
+            self.assertEqual(u'66,666.666', localize(self.n))
  258
+            self.assertEqual(u'99,999.999', localize(self.f))
  259
+
  260
+            settings.USE_THOUSAND_SEPARATOR = False
  261
+            self.assertEqual(u'66666.666', localize(self.n))
  262
+            self.assertEqual(u'99999.999', localize(self.f))
  263
+            self.assertEqual(u'Dec. 31, 2009', localize(self.d))
  264
+            self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', localize(self.dt))
  265
+
  266
+            settings.USE_THOUSAND_SEPARATOR = True
  267
+            self.assertEqual(u'66,666.666', Template('{{ n }}').render(self.ctxt))
  268
+            self.assertEqual(u'99,999.999', Template('{{ f }}').render(self.ctxt))
  269
+
  270
+            settings.USE_THOUSAND_SEPARATOR = False
  271
+            self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))
  272
+            self.assertEqual(u'99999.999', Template('{{ f }}').render(self.ctxt))
  273
+            self.assertEqual(u'Dec. 31, 2009', Template('{{ d }}').render(self.ctxt))
  274
+            self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', Template('{{ dt }}').render(self.ctxt))
  275
+            self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
  276
+            self.assertEqual(u'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
  277
+            self.assertEqual(u'12/31/2009', Template('{{ d|date:"SHORT_DATE_FORMAT" }}').render(self.ctxt))
  278
+            self.assertEqual(u'12/31/2009 8:50 p.m.', Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(self.ctxt))
  279
+
  280
+            form5 = I18nForm({
  281
+                'decimal_field': u'66666.666',
  282
+                'float_field': u'99999.999',
  283
+                'date_field': u'12/31/2009',
  284
+                'datetime_field': u'12/31/2009 20:50',
  285
+                'time_field': u'20:50'
  286
+            })
  287
+            self.assertEqual(True, form5.is_valid())
  288
+            self.assertEqual(decimal.Decimal('66666.666'), form5.cleaned_data['decimal_field'])
  289
+            self.assertEqual(99999.999, form5.cleaned_data['float_field'])
  290
+            self.assertEqual(datetime.date(2009, 12, 31), form5.cleaned_data['date_field'])
  291
+            self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), form5.cleaned_data['datetime_field'])
  292
+            self.assertEqual(datetime.time(20, 50), form5.cleaned_data['time_field'])
  293
+
  294
+            form6 = SelectDateForm({
  295
+                'date_field_month': u'12',
  296
+                'date_field_day': u'31',
  297
+                'date_field_year': u'2009'
  298
+            })
  299
+            self.assertEqual(True, form6.is_valid())
  300
+            self.assertEqual(datetime.date(2009, 12, 31), form6.cleaned_data['date_field'])
  301
+            self.assertEqual(
  302
+                u'<select name="mydate_month" id="id_mydate_month">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12" selected="selected">December</option>\n</select>\n<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>',
  303
+                SelectDateWidget().render('mydate', datetime.date(2009, 12, 31))
  304
+            )
  305
+        finally:
  306
+            deactivate()
  307
+
  308
+    def test_sub_locales(self):
  309
+        """
  310
+        Check if sublocales fall back to the main locale
  311
+        """
  312
+        settings.USE_L10N = True
282 313
         activate('de-at')
283 314
         settings.USE_THOUSAND_SEPARATOR = True
284  
-        self.assertEqual(u'66.666,666', template.Template('{{ n }}').render(ctxt))
285  
-        deactivate()
286  
-
287  
-        activate('es-ar')
288  
-        self.assertEqual(u'31 de Diciembre de 2009', date_format(d))
289  
-        deactivate()
290  
-
291  
-        # Restore defaults
292  
-        settings.USE_I18N = old_use_i18n
293  
-        settings.USE_L10N = old_use_l10n
294  
-        settings.USE_THOUSAND_SEPARATOR = old_use_thousand_separator
295  
-
  315
+        try:
  316
+            self.assertEqual(u'66.666,666', Template('{{ n }}').render(self.ctxt))
  317
+        finally:
  318
+            deactivate()
  319
+
  320
+        activate('es-us')
  321
+        try:
  322
+            self.assertEqual(u'31 de diciembre de 2009', date_format(self.d))
  323
+        finally:
  324
+            deactivate()
296 325
 
297 326
 class MiscTests(TestCase):
298 327
 

0 notes on commit b5a4aef

Please sign in to comment.
Something went wrong with that request. Please try again.