refined the unit test data source logic

This commit is contained in:
Eric Stadtherr 2016-08-03 09:11:27 -06:00
parent ed39efcfcb
commit 264407b259
3 changed files with 30 additions and 33 deletions

View file

@ -28,46 +28,43 @@ def test_adding_datasource_to_layer():
</Map>
'''
if 'shape' not in mapnik.DatasourceCache.plugin_names():
print "skipping test_adding_datasource_to_layer because \"shape\" plugin is not available"
return
if 'shape' in mapnik.DatasourceCache.plugin_names():
m = mapnik.Map(256, 256)
m = mapnik.Map(256, 256)
mapnik.load_map_from_string(m, map_string)
mapnik.load_map_from_string(m, map_string)
# validate it loaded fine
eq_(m.layers[0].styles[0], 'world_borders_style')
eq_(m.layers[0].styles[1], 'point_style')
eq_(len(m.layers), 1)
# validate it loaded fine
eq_(m.layers[0].styles[0], 'world_borders_style')
eq_(m.layers[0].styles[1], 'point_style')
eq_(len(m.layers), 1)
# also assign a variable reference to that layer
# below we will test that this variable references
# the same object that is attached to the map
lyr = m.layers[0]
# also assign a variable reference to that layer
# below we will test that this variable references
# the same object that is attached to the map
lyr = m.layers[0]
# ensure that there was no datasource for the layer...
eq_(m.layers[0].datasource, None)
eq_(lyr.datasource, None)
# ensure that there was no datasource for the layer...
eq_(m.layers[0].datasource, None)
eq_(lyr.datasource, None)
# also note that since the srs was black it defaulted to wgs84
eq_(m.layers[0].srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
eq_(lyr.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
# also note that since the srs was black it defaulted to wgs84
eq_(m.layers[0].srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
eq_(lyr.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
# now add a datasource one...
ds = mapnik.Shapefile(file='../data/shp/world_merc.shp')
m.layers[0].datasource = ds
# now add a datasource one...
ds = mapnik.Shapefile(file='../data/shp/world_merc.shp')
m.layers[0].datasource = ds
# now ensure it is attached
eq_(m.layers[0].datasource.describe()['name'], "shape")
eq_(lyr.datasource.describe()['name'], "shape")
# now ensure it is attached
eq_(m.layers[0].datasource.describe()['name'], "shape")
eq_(lyr.datasource.describe()['name'], "shape")
# and since we have now added a shapefile in spherical mercator, adjust the projection
lyr.srs = '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
# and since we have now added a shapefile in spherical mercator, adjust the projection
lyr.srs = '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
# test that assignment
eq_(m.layers[0].srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
eq_(lyr.srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
# test that assignment
eq_(m.layers[0].srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
eq_(lyr.srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
if __name__ == "__main__":
setup()

View file

@ -48,7 +48,7 @@ def test_good_files():
if have_inputs:
good_files.append(xmlfile)
else:
print 'Notice: skipping load_map_test for %s due to missing input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
print 'Notice: skipping load_map_test for %s due to unavailable input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
failures = [];
strict = False

View file

@ -23,7 +23,7 @@ def compare_map(xmlfile):
missing_plugins = set()
have_inputs = datasources_available(xmlfile, missing_plugins)
if not have_inputs:
print 'Notice: skipping saved map comparison for %s due to missing input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
print 'Notice: skipping saved map comparison for %s due to unavailable input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
return False
m = mapnik.Map(256, 256)