Skip to content

Commit

Permalink
Try to make PG raster test more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Mar 6, 2020
1 parent 9bbfe81 commit 3b6bc30
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/src/python/test_provider_postgresraster.py
Expand Up @@ -66,8 +66,19 @@ def setUpClass(cls):
cls.dbconn = 'service=qgis_test'
if 'QGIS_PGTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_PGTEST_DB']
# Create test layers

cls._load_test_table('public', 'raster_tiled_3035')
cls._load_test_table('public', 'raster_3035_no_constraints')
cls._load_test_table('public', 'raster_3035_tiled_no_overviews')
cls._load_test_table('public', 'raster_3035_tiled_no_pk')
cls._load_test_table('public', 'raster_3035_tiled_composite_pk')
cls._load_test_table('public', 'raster_3035_untiled_multiple_rows')
cls._load_test_table('idro', 'cosmo_i5_snow', 'bug_34823_pg_raster')

# Fix timing issues in backend
#time.sleep(1)

# Create test layer
cls.rl = QgsRasterLayer(cls.dbconn + ' sslmode=disable key=\'rid\' srid=3035 table="public"."raster_tiled_3035" sql=', 'test', 'postgresraster')
assert cls.rl.isValid()
cls.source = cls.rl.dataProvider()
Expand Down Expand Up @@ -118,21 +129,18 @@ def testBlockTiled(self):
def testNoConstraintRaster(self):
"""Read unconstrained raster layer"""

self._load_test_table('public', 'raster_3035_no_constraints')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable key=\'pk\' srid=3035 table="public"."raster_3035_no_constraints" sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testPkGuessing(self):
"""Read raster layer with no pkey in uri"""

self._load_test_table('public', 'raster_tiled_3035')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_tiled_3035" sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testWhereCondition(self):
"""Read raster layer with where condition"""

self._load_test_table('public', 'raster_3035_tiled_no_overviews')
rl_nowhere = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_no_overviews"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl_nowhere.isValid())
Expand Down Expand Up @@ -162,15 +170,13 @@ def testWhereCondition(self):
def testNoPk(self):
"""Read raster with no PK"""

self._load_test_table('public', 'raster_3035_tiled_no_pk')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_no_pk"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testCompositeKey(self):
"""Read raster with composite pks"""

self._load_test_table('public', 'raster_3035_tiled_composite_pk')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_composite_pk"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())
Expand Down Expand Up @@ -235,17 +241,13 @@ def testOtherSchema(self):
"""Test that a layer in a different schema than public can be loaded
See: GH #34823"""

self._load_test_table('idro', 'cosmo_i5_snow', 'bug_34823_pg_raster')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema}".format(table='cosmo_i5_snow', schema='idro'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())
self.assertTrue(compareWkt(rl.extent().asWktPolygon(), 'POLYGON((-64.79286766849691048 -77.26689086732433509, -62.18292922825105506 -77.26689086732433509, -62.18292922825105506 -74.83694818157819384, -64.79286766849691048 -74.83694818157819384, -64.79286766849691048 -77.26689086732433509))'))

def testUntiledMultipleRows(self):
"""Test multiple rasters (one per row)"""

self._load_test_table('public', 'raster_3035_untiled_multiple_rows')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema} sql=\"pk\" = 1".format(table='raster_3035_untiled_multiple_rows', schema='public'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())
block = rl.dataProvider().block(1, rl.extent(), 2, 2)
Expand All @@ -267,8 +269,6 @@ def testUntiledMultipleRows(self):
def testSetSubsetString(self):
"""Test setSubsetString"""

self._load_test_table('public', 'raster_3035_untiled_multiple_rows')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema} sql=\"pk\" = 2".format(table='raster_3035_untiled_multiple_rows', schema='public'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())

Expand Down

0 comments on commit 3b6bc30

Please sign in to comment.