Skip to content

Commit bb798b4

Browse files
committedAug 25, 2013
speedup creation of spatialite database in tests
1 parent 43fc36a commit bb798b4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed
 

‎tests/src/python/test_qgsissue7244.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def setUpClass(cls):
4141
# create test db
4242
if os.path.exists("test.sqlite") :
4343
os.remove("test.sqlite")
44-
con = sqlite3.connect("test.sqlite")
44+
con = sqlite3.connect("test.sqlite", isolation_level=None)
4545
cur = con.cursor()
46+
cur.execute("BEGIN")
4647
sql = "SELECT InitSpatialMetadata()"
4748
cur.execute(sql)
4849

@@ -73,7 +74,7 @@ def setUpClass(cls):
7374
sql = "INSERT INTO test_pg (name, geometry) "
7475
sql += "VALUES ('polygon with interior ring', GeomFromText('POLYGON((0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1))', 4326))"
7576
cur.execute(sql)
76-
con.commit()
77+
cur.execute("COMMIT")
7778
con.close()
7879

7980
@classmethod

‎tests/src/python/test_qgsspatialiteprovider.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ class TestQgsSpatialiteProvider(TestCase):
4343
def setUpClass(cls):
4444
"""Run before all tests"""
4545
# create test db
46-
cls.dbname = os.path.join( tempfile.gettempdir(), "test.sqlite" )
46+
cls.dbname = os.path.join( tempfile.gettempdir(), "test.sqlite" )
4747
if os.path.exists( cls.dbname ):
4848
os.remove( cls.dbname )
49-
con = sqlite3.connect(cls.dbname)
49+
con = sqlite3.connect(cls.dbname, isolation_level=None)
5050
cur = con.cursor()
51+
cur.execute( "BEGIN" )
5152
sql = "SELECT InitSpatialMetadata()"
5253
cur.execute(sql)
5354

@@ -69,7 +70,7 @@ def setUpClass(cls):
6970
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
7071
cur.execute(sql)
7172

72-
con.commit()
73+
cur.execute( "COMMIT" )
7374
con.close()
7475

7576
@classmethod
@@ -97,7 +98,7 @@ def test_SplitFeature(self):
9798
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
9899
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
99100
if not layer.commitChanges():
100-
die("this commit should work")
101+
die("this commit should work")
101102
layer.featureCount() == 4 or die("we should have 4 features after 2 split")
102103

103104
def xtest_SplitFeatureWithFailedCommit(self):
@@ -109,7 +110,7 @@ def xtest_SplitFeatureWithFailedCommit(self):
109110
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
110111
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
111112
if layer.commitChanges():
112-
die("this commit should fail")
113+
die("this commit should fail")
113114
layer.rollBack()
114115
feat = QgsFeature()
115116
it=layer.getFeatures()

0 commit comments

Comments
 (0)
Please sign in to comment.