<s> import re <EOL> import unittest <EOL> from django . contrib . gis . gdal import HAS_GDAL <EOL> from django . db import connection <EOL> from django . test import mock , skipUnlessDBFeature <EOL> from django . utils import six <EOL> from . utils import SpatialRefSys , oracle , postgis , spatialite <EOL> test_srs = ( { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : False , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:9> ) , <EOL> '<STR_LIT>' : re . sub ( '<STR_LIT>' , '<STR_LIT>' , """<STR_LIT>""" ) <EOL> } , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , '<STR_LIT>' : True , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> ) , <EOL> } ) <EOL> @ unittest . skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> class SpatialRefSysTest ( unittest . TestCase ) : <EOL> def test_get_units ( self ) : <EOL> epsg_4326 = next ( f for f in test_srs if f [ '<STR_LIT>' ] == <NUM_LIT> ) <EOL> unit , unit_name = SpatialRefSys ( ) . get_units ( epsg_4326 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( unit_name , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( unit , <NUM_LIT> ) <EOL> @ mock . patch ( '<STR_LIT>' , False ) <EOL> def test_get_units_without_gdal ( self ) : <EOL> epsg_4326 = next ( f for f in test_srs if f [ '<STR_LIT>' ] == <NUM_LIT> ) <EOL> unit , unit_name = SpatialRefSys ( ) . get_units ( epsg_4326 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( unit_name , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( unit , <NUM_LIT> ) <EOL> def test_retrieve ( self ) : <EOL> """<STR_LIT>""" <EOL> for sd in test_srs : <EOL> srs = SpatialRefSys . objects . get ( srid = sd [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( sd [ '<STR_LIT>' ] , srs . srid ) <EOL> auth_name , oracle_flag = sd [ '<STR_LIT>' ] <EOL> if postgis or ( oracle and oracle_flag ) : <EOL> self . assertTrue ( srs . auth_name . startswith ( auth_name ) ) <EOL> self . assertEqual ( sd [ '<STR_LIT>' ] , srs . auth_srid ) <EOL> if postgis : <EOL> self . assertTrue ( srs . wkt . startswith ( sd [ '<STR_LIT>' ] ) ) <EOL> six . assertRegex ( self , srs . proj4text , sd [ '<STR_LIT>' ] ) <EOL> def test_osr ( self ) : <EOL> """<STR_LIT>""" <EOL> for sd in test_srs : <EOL> sr = SpatialRefSys . objects . get ( srid = sd [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( sr . spheroid . startswith ( sd [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( sd [ '<STR_LIT>' ] , sr . geographic ) <EOL> self . assertEqual ( sd [ '<STR_LIT>' ] , sr . projected ) <EOL> if not ( spatialite and not sd [ '<STR_LIT>' ] ) : <EOL> self . assertTrue ( sr . name . startswith ( sd [ '<STR_LIT:name>' ] ) ) <EOL> if postgis or spatialite : <EOL> srs = sr . srs <EOL> six . assertRegex ( self , srs . proj4 , sd [ '<STR_LIT>' ] ) <EOL> if not spatialite or connection . ops . spatial_version [ <NUM_LIT:0> ] >= <NUM_LIT:4> : <EOL> self . assertTrue ( srs . wkt . startswith ( sd [ '<STR_LIT>' ] ) ) <EOL> def test_ellipsoid ( self ) : <EOL> """<STR_LIT>""" <EOL> for sd in test_srs : <EOL> ellps1 = sd [ '<STR_LIT>' ] <EOL> prec = sd [ '<STR_LIT>' ] <EOL> srs = SpatialRefSys . objects . get ( srid = sd [ '<STR_LIT>' ] ) <EOL> ellps2 = srs . ellipsoid <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> self . assertAlmostEqual ( ellps1 [ i ] , ellps2 [ i ] , prec [ i ] ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_add_entry ( self ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . gis . utils import add_srs_entry <EOL> add_srs_entry ( <NUM_LIT> ) <EOL> self . assertTrue ( <EOL> SpatialRefSys . objects . filter ( srid = <NUM_LIT> ) . exists ( ) <EOL> ) <EOL> srs = SpatialRefSys . objects . get ( srid = <NUM_LIT> ) <EOL> self . assertTrue ( <EOL> SpatialRefSys . get_spheroid ( srs . wkt ) . startswith ( '<STR_LIT>' ) <EOL> ) </s>
