<s> from unittest import TestCase <EOL> from django . core . exceptions import ValidationError <EOL> from django . core . validators import EMPTY_VALUES <EOL> class LocalFlavorTestCase ( TestCase ) : <EOL> def assertFieldOutput ( self , fieldclass , valid , invalid , field_args = [ ] , <EOL> field_kwargs = { } , empty_value = u'<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> required = fieldclass ( * field_args , ** field_kwargs ) <EOL> optional = fieldclass ( * field_args , ** dict ( field_kwargs , required = False ) ) <EOL> for input , output in valid . items ( ) : <EOL> self . assertEqual ( required . clean ( input ) , output ) <EOL> self . assertEqual ( optional . clean ( input ) , output ) <EOL> for input , errors in invalid . items ( ) : <EOL> try : <EOL> required . clean ( input ) <EOL> except ValidationError , e : <EOL> self . assertEqual ( errors , e . messages ) <EOL> else : <EOL> self . fail ( ) <EOL> try : <EOL> optional . clean ( input ) <EOL> except ValidationError , e : <EOL> self . assertEqual ( errors , e . messages ) <EOL> else : <EOL> self . fail ( ) <EOL> error_required = [ u'<STR_LIT>' ] <EOL> for val in EMPTY_VALUES : <EOL> try : <EOL> required . clean ( val ) <EOL> except ValidationError , e : <EOL> self . assertEqual ( error_required , e . messages ) <EOL> else : <EOL> self . fail ( ) <EOL> self . assertEqual ( optional . clean ( val ) , empty_value ) </s>
