<s> from django . contrib . gis . gdal import SpatialReference , CoordTransform , OGRException , SRSException <EOL> from django . utils import unittest <EOL> class TestSRS : <EOL> def __init__ ( self , wkt , ** kwargs ) : <EOL> self . wkt = wkt <EOL> for key , value in kwargs . items ( ) : <EOL> setattr ( self , key , value ) <EOL> srlist = ( TestSRS ( '<STR_LIT>' , <EOL> proj = '<STR_LIT>' , <EOL> epsg = <NUM_LIT> , projected = False , geographic = True , local = False , <EOL> lin_name = '<STR_LIT>' , ang_name = '<STR_LIT>' , lin_units = <NUM_LIT:1.0> , ang_units = <NUM_LIT> , <EOL> auth = { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) } , <EOL> attr = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( ( '<STR_LIT>' , <NUM_LIT:1> ) , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ) , <EOL> ) , <EOL> TestSRS ( '<STR_LIT>' , <EOL> proj = None , epsg = <NUM_LIT> , projected = True , geographic = False , local = False , <EOL> lin_name = '<STR_LIT>' , ang_name = '<STR_LIT>' , lin_units = <NUM_LIT:1.0> , ang_units = <NUM_LIT> , <EOL> auth = { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , } , <EOL> attr = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( ( '<STR_LIT>' , <NUM_LIT:2> ) , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ) , <EOL> ) , <EOL> TestSRS ( '<STR_LIT>' , <EOL> proj = None , epsg = None , projected = True , geographic = False , local = False , <EOL> lin_name = '<STR_LIT>' , ang_name = '<STR_LIT>' , lin_units = <NUM_LIT> , ang_units = <NUM_LIT> , <EOL> auth = { '<STR_LIT>' : ( None , None ) , } , <EOL> attr = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( ( '<STR_LIT>' , <NUM_LIT:9> ) , '<STR_LIT>' ) , ( ( '<STR_LIT>' , <NUM_LIT:11> ) , None ) , ) , <EOL> ) , <EOL> TestSRS ( '<STR_LIT>' , <EOL> esri = True , proj = None , epsg = None , projected = False , geographic = False , local = True , <EOL> lin_name = '<STR_LIT>' , ang_name = '<STR_LIT>' , lin_units = <NUM_LIT:1.0> , ang_units = <NUM_LIT> , <EOL> attr = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ) , <EOL> ) <EOL> well_known = ( TestSRS ( '<STR_LIT>' , wk = '<STR_LIT>' , name = '<STR_LIT>' , attrs = ( ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> TestSRS ( '<STR_LIT>' , wk = '<STR_LIT>' , name = '<STR_LIT>' , attrs = ( ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> TestSRS ( '<STR_LIT>' , wk = '<STR_LIT>' , name = '<STR_LIT>' , attrs = ( ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> TestSRS ( '<STR_LIT>' , wk = '<STR_LIT>' , name = '<STR_LIT>' , attrs = ( ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> TestSRS ( '<STR_LIT>' , wk = '<STR_LIT>' , name = '<STR_LIT>' , attrs = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> ) <EOL> bad_srlist = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> class SpatialRefTest ( unittest . TestCase ) : <EOL> def test01_wkt ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> srs = SpatialReference ( s . wkt ) <EOL> def test02_bad_wkt ( self ) : <EOL> "<STR_LIT>" <EOL> for bad in bad_srlist : <EOL> try : <EOL> srs = SpatialReference ( bad ) <EOL> srs . validate ( ) <EOL> except ( SRSException , OGRException ) : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test03_get_wkt ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> srs = SpatialReference ( s . wkt ) <EOL> self . assertEqual ( s . wkt , srs . wkt ) <EOL> def test04_proj ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> if s . proj : <EOL> srs1 = SpatialReference ( s . wkt ) <EOL> srs2 = SpatialReference ( s . proj ) <EOL> self . assertEqual ( srs1 . proj , srs2 . proj ) <EOL> def test05_epsg ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> if s . epsg : <EOL> srs1 = SpatialReference ( s . wkt ) <EOL> srs2 = SpatialReference ( s . epsg ) <EOL> srs3 = SpatialReference ( str ( s . epsg ) ) <EOL> srs4 = SpatialReference ( '<STR_LIT>' % s . epsg ) <EOL> for srs in ( srs1 , srs2 , srs3 , srs4 ) : <EOL> for attr , expected in s . attr : <EOL> self . assertEqual ( expected , srs [ attr ] ) <EOL> def test07_boolean_props ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> srs = SpatialReference ( s . wkt ) <EOL> self . assertEqual ( s . projected , srs . projected ) <EOL> self . assertEqual ( s . geographic , srs . geographic ) <EOL> def test08_angular_linear ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> srs = SpatialReference ( s . wkt ) <EOL> self . assertEqual ( s . ang_name , srs . angular_name ) <EOL> self . assertEqual ( s . lin_name , srs . linear_name ) <EOL> self . assertAlmostEqual ( s . ang_units , srs . angular_units , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( s . lin_units , srs . linear_units , <NUM_LIT:9> ) <EOL> def test09_authority ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> srs = SpatialReference ( s . wkt ) <EOL> for target , tup in s . auth . items ( ) : <EOL> self . assertEqual ( tup [ <NUM_LIT:0> ] , srs . auth_name ( target ) ) <EOL> self . assertEqual ( tup [ <NUM_LIT:1> ] , srs . auth_code ( target ) ) <EOL> def test10_attributes ( self ) : <EOL> "<STR_LIT>" <EOL> for s in srlist : <EOL> srs = SpatialReference ( s . wkt ) <EOL> for tup in s . attr : <EOL> att = tup [ <NUM_LIT:0> ] <EOL> exp = tup [ <NUM_LIT:1> ] <EOL> self . assertEqual ( exp , srs [ att ] ) <EOL> def test11_wellknown ( self ) : <EOL> "<STR_LIT>" <EOL> for s in well_known : <EOL> srs = SpatialReference ( s . wk ) <EOL> self . assertEqual ( s . name , srs . name ) <EOL> for tup in s . attrs : <EOL> if len ( tup ) == <NUM_LIT:2> : <EOL> key = tup [ <NUM_LIT:0> ] <EOL> exp = tup [ <NUM_LIT:1> ] <EOL> elif len ( tup ) == <NUM_LIT:3> : <EOL> key = tup [ : <NUM_LIT:2> ] <EOL> exp = tup [ <NUM_LIT:2> ] <EOL> self . assertEqual ( srs [ key ] , exp ) <EOL> def test12_coordtransform ( self ) : <EOL> "<STR_LIT>" <EOL> target = SpatialReference ( '<STR_LIT>' ) <EOL> for s in srlist : <EOL> if s . proj : <EOL> ct = CoordTransform ( SpatialReference ( s . wkt ) , target ) <EOL> def test13_attr_value ( self ) : <EOL> "<STR_LIT>" <EOL> s1 = SpatialReference ( '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , s1 . __getitem__ , <NUM_LIT:0> ) <EOL> self . assertRaises ( TypeError , s1 . __getitem__ , ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , s1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , s1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , s1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT> , int ( s1 [ '<STR_LIT>' , <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( None , s1 [ '<STR_LIT>' ] ) <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . makeSuite ( SpatialRefTest ) ) <EOL> return s <EOL> def run ( verbosity = <NUM_LIT:2> ) : <EOL> unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ( ) ) </s>
