mirror of
https://github.com/django/django.git
synced 2024-12-24 01:55:49 +00:00
Converted Japanese localflavor doctests to unittests. We have always been at war with doctests. Thanks to Idan Gazit.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14946 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f8caeefff1
commit
6e3be3b578
@ -1,60 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Tests for the contrib/localflavor/ JP form fields.
|
||||
from django.contrib.localflavor.jp.forms import (JPPostalCodeField,
|
||||
JPPrefectureSelect)
|
||||
|
||||
tests = r"""
|
||||
# JPPostalCodeField ###############################################################
|
||||
from utils import LocalFlavorTestCase
|
||||
|
||||
A form field that validates its input is a Japanese postcode.
|
||||
|
||||
Accepts 7 digits(with/out hyphen).
|
||||
>>> from django.contrib.localflavor.jp.forms import JPPostalCodeField
|
||||
>>> f = JPPostalCodeField()
|
||||
>>> f.clean('251-0032')
|
||||
u'2510032'
|
||||
>>> f.clean('2510032')
|
||||
u'2510032'
|
||||
>>> f.clean('2510-032')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
>>> f.clean('251a0032')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
>>> f.clean('a51-0032')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
>>> f.clean('25100321')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
|
||||
>>> f = JPPostalCodeField(required=False)
|
||||
>>> f.clean('251-0032')
|
||||
u'2510032'
|
||||
>>> f.clean('2510032')
|
||||
u'2510032'
|
||||
>>> f.clean('2510-032')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
>>> f.clean('')
|
||||
u''
|
||||
>>> f.clean(None)
|
||||
u''
|
||||
|
||||
# JPPrefectureSelect ###############################################################
|
||||
|
||||
A Select widget that uses a list of Japanese prefectures as its choices.
|
||||
>>> from django.contrib.localflavor.jp.forms import JPPrefectureSelect
|
||||
>>> w = JPPrefectureSelect()
|
||||
>>> print w.render('prefecture', 'kanagawa')
|
||||
<select name="prefecture">
|
||||
class JPLocalFlavorTests(LocalFlavorTestCase):
|
||||
def test_JPPrefectureSelect(self):
|
||||
f = JPPrefectureSelect()
|
||||
out = u'''<select name="prefecture">
|
||||
<option value="hokkaido">Hokkaido</option>
|
||||
<option value="aomori">Aomori</option>
|
||||
<option value="iwate">Iwate</option>
|
||||
@ -102,5 +55,19 @@ A Select widget that uses a list of Japanese prefectures as its choices.
|
||||
<option value="miyazaki">Miyazaki</option>
|
||||
<option value="kagoshima">Kagoshima</option>
|
||||
<option value="okinawa">Okinawa</option>
|
||||
</select>
|
||||
"""
|
||||
</select>'''
|
||||
self.assertEqual(f.render('prefecture', 'kanagawa'), out)
|
||||
|
||||
def test_JPPostalCodeField(self):
|
||||
error_format = [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||
valid = {
|
||||
'251-0032': '2510032',
|
||||
'2510032': '2510032',
|
||||
}
|
||||
invalid = {
|
||||
'2510-032': error_format,
|
||||
'251a0032': error_format,
|
||||
'a51-0032': error_format,
|
||||
'25100321': error_format,
|
||||
}
|
||||
self.assertFieldOutput(JPPostalCodeField, valid, invalid)
|
||||
|
@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from localflavor.cz import tests as localflavor_cz_tests
|
||||
from localflavor.jp import tests as localflavor_jp_tests
|
||||
from localflavor.kw import tests as localflavor_kw_tests
|
||||
from localflavor.nl import tests as localflavor_nl_tests
|
||||
from localflavor.pl import tests as localflavor_pl_tests
|
||||
@ -31,12 +30,12 @@ from localflavor.ie import IELocalFlavorTests
|
||||
from localflavor.il import ILLocalFlavorTests
|
||||
from localflavor.is_ import ISLocalFlavorTests
|
||||
from localflavor.it import ITLocalFlavorTests
|
||||
from localflavor.jp import JPLocalFlavorTests
|
||||
from localflavor.tr import TRLocalFlavorTests
|
||||
|
||||
|
||||
__test__ = {
|
||||
'localflavor_cz_tests': localflavor_cz_tests,
|
||||
'localflavor_jp_tests': localflavor_jp_tests,
|
||||
'localflavor_kw_tests': localflavor_kw_tests,
|
||||
'localflavor_nl_tests': localflavor_nl_tests,
|
||||
'localflavor_pl_tests': localflavor_pl_tests,
|
||||
|
@ -31,5 +31,6 @@ from regressiontests.forms.localflavortests import (
|
||||
ILLocalFlavorTests,
|
||||
ISLocalFlavorTests,
|
||||
ITLocalFlavorTests,
|
||||
JPLocalFlavorTests,
|
||||
TRLocalFlavorTests,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user