<s> from __future__ import unicode_literals <EOL> from django . forms import FloatField , NumberInput , ValidationError <EOL> from django . test import SimpleTestCase <EOL> from django . utils import formats , translation <EOL> from . import FormFieldAssertionsMixin <EOL> class FloatFieldTest ( FormFieldAssertionsMixin , SimpleTestCase ) : <EOL> def test_floatfield_1 ( self ) : <EOL> f = FloatField ( ) <EOL> self . assertWidgetRendersTo ( f , '<STR_LIT>' ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( None ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , f . clean ( '<STR_LIT:1>' ) ) <EOL> self . assertIsInstance ( f . clean ( '<STR_LIT:1>' ) , float ) <EOL> self . assertEqual ( <NUM_LIT> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT> , f . clean ( <NUM_LIT> ) ) <EOL> self . assertEqual ( <NUM_LIT> , f . clean ( <NUM_LIT> ) ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT:a>' ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , f . clean ( '<STR_LIT>' ) ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> self . assertIsNone ( f . max_value ) <EOL> self . assertIsNone ( f . min_value ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> def test_floatfield_2 ( self ) : <EOL> f = FloatField ( required = False ) <EOL> self . assertIsNone ( f . clean ( '<STR_LIT>' ) ) <EOL> self . assertIsNone ( f . clean ( None ) ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , f . clean ( '<STR_LIT:1>' ) ) <EOL> self . assertIsNone ( f . max_value ) <EOL> self . assertIsNone ( f . min_value ) <EOL> def test_floatfield_3 ( self ) : <EOL> f = FloatField ( max_value = <NUM_LIT> , min_value = <NUM_LIT:0.5> ) <EOL> self . assertWidgetRendersTo ( <EOL> f , <EOL> '<STR_LIT>' , <EOL> ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> with self . assertRaisesMessage ( ValidationError , "<STR_LIT>" ) : <EOL> f . clean ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:0.5> , f . clean ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( f . max_value , <NUM_LIT> ) <EOL> self . assertEqual ( f . min_value , <NUM_LIT:0.5> ) <EOL> def test_floatfield_widget_attrs ( self ) : <EOL> f = FloatField ( widget = NumberInput ( attrs = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : <NUM_LIT:0.0> } ) ) <EOL> self . assertWidgetRendersTo ( <EOL> f , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def test_floatfield_localized ( self ) : <EOL> """<STR_LIT>""" <EOL> f = FloatField ( localize = True ) <EOL> self . assertWidgetRendersTo ( f , '<STR_LIT>' ) <EOL> def test_floatfield_changed ( self ) : <EOL> f = FloatField ( ) <EOL> n = <NUM_LIT> <EOL> self . assertFalse ( f . has_changed ( n , '<STR_LIT>' ) ) <EOL> with translation . override ( '<STR_LIT>' ) , self . settings ( USE_L10N = True ) : <EOL> f = FloatField ( localize = True ) <EOL> localized_n = formats . localize_input ( n ) <EOL> self . assertFalse ( f . has_changed ( n , localized_n ) ) </s>
