2013-07-01 20:22:27 +08:00
|
|
|
import unittest
|
|
|
|
from unittest import skipUnless
|
|
|
|
|
2013-05-11 11:08:45 +08:00
|
|
|
from django.contrib.gis.gdal import HAS_GDAL
|
|
|
|
|
|
|
|
if HAS_GDAL:
|
|
|
|
from django.contrib.gis.gdal import Driver, OGRException
|
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
|
|
|
|
valid_drivers = ('ESRI Shapefile', 'MapInfo File', 'TIGER', 'S57', 'DGN',
|
|
|
|
'Memory', 'CSV', 'GML', 'KML')
|
|
|
|
|
|
|
|
invalid_drivers = ('Foo baz', 'clucka', 'ESRI Shp')
|
|
|
|
|
|
|
|
aliases = {'eSrI' : 'ESRI Shapefile',
|
|
|
|
'TigER/linE' : 'TIGER',
|
|
|
|
'SHAPE' : 'ESRI Shapefile',
|
|
|
|
'sHp' : 'ESRI Shapefile',
|
|
|
|
}
|
|
|
|
|
2013-05-11 11:08:45 +08:00
|
|
|
|
|
|
|
@skipUnless(HAS_GDAL, "GDAL is required")
|
2008-08-06 02:13:06 +08:00
|
|
|
class DriverTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def test01_valid_driver(self):
|
|
|
|
"Testing valid OGR Data Source Drivers."
|
|
|
|
for d in valid_drivers:
|
|
|
|
dr = Driver(d)
|
|
|
|
self.assertEqual(d, str(dr))
|
|
|
|
|
|
|
|
def test02_invalid_driver(self):
|
|
|
|
"Testing invalid OGR Data Source Drivers."
|
|
|
|
for i in invalid_drivers:
|
|
|
|
self.assertRaises(OGRException, Driver, i)
|
|
|
|
|
|
|
|
def test03_aliases(self):
|
|
|
|
"Testing driver aliases."
|
|
|
|
for alias, full_name in aliases.items():
|
|
|
|
dr = Driver(alias)
|
|
|
|
self.assertEqual(full_name, str(dr))
|