Skip to content

Commit

Permalink
Merge pull request #5601 from rouault/unblacklist_PyQgsDBManagerGpkg
Browse files Browse the repository at this point in the history
Fix DBManager + PyQgsDBManagerGpkg and unblack list it for Travis-CI
  • Loading branch information
rouault committed Nov 10, 2017
2 parents a65f072 + 95feb87 commit 8c6e029
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion .ci/travis/linux/blacklist.txt
Expand Up @@ -6,7 +6,6 @@ qgis_composermapgridtest
qgis_composerutils
ProcessingGrass7AlgorithmsImageryTest
ProcessingGrass7AlgorithmsRasterTest
PyQgsDBManagerGpkg
PyQgsAppStartup

# temporary during processing refactoring
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/db_manager/db_plugins/gpkg/connector.py
Expand Up @@ -51,6 +51,9 @@ def __init__(self, uri):

def _opendb(self):

# Keep this explicit assignment to None to make sure the file is
# properly closed before being re-opened
self.gdal_ds = None
self.gdal_ds = gdal.OpenEx(self.dbname, gdal.OF_UPDATE)
if self.gdal_ds is None:
self.gdal_ds = gdal.OpenEx(self.dbname)
Expand Down
17 changes: 11 additions & 6 deletions tests/src/python/test_db_manager_gpkg.py
Expand Up @@ -129,10 +129,13 @@ def testListLayer(self):
info = table.info()
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINESTRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div>"""

if int(gdal.VersionInfo('VERSION_NUM')) >= GDAL_COMPUTE_VERSION(2, 2, 0):
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINESTRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testLayer (<a href="action:trigger/trigger_insert_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testLayer" AFTER INSERT ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE table_name = 'testLayer'; END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testLayer (<a href="action:trigger/trigger_delete_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testLayer" AFTER DELETE ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE table_name = 'testLayer'; END&nbsp;</td></tr></table></div></div>"""
# GDAL 2.2.0
expected_html_2 = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINESTRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testLayer (<a href="action:trigger/trigger_insert_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testLayer" AFTER INSERT ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE table_name = 'testLayer'; END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testLayer (<a href="action:trigger/trigger_delete_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testLayer" AFTER DELETE ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE table_name = 'testLayer'; END&nbsp;</td></tr></table></div></div>"""

self.assertEqual(info.toHtml(), expected_html)
# GDAL 2.3.0
expected_html_3 = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINESTRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testLayer (<a href="action:trigger/trigger_insert_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testLayer" AFTER INSERT ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE lower(table_name) = lower('testLayer'); END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testLayer (<a href="action:trigger/trigger_delete_feature_count_testLayer/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testLayer" AFTER DELETE ON "testLayer" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE lower(table_name) = lower('testLayer'); END&nbsp;</td></tr></table></div></div>"""

self.assertIn(info.toHtml(), [expected_html, expected_html_2, expected_html_3])

connection.remove()

Expand Down Expand Up @@ -391,10 +394,12 @@ def testNonSpatial(self):
info = table.info()
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div>"""

if int(gdal.VersionInfo('VERSION_NUM')) >= GDAL_COMPUTE_VERSION(2, 2, 0):
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testNonSpatial (<a href="action:trigger/trigger_insert_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testNonSpatial" AFTER INSERT ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE table_name = 'testNonSpatial'; END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testNonSpatial (<a href="action:trigger/trigger_delete_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testNonSpatial" AFTER DELETE ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE table_name = 'testNonSpatial'; END&nbsp;</td></tr></table></div></div>"""
# GDAL 2.2.0
expected_html_2 = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testNonSpatial (<a href="action:trigger/trigger_insert_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testNonSpatial" AFTER INSERT ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE table_name = 'testNonSpatial'; END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testNonSpatial (<a href="action:trigger/trigger_delete_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testNonSpatial" AFTER DELETE ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE table_name = 'testNonSpatial'; END&nbsp;</td></tr></table></div></div>"""

self.assertEqual(info.toHtml(), expected_html, info.toHtml())
# GDAL 2.3.0
expected_html_3 = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>N&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div><div class="section"><h2>Triggers</h2><div><table class="header"><tr><th>Name&nbsp;</th><th>Function&nbsp;</th></tr><tr><td>trigger_insert_feature_count_testNonSpatial (<a href="action:trigger/trigger_insert_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_insert_feature_count_testNonSpatial" AFTER INSERT ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count + 1 WHERE lower(table_name) = lower('testNonSpatial'); END&nbsp;</td></tr><tr><td>trigger_delete_feature_count_testNonSpatial (<a href="action:trigger/trigger_delete_feature_count_testNonSpatial/delete">delete</a>)&nbsp;</td><td>CREATE TRIGGER "trigger_delete_feature_count_testNonSpatial" AFTER DELETE ON "testNonSpatial" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE lower(table_name) = lower('testNonSpatial'); END&nbsp;</td></tr></table></div></div>"""
self.assertIn(info.toHtml(), [expected_html, expected_html_2, expected_html_3], info.toHtml())

connection.remove()

Expand Down

0 comments on commit 8c6e029

Please sign in to comment.