2013-07-01 12:22:27 +00:00
|
|
|
import unittest
|
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
from django.contrib.gis.gdal import HAS_GDAL
|
|
|
|
|
|
|
|
if HAS_GDAL:
|
2014-12-17 21:00:05 +00:00
|
|
|
from django.contrib.gis.gdal import Driver, GDALException
|
2013-05-11 03:08:45 +00:00
|
|
|
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2014-12-02 16:53:04 +00:00
|
|
|
valid_drivers = (
|
|
|
|
# vector
|
|
|
|
'ESRI Shapefile', 'MapInfo File', 'TIGER', 'S57', 'DGN', 'Memory', 'CSV',
|
|
|
|
'GML', 'KML',
|
|
|
|
# raster
|
2014-12-17 14:30:12 +00:00
|
|
|
'GTiff', 'JPEG', 'MEM', 'PNG',
|
2014-12-02 16:53:04 +00:00
|
|
|
)
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2014-12-02 16:53:04 +00:00
|
|
|
invalid_drivers = ('Foo baz', 'clucka', 'ESRI Shp', 'ESRI rast')
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2014-12-02 16:53:04 +00:00
|
|
|
aliases = {
|
|
|
|
'eSrI': 'ESRI Shapefile',
|
|
|
|
'TigER/linE': 'TIGER',
|
|
|
|
'SHAPE': 'ESRI Shapefile',
|
|
|
|
'sHp': 'ESRI Shapefile',
|
|
|
|
'tiFf': 'GTiff',
|
|
|
|
'tIf': 'GTiff',
|
|
|
|
'jPEg': 'JPEG',
|
|
|
|
'jpG': 'JPEG',
|
|
|
|
}
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
|
2014-12-02 16:53:04 +00:00
|
|
|
@unittest.skipUnless(HAS_GDAL, "GDAL is required")
|
2008-08-05 18:13:06 +00:00
|
|
|
class DriverTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def test01_valid_driver(self):
|
2014-12-02 16:53:04 +00:00
|
|
|
"Testing valid GDAL/OGR Data Source Drivers."
|
2008-08-05 18:13:06 +00:00
|
|
|
for d in valid_drivers:
|
|
|
|
dr = Driver(d)
|
|
|
|
self.assertEqual(d, str(dr))
|
|
|
|
|
|
|
|
def test02_invalid_driver(self):
|
2014-12-02 16:53:04 +00:00
|
|
|
"Testing invalid GDAL/OGR Data Source Drivers."
|
2008-08-05 18:13:06 +00:00
|
|
|
for i in invalid_drivers:
|
2016-01-17 11:26:39 +00:00
|
|
|
with self.assertRaises(GDALException):
|
|
|
|
Driver(i)
|
2008-08-05 18:13:06 +00:00
|
|
|
|
|
|
|
def test03_aliases(self):
|
|
|
|
"Testing driver aliases."
|
|
|
|
for alias, full_name in aliases.items():
|
|
|
|
dr = Driver(alias)
|
|
|
|
self.assertEqual(full_name, str(dr))
|