<s> from wtforms import Form <EOL> from wtforms_test import FormTestCase <EOL> from tests import MultiDict <EOL> from wtforms_components import ColorField <EOL> class TestColorField ( FormTestCase ) : <EOL> def setup_method ( self , method ) : <EOL> self . valid_colors = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . invalid_colors = [ <EOL> '<STR_LIT:abc>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def init_form ( self , ** kwargs ) : <EOL> class TestForm ( Form ) : <EOL> color = ColorField ( ** kwargs ) <EOL> self . form_class = TestForm <EOL> return self . form_class <EOL> def test_valid_colors ( self ) : <EOL> form_class = self . init_form ( ) <EOL> for color in self . valid_colors : <EOL> form = form_class ( MultiDict ( color = color ) ) <EOL> form . validate ( ) <EOL> assert len ( form . errors ) == <NUM_LIT:0> <EOL> def test_invalid_number_ranges ( self ) : <EOL> form_class = self . init_form ( ) <EOL> for color in self . invalid_colors : <EOL> form = form_class ( MultiDict ( color = color ) ) <EOL> form . validate ( ) <EOL> assert len ( form . errors [ '<STR_LIT>' ] ) == <NUM_LIT:1> <EOL> def test_field_rendering_when_validation_fails ( self ) : <EOL> form_class = self . init_form ( ) <EOL> form = form_class ( MultiDict ( color = '<STR_LIT>' ) ) <EOL> form . validate ( ) <EOL> assert '<STR_LIT>' in str ( form . color ) <EOL> def test_converts_empty_strings_to_none ( self ) : <EOL> form_class = self . init_form ( ) <EOL> form = form_class ( MultiDict ( color = '<STR_LIT>' ) ) <EOL> assert form . data == { '<STR_LIT>' : None } </s>
