Skip to content
Permalink
Browse files

test_provider_ogr_gpkg.py: Test disabling walForSqlite3 setting

  • Loading branch information
rouault committed Nov 2, 2016
1 parent 053c531 commit 189d8f565b6f6a6c0bd0b8738053d7087f390e91
Showing with 49 additions and 4 deletions.
  1. +49 −4 tests/src/python/test_provider_ogr_gpkg.py
@@ -20,12 +20,11 @@
import glob
from osgeo import gdal, ogr

from qgis.PyQt.QtCore import QCoreApplication, QSettings
from qgis.core import QgsVectorLayer, QgsFeature, QgsGeometry, QgsFeatureRequest, QgsRectangle
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

start_app()


def GDAL_COMPUTE_VERSION(maj, min, rev):
return ((maj) * 1000000 + (min) * 10000 + (rev) * 100)
@@ -48,10 +47,17 @@ def setUpClass(cls):
# Create test layer
cls.basetestpath = tempfile.mkdtemp()

QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsOGRProviderGpkg.com")
QCoreApplication.setApplicationName("TestPyQgsOGRProviderGpkg")
QSettings().clear()
start_app()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
shutil.rmtree(cls.basetestpath, True)
QSettings().clear()

def XXXXtestSingleToMultiPolygonPromotion(self):

@@ -149,10 +155,10 @@ def testBug15351_closeIter_commit_closeProvider(self):
self.internalTestBug15351('closeIter_commit_closeProvider')

# We need GDAL 2.0 to issue PRAGMA journal_mode
def testBug15351_closeIter_commit_closeProvider(self):
def testBug15351_commit_closeProvider_closeIter(self):
if int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 0, 0):
return
self.internalTestBug15351('closeIter_commit_closeProvider')
self.internalTestBug15351('commit_closeProvider_closeIter')

# We need GDAL 2.0 to issue PRAGMA journal_mode
def testBug15351_commit_closeIter_closeProvider(self):
@@ -206,5 +212,44 @@ def testGeopackageExtentUpdate(self):
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001),
provider_extent.asPolygon()[0])

def testDisablewalForSqlite3(self):
''' Test disabling walForSqlite3 setting '''
QSettings().setValue("/qgis/walForSqlite3", False)

tmpfile = os.path.join(self.basetestpath, 'testDisablewalForSqlite3.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint)
lyr.CreateField(ogr.FieldDefn('attr0', ogr.OFTInteger))
lyr.CreateField(ogr.FieldDefn('attr1', ogr.OFTInteger))
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('POINT(0 0)'))
lyr.CreateFeature(f)
f = None
ds = None

vl = QgsVectorLayer(u'{}'.format(tmpfile), u'test', u'ogr')

# Test that we are using default delete mode and not WAL
ds = ogr.Open(tmpfile)
lyr = ds.ExecuteSQL('PRAGMA journal_mode')
f = lyr.GetNextFeature()
res = f.GetField(0)
ds.ReleaseResultSet(lyr)
ds = None
self.assertEqual(res, 'delete')

self.assertTrue(vl.startEditing())
feature = vl.getFeatures().next()
self.assertTrue(vl.changeAttributeValue(feature.id(), 1, 1001))

# Commit changes
cbk = ErrorReceiver()
vl.dataProvider().raiseError.connect(cbk.receiveError)
self.assertTrue(vl.commitChanges())
self.assertIsNone(cbk.msg)
vl = None

QSettings().setValue("/qgis/walForSqlite3", None)

if __name__ == '__main__':
unittest.main()

0 comments on commit 189d8f5

Please sign in to comment.
You can’t perform that action at this time.