Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 6e3be3b578477dfef5f66ec40f5dc36338f28b56 1 parent f8caeef
@alex alex authored
View
79 tests/regressiontests/forms/localflavor/jp.py
@@ -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 @@
<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)
View
3  tests/regressiontests/forms/localflavortests.py
@@ -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.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,
View
1  tests/regressiontests/forms/tests/__init__.py
@@ -31,5 +31,6 @@
ILLocalFlavorTests,
ISLocalFlavorTests,
ITLocalFlavorTests,
+ JPLocalFlavorTests,
TRLocalFlavorTests,
)

0 comments on commit 6e3be3b

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