<s> from django . forms import ValidationError <EOL> from django . contrib . gis import forms <EOL> from django . contrib . gis . geos import GEOSGeometry <EOL> from django . utils import unittest <EOL> class GeometryFieldTest ( unittest . TestCase ) : <EOL> def test00_init ( self ) : <EOL> "<STR_LIT>" <EOL> fld = forms . GeometryField ( ) <EOL> for bad_default in ( '<STR_LIT>' , <NUM_LIT:3> , '<STR_LIT>' , None , <NUM_LIT:0> ) : <EOL> self . assertRaises ( ValidationError , fld . clean , bad_default ) <EOL> def test01_srid ( self ) : <EOL> "<STR_LIT>" <EOL> fld = forms . GeometryField ( srid = <NUM_LIT> ) <EOL> geom = fld . clean ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , geom . srid ) <EOL> fld = forms . GeometryField ( srid = <NUM_LIT> ) <EOL> tol = <NUM_LIT> <EOL> xform_geom = GEOSGeometry ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> cleaned_geom = fld . clean ( '<STR_LIT>' ) <EOL> self . assertTrue ( xform_geom . equals_exact ( cleaned_geom , tol ) ) <EOL> def test02_null ( self ) : <EOL> "<STR_LIT>" <EOL> fld = forms . GeometryField ( ) <EOL> self . assertRaises ( forms . ValidationError , fld . clean , None ) <EOL> fld = forms . GeometryField ( required = False , null = False ) <EOL> self . assertRaises ( forms . ValidationError , fld . clean , None ) <EOL> fld = forms . GeometryField ( required = False ) <EOL> self . assertEqual ( None , fld . clean ( None ) ) <EOL> def test03_geom_type ( self ) : <EOL> "<STR_LIT>" <EOL> fld = forms . GeometryField ( ) <EOL> for wkt in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertEqual ( GEOSGeometry ( wkt ) , fld . clean ( wkt ) ) <EOL> pnt_fld = forms . GeometryField ( geom_type = '<STR_LIT>' ) <EOL> self . assertEqual ( GEOSGeometry ( '<STR_LIT>' ) , pnt_fld . clean ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( forms . ValidationError , pnt_fld . clean , '<STR_LIT>' ) <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . makeSuite ( GeometryFieldTest ) ) <EOL> return s <EOL> def run ( verbosity = <NUM_LIT:2> ) : <EOL> unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run ( ) </s>
