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 38a7711 commit eb91915bb4e773618fd40402f708b14ff12250d9
Showing with 47 additions and 0 deletions.
  1. +47 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -20,6 +20,7 @@
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
@@ -48,10 +49,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 testSingleToMultiPolygonPromotion(self):

@@ -200,5 +208,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 eb91915

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