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

View file

@ -48,7 +48,7 @@ def test_good_files():
if have_inputs: if have_inputs:
good_files.append(xmlfile) good_files.append(xmlfile)
else: 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 = []; failures = [];
strict = False strict = False

View file

@ -23,7 +23,7 @@ def compare_map(xmlfile):
missing_plugins = set() missing_plugins = set()
have_inputs = datasources_available(xmlfile, missing_plugins) have_inputs = datasources_available(xmlfile, missing_plugins)
if not have_inputs: 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 return False
m = mapnik.Map(256, 256) m = mapnik.Map(256, 256)