Fixed #27103 -- Registered vcapi/rcapi GDAL prototypes based on their own drivers.
This commit is contained in:
parent
48c34f3336
commit
fb951fb0c5
|
@ -76,10 +76,11 @@ class Driver(GDALBase):
|
||||||
"""
|
"""
|
||||||
Attempts to register all the data source drivers.
|
Attempts to register all the data source drivers.
|
||||||
"""
|
"""
|
||||||
# Only register all if the driver count is 0 (or else all drivers
|
# Only register all if the driver counts are 0 (or else all drivers
|
||||||
# will be registered over and over again)
|
# will be registered over and over again)
|
||||||
if not cls.driver_count():
|
if not vcapi.get_driver_count():
|
||||||
vcapi.register_all()
|
vcapi.register_all()
|
||||||
|
if not rcapi.get_driver_count():
|
||||||
rcapi.register_all()
|
rcapi.register_all()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.contrib.gis.gdal import HAS_GDAL
|
from django.contrib.gis.gdal import HAS_GDAL
|
||||||
|
from django.test import mock
|
||||||
|
|
||||||
if HAS_GDAL:
|
if HAS_GDAL:
|
||||||
from django.contrib.gis.gdal import Driver, GDALException
|
from django.contrib.gis.gdal import Driver, GDALException
|
||||||
|
@ -48,3 +49,32 @@ class DriverTest(unittest.TestCase):
|
||||||
for alias, full_name in aliases.items():
|
for alias, full_name in aliases.items():
|
||||||
dr = Driver(alias)
|
dr = Driver(alias)
|
||||||
self.assertEqual(full_name, str(dr))
|
self.assertEqual(full_name, str(dr))
|
||||||
|
|
||||||
|
@mock.patch('django.contrib.gis.gdal.driver.vcapi.get_driver_count')
|
||||||
|
@mock.patch('django.contrib.gis.gdal.driver.rcapi.get_driver_count')
|
||||||
|
@mock.patch('django.contrib.gis.gdal.driver.vcapi.register_all')
|
||||||
|
@mock.patch('django.contrib.gis.gdal.driver.rcapi.register_all')
|
||||||
|
def test_registered(self, rreg, vreg, rcount, vcount):
|
||||||
|
"""
|
||||||
|
Prototypes are registered only if their respective driver counts are
|
||||||
|
zero.
|
||||||
|
"""
|
||||||
|
def check(rcount_val, vcount_val):
|
||||||
|
vreg.reset_mock()
|
||||||
|
rreg.reset_mock()
|
||||||
|
rcount.return_value = rcount_val
|
||||||
|
vcount.return_value = vcount_val
|
||||||
|
Driver.ensure_registered()
|
||||||
|
if rcount_val:
|
||||||
|
self.assertFalse(rreg.called)
|
||||||
|
else:
|
||||||
|
rreg.assert_called_once_with()
|
||||||
|
if vcount_val:
|
||||||
|
self.assertFalse(vreg.called)
|
||||||
|
else:
|
||||||
|
vreg.assert_called_once_with()
|
||||||
|
|
||||||
|
check(0, 0)
|
||||||
|
check(120, 0)
|
||||||
|
check(0, 120)
|
||||||
|
check(120, 120)
|
||||||
|
|
Loading…
Reference in New Issue