From 187a11e1f14ed655c98ad94699ccfb314f6690ea Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 18 Dec 2010 20:32:17 +0000 Subject: [PATCH] Converted Dutch 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@14948 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor/nl.py | 122 ++++++++---------- .../regressiontests/forms/localflavortests.py | 3 +- tests/regressiontests/forms/tests/__init__.py | 1 + 3 files changed, 58 insertions(+), 68 deletions(-) diff --git a/tests/regressiontests/forms/localflavor/nl.py b/tests/regressiontests/forms/localflavor/nl.py index 25241d0786..8ef0ae981f 100644 --- a/tests/regressiontests/forms/localflavor/nl.py +++ b/tests/regressiontests/forms/localflavor/nl.py @@ -1,72 +1,62 @@ -# -*- coding: utf-8 -*- -# Tests for the contrib/localflavor/ NL form fields. +from django.contrib.localflavor.nl.forms import (NLPhoneNumberField, + NLZipCodeField, NLSoFiNumberField, NLProvinceSelect) -tests = r""" -# NLPhoneNumberField ######################################################## +from utils import LocalFlavorTestCase ->>> from django.contrib.localflavor.nl.forms import NLPhoneNumberField ->>> f = NLPhoneNumberField(required=False) ->>> f.clean('') -u'' ->>> f.clean('012-3456789') -'012-3456789' ->>> f.clean('0123456789') -'0123456789' ->>> f.clean('+31-12-3456789') -'+31-12-3456789' ->>> f.clean('(0123) 456789') -'(0123) 456789' ->>> f.clean('foo') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid phone number'] -# NLZipCodeField ############################################################ +class NLLocalFlavorTests(LocalFlavorTestCase): + def test_NLProvinceSelect(self): + f = NLProvinceSelect() + out = u'''''' + self.assertEqual(f.render('provinces', 'OV'), out) ->>> from django.contrib.localflavor.nl.forms import NLZipCodeField ->>> f = NLZipCodeField(required=False) ->>> f.clean('') -u'' ->>> f.clean('1234ab') -u'1234 AB' ->>> f.clean('1234 ab') -u'1234 AB' ->>> f.clean('1234 AB') -u'1234 AB' ->>> f.clean('0123AB') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid postal code'] ->>> f.clean('foo') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid postal code'] + def test_NLPhoneNumberField(self): + error_invalid = [u'Enter a valid phone number'] + valid = { + '012-3456789': '012-3456789', + '0123456789': '0123456789', + '+31-12-3456789': '+31-12-3456789', + '(0123) 456789': '(0123) 456789', + } + invalid = { + 'foo': error_invalid, + } + self.assertFieldOutput(NLPhoneNumberField, valid, invalid) -# NLSoFiNumberField ######################################################### + def test_NLZipCodeField(self): + error_invalid = [u'Enter a valid postal code'] + valid = { + '1234ab': '1234 AB', + '1234 ab': '1234 AB', + '1234 AB': '1234 AB', + } + invalid = { + '0123AB': error_invalid, + 'foo': error_invalid, + } + self.assertFieldOutput(NLZipCodeField, valid, invalid) ->>> from django.contrib.localflavor.nl.forms import NLSoFiNumberField ->>> f = NLSoFiNumberField(required=False) ->>> f.clean('') -u'' ->>> f.clean('123456782') -'123456782' ->>> f.clean('000000000') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid SoFi number'] ->>> f.clean('123456789') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid SoFi number'] ->>> f.clean('foo') -Traceback (most recent call last): - ... -ValidationError: [u'Enter a valid SoFi number'] - -# NLProvinceSelect ########################################################## - ->>> from django.contrib.localflavor.nl.forms import NLProvinceSelect ->>> s = NLProvinceSelect() ->>> s.render('provinces', 'OV') -u'' -""" + def test_NLSoFiNumberField(self): + error_invalid = [u'Enter a valid SoFi number'] + valid = { + '123456782': '123456782', + } + invalid = { + '000000000': error_invalid, + '123456789': error_invalid, + 'foo': error_invalid, + } + self.assertFieldOutput(NLSoFiNumberField, valid, invalid) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 56ea2d5d98..ef4136ec60 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.nl import tests as localflavor_nl_tests from localflavor.pl import tests as localflavor_pl_tests from localflavor.pt import tests as localflavor_pt_tests from localflavor.ro import tests as localflavor_ro_tests @@ -31,12 +30,12 @@ from localflavor.is_ import ISLocalFlavorTests from localflavor.it import ITLocalFlavorTests from localflavor.jp import JPLocalFlavorTests from localflavor.kw import KWLocalFlavorTests +from localflavor.nl import NLLocalFlavorTests from localflavor.tr import TRLocalFlavorTests __test__ = { 'localflavor_cz_tests': localflavor_cz_tests, - 'localflavor_nl_tests': localflavor_nl_tests, 'localflavor_pl_tests': localflavor_pl_tests, 'localflavor_pt_tests': localflavor_pt_tests, 'localflavor_ro_tests': localflavor_ro_tests, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 13b393f72e..00633ad21c 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -33,5 +33,6 @@ from regressiontests.forms.localflavortests import ( ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests, + NLLocalFlavorTests, TRLocalFlavorTests, )