Fixed #27103 -- Registered vcapi/rcapi GDAL prototypes based on their own drivers.

This commit is contained in:
Matthew Somerville 2016-08-22 12:59:25 +01:00 committed by Tim Graham
parent 48c34f3336
commit fb951fb0c5
2 changed files with 33 additions and 2 deletions

View File

@ -76,10 +76,11 @@ class Driver(GDALBase):
"""
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)
if not cls.driver_count():
if not vcapi.get_driver_count():
vcapi.register_all()
if not rcapi.get_driver_count():
rcapi.register_all()
@classmethod

View File

@ -1,6 +1,7 @@
import unittest
from django.contrib.gis.gdal import HAS_GDAL
from django.test import mock
if HAS_GDAL:
from django.contrib.gis.gdal import Driver, GDALException
@ -48,3 +49,32 @@ class DriverTest(unittest.TestCase):
for alias, full_name in aliases.items():
dr = Driver(alias)
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)