From 6e3be3b578477dfef5f66ec40f5dc36338f28b56 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 18 Dec 2010 20:31:58 +0000 Subject: [PATCH] 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 --- tests/regressiontests/forms/localflavor/jp.py | 79 ++++++------------- .../regressiontests/forms/localflavortests.py | 3 +- tests/regressiontests/forms/tests/__init__.py | 1 + 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/tests/regressiontests/forms/localflavor/jp.py b/tests/regressiontests/forms/localflavor/jp.py index 7b5b82667c..1f8362a092 100644 --- a/tests/regressiontests/forms/localflavor/jp.py +++ b/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') - @@ -102,5 +55,19 @@ A Select widget that uses a list of Japanese prefectures as its choices. - -""" +''' + 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) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index e7d5637392..d0e754de21 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/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.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, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 345ed855f5..c1e0e37df9 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -31,5 +31,6 @@ from regressiontests.forms.localflavortests import ( ILLocalFlavorTests, ISLocalFlavorTests, ITLocalFlavorTests, + JPLocalFlavorTests, TRLocalFlavorTests, )