Converted Portuguese 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@14950 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-12-18 20:32:41 +00:00
parent f9e6ca1026
commit 8f012072af
3 changed files with 30 additions and 104 deletions

View File

@ -1,106 +1,32 @@
# -*- coding: utf-8 -*- from django.contrib.localflavor.pt.forms import PTZipCodeField, PTPhoneNumberField
# Tests for the contrib/localflavor/ PT form fields.
tests = r""" from utils import LocalFlavorTestCase
# PTZipCodeField #############################################################
PTZipCodeField validates that the data is a valid PT zipcode.
>>> from django.contrib.localflavor.pt.forms import PTZipCodeField
>>> f = PTZipCodeField()
>>> f.clean('3030-034')
u'3030-034'
>>> f.clean('1003456')
u'1003-456'
>>> f.clean('2A200')
Traceback (most recent call last):
...
ValidationError: [u'Enter a zip code in the format XXXX-XXX.']
>>> f.clean('980001')
Traceback (most recent call last):
...
ValidationError: [u'Enter a zip code in the format XXXX-XXX.']
>>> 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 = PTZipCodeField(required=False) class PTLocalFlavorTests(LocalFlavorTestCase):
>>> f.clean('3030-034') def test_PTZipCodeField(self):
u'3030-034' error_format = [u'Enter a zip code in the format XXXX-XXX.']
>>> f.clean('1003456') valid = {
u'1003-456' '3030-034': '3030-034',
>>> f.clean('2A200') '1003456': '1003-456',
Traceback (most recent call last): }
... invalid = {
ValidationError: [u'Enter a zip code in the format XXXX-XXX.'] '2A200': error_format,
>>> f.clean('980001') '980001': error_format,
Traceback (most recent call last): }
... self.assertFieldOutput(PTZipCodeField, valid, invalid)
ValidationError: [u'Enter a zip code in the format XXXX-XXX.']
>>> f.clean(None)
u''
>>> f.clean('')
u''
# PTPhoneNumberField ########################################################## def test_PTPhoneNumberField(self):
error_format = [u'Phone numbers must have 9 digits, or start by + or 00']
PTPhoneNumberField validates that the data is a valid Portuguese phone number. valid = {
It's normalized to XXXXXXXXX format or +X(X) for international numbers. Dots are valid too. '917845189': '917845189',
>>> from django.contrib.localflavor.pt.forms import PTPhoneNumberField '91 784 5189': '917845189',
>>> f = PTPhoneNumberField() '91 784 5189': '917845189',
>>> f.clean('917845189') '+351 91 111': '+35191111',
u'917845189' '00351873': '00351873',
>>> f.clean('91 784 5189') }
u'917845189' invalid = {
>>> f.clean('91 784 5189') '91 784 51 8': error_format,
u'917845189' '091 456 987 1': error_format,
>>> f.clean('+351 91 111') }
u'+35191111' self.assertFieldOutput(PTPhoneNumberField, valid, invalid)
>>> f.clean('00351873')
u'00351873'
>>> f.clean('91 784 51 8')
Traceback (most recent call last):
...
ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.']
>>> f.clean('091 456 987 1')
Traceback (most recent call last):
...
ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.']
>>> 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 = PTPhoneNumberField(required=False)
>>> f.clean('917845189')
u'917845189'
>>> f.clean('91 784 5189')
u'917845189'
>>> f.clean('91 784 5189')
u'917845189'
>>> f.clean('+351 91 111')
u'+35191111'
>>> f.clean('00351873')
u'00351873'
>>> f.clean('91 784 51 8')
Traceback (most recent call last):
...
ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.']
>>> f.clean('091 456 987 1')
Traceback (most recent call last):
...
ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.']
>>> f.clean(None)
u''
>>> f.clean('')
u''
"""

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from localflavor.cz import tests as localflavor_cz_tests from localflavor.cz import tests as localflavor_cz_tests
from localflavor.pt import tests as localflavor_pt_tests
from localflavor.ro import tests as localflavor_ro_tests from localflavor.ro import tests as localflavor_ro_tests
from localflavor.se import tests as localflavor_se_tests from localflavor.se import tests as localflavor_se_tests
from localflavor.sk import tests as localflavor_sk_tests from localflavor.sk import tests as localflavor_sk_tests
@ -31,12 +30,12 @@ from localflavor.jp import JPLocalFlavorTests
from localflavor.kw import KWLocalFlavorTests from localflavor.kw import KWLocalFlavorTests
from localflavor.nl import NLLocalFlavorTests from localflavor.nl import NLLocalFlavorTests
from localflavor.pl import PLLocalFlavorTests from localflavor.pl import PLLocalFlavorTests
from localflavor.pt import PTLocalFlavorTests
from localflavor.tr import TRLocalFlavorTests from localflavor.tr import TRLocalFlavorTests
__test__ = { __test__ = {
'localflavor_cz_tests': localflavor_cz_tests, 'localflavor_cz_tests': localflavor_cz_tests,
'localflavor_pt_tests': localflavor_pt_tests,
'localflavor_ro_tests': localflavor_ro_tests, 'localflavor_ro_tests': localflavor_ro_tests,
'localflavor_se_tests': localflavor_se_tests, 'localflavor_se_tests': localflavor_se_tests,
'localflavor_sk_tests': localflavor_sk_tests, 'localflavor_sk_tests': localflavor_sk_tests,

View File

@ -35,5 +35,6 @@ from regressiontests.forms.localflavortests import (
KWLocalFlavorTests, KWLocalFlavorTests,
NLLocalFlavorTests, NLLocalFlavorTests,
PLLocalFlavorTests, PLLocalFlavorTests,
PTLocalFlavorTests,
TRLocalFlavorTests, TRLocalFlavorTests,
) )