Skip to content

Commit

Permalink
speedup creation of spatialite database in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Aug 25, 2013
1 parent 43fc36a commit bb798b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions tests/src/python/test_qgsissue7244.py
Expand Up @@ -41,8 +41,9 @@ def setUpClass(cls):
# create test db
if os.path.exists("test.sqlite") :
os.remove("test.sqlite")
con = sqlite3.connect("test.sqlite")
con = sqlite3.connect("test.sqlite", isolation_level=None)
cur = con.cursor()
cur.execute("BEGIN")
sql = "SELECT InitSpatialMetadata()"
cur.execute(sql)

Expand Down Expand Up @@ -73,7 +74,7 @@ def setUpClass(cls):
sql = "INSERT INTO test_pg (name, geometry) "
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))"
cur.execute(sql)
con.commit()
cur.execute("COMMIT")
con.close()

@classmethod
Expand Down
11 changes: 6 additions & 5 deletions tests/src/python/test_qgsspatialiteprovider.py
Expand Up @@ -43,11 +43,12 @@ class TestQgsSpatialiteProvider(TestCase):
def setUpClass(cls):
"""Run before all tests"""
# create test db
cls.dbname = os.path.join( tempfile.gettempdir(), "test.sqlite" )
cls.dbname = os.path.join( tempfile.gettempdir(), "test.sqlite" )
if os.path.exists( cls.dbname ):
os.remove( cls.dbname )
con = sqlite3.connect(cls.dbname)
con = sqlite3.connect(cls.dbname, isolation_level=None)
cur = con.cursor()
cur.execute( "BEGIN" )
sql = "SELECT InitSpatialMetadata()"
cur.execute(sql)

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

con.commit()
cur.execute( "COMMIT" )
con.close()

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

def xtest_SplitFeatureWithFailedCommit(self):
Expand All @@ -109,7 +110,7 @@ def xtest_SplitFeatureWithFailedCommit(self):
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
if layer.commitChanges():
die("this commit should fail")
die("this commit should fail")
layer.rollBack()
feat = QgsFeature()
it=layer.getFeatures()
Expand Down

0 comments on commit bb798b4

Please sign in to comment.