Skip to content

Commit

Permalink
test_provider_ogr_gpkg.py: Test disabling walForSqlite3 setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 2, 2016
1 parent 38a7711 commit eb91915
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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.