From 6127cf13cd6d6e20172b105b231ab9561718f0ef Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 18 Dec 2010 20:30:38 +0000 Subject: [PATCH] Converted French localflavor doctests into unittests. We have always been at war with doctests. Thanks to Idan Gazit. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14939 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor/fr.py | 145 ++++-------------- .../regressiontests/forms/localflavortests.py | 3 +- tests/regressiontests/forms/tests/__init__.py | 1 + 3 files changed, 36 insertions(+), 113 deletions(-) diff --git a/tests/regressiontests/forms/localflavor/fr.py b/tests/regressiontests/forms/localflavor/fr.py index d602c3b335..96045c32a9 100644 --- a/tests/regressiontests/forms/localflavor/fr.py +++ b/tests/regressiontests/forms/localflavor/fr.py @@ -1,117 +1,40 @@ -# -*- coding: utf-8 -*- -# Tests for the contrib/localflavor/ FR form fields. +from django.contrib.localflavor.fr.forms import (FRZipCodeField, + FRPhoneNumberField, FRDepartmentSelect) -tests = r""" -# FRZipCodeField ############################################################# - -FRZipCodeField validates that the data is a valid FR zipcode. ->>> from django.contrib.localflavor.fr.forms import FRZipCodeField ->>> f = FRZipCodeField() ->>> f.clean('75001') -u'75001' ->>> f.clean('93200') -u'93200' ->>> f.clean('2A200') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean('980001') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean(None) -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f.clean('') -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] - ->>> f = FRZipCodeField(required=False) ->>> f.clean('75001') -u'75001' ->>> f.clean('93200') -u'93200' ->>> f.clean('2A200') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean('980001') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean(None) -u'' ->>> f.clean('') -u'' +from utils import LocalFlavorTestCase -# FRPhoneNumberField ########################################################## +class FRLocalFlavorTests(LocalFlavorTestCase): + def test_FRZipCodeField(self): + error_format = [u'Enter a zip code in the format XXXXX.'] + valid = { + '75001': '75001', + '93200': '93200', + } + invalid = { + '2A200': error_format, + '980001': error_format, + } + self.assertFieldOutput(FRZipCodeField, valid, invalid) -FRPhoneNumberField validates that the data is a valid french phone number. -It's normalized to 0X XX XX XX XX format. Dots are valid too. ->>> from django.contrib.localflavor.fr.forms import FRPhoneNumberField ->>> f = FRPhoneNumberField() ->>> f.clean('01 55 44 58 64') -u'01 55 44 58 64' ->>> f.clean('0155445864') -u'01 55 44 58 64' ->>> f.clean('01 5544 5864') -u'01 55 44 58 64' ->>> f.clean('01 55.44.58.64') -u'01 55 44 58 64' ->>> f.clean('01.55.44.58.64') -u'01 55 44 58 64' ->>> f.clean('01,55,44,58,64') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] ->>> f.clean('555 015 544') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] ->>> f.clean(None) -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f.clean('') -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] + def test_FRPhoneNumberField(self): + error_format = [u'Phone numbers must be in 0X XX XX XX XX format.'] + valid = { + '01 55 44 58 64': '01 55 44 58 64', + '0155445864': '01 55 44 58 64', + '01 5544 5864': '01 55 44 58 64', + '01 55.44.58.64': '01 55 44 58 64', + '01.55.44.58.64': '01 55 44 58 64', + } + invalid = { + '01,55,44,58,64': error_format, + '555 015 544': error_format, + } + self.assertFieldOutput(FRPhoneNumberField, valid, invalid) ->>> f = FRPhoneNumberField(required=False) ->>> f.clean('01 55 44 58 64') -u'01 55 44 58 64' ->>> f.clean('0155445864') -u'01 55 44 58 64' ->>> f.clean('01 5544 5864') -u'01 55 44 58 64' ->>> f.clean('01 55.44.58.64') -u'01 55 44 58 64' ->>> f.clean('01.55.44.58.64') -u'01 55 44 58 64' ->>> f.clean('01,55,44,58,64') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] ->>> f.clean('555 015 544') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] ->>> f.clean(None) -u'' ->>> f.clean('') -u'' - -# FRDepartmentSelect ############################################################### - -FRDepartmentSelect is a Select widget that uses a list of french departments -including DOM TOM ->>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect ->>> w = FRDepartmentSelect() ->>> print w.render('dep', 'Paris') - @@ -218,5 +141,5 @@ including DOM TOM - -""" +''' + self.assertEqual(f.render('dep', 'Paris'), out) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 11b4b5c15d..921148c854 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.fr import tests as localflavor_fr_tests from localflavor.generic import tests as localflavor_generic_tests from localflavor.id import tests as localflavor_id_tests from localflavor.ie import tests as localflavor_ie_tests @@ -30,13 +29,13 @@ from localflavor.cl import CLLocalFlavorTests from localflavor.de import DELocalFlavorTests from localflavor.es import ESLocalFlavorTests from localflavor.fi import FILocalFlavorTests +from localflavor.fr import FRLocalFlavorTests from localflavor.il import ILLocalFlavorTests from localflavor.tr import TRLocalFlavorTests __test__ = { 'localflavor_cz_tests': localflavor_cz_tests, - 'localflavor_fr_tests': localflavor_fr_tests, 'localflavor_generic_tests': localflavor_generic_tests, 'localflavor_id_tests': localflavor_id_tests, 'localflavor_ie_tests': localflavor_ie_tests, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index ea3ea78ef6..99845d42be 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -24,6 +24,7 @@ from regressiontests.forms.localflavortests import ( DELocalFlavorTests, ESLocalFlavorTests, FILocalFlavorTests, + FRLocalFlavorTests, ILLocalFlavorTests, TRLocalFlavorTests, )