renamed mapnik to mapnik2 in python tests

This commit is contained in:
Alberto Valverde 2010-03-11 18:12:22 +00:00
parent 8661d60f43
commit c47cd93f93
11 changed files with 173 additions and 173 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
import os
import mapnik
import mapnik2
from nose.tools import *
from utilities import execution_path,Todo
@ -11,13 +11,13 @@ def setup():
os.chdir(execution_path('.'))
def _pycairo_surface(type,sym):
if mapnik.has_pycairo():
if mapnik2.has_pycairo():
import cairo
test_cairo_file = 'test.%s' % type
m = mapnik.Map(256,256)
mapnik.load_map(m,'../data/good_maps/%s_symbolizer.xml' % sym)
m = mapnik2.Map(256,256)
mapnik2.load_map(m,'../data/good_maps/%s_symbolizer.xml' % sym)
surface = getattr(cairo,'%sSurface' % type.upper())(test_cairo_file, m.width,m.height)
mapnik.render(m, surface)
mapnik2.render(m, surface)
surface.finish()
if os.path.exists(test_cairo_file):

View file

@ -3,7 +3,7 @@
from nose.tools import *
from utilities import execution_path
import os, mapnik
import os, mapnik2
def setup():
# All of the paths used are relative, if we run the tests
@ -11,21 +11,21 @@ def setup():
os.chdir(execution_path('.'))
def test_field_listing():
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
lyr = mapnik2.Layer('test')
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
fields = lyr.datasource.fields()
eq_(fields, ['AREA', 'EAS_ID', 'PRFEDEA'])
def test_total_feature_count():
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
lyr = mapnik2.Layer('test')
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
features = lyr.datasource.all_features()
num_feats = len(features)
eq_(num_feats, 10)
def test_feature_envelope():
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
lyr = mapnik2.Layer('test')
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
features = lyr.datasource.all_features()
for feat in features:
env = feat.envelope()
@ -35,8 +35,8 @@ def test_feature_envelope():
eq_(intersects, True)
def test_feature_attributes():
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
lyr = mapnik2.Layer('test')
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
features = lyr.datasource.all_features()
feat = features[0]
attrs = {'PRFEDEA': u'35043411', 'EAS_ID': 168, 'AREA': 215229.266}

View file

@ -3,10 +3,10 @@
from nose.tools import *
from utilities import Todo
import mapnik
import mapnik2
if hasattr(mapnik,'Expression'):
mapnik.Filter = mapnik.Expression
if hasattr(mapnik2,'Expression'):
mapnik2.Filter = mapnik2.Expression
map_ = '''<Map>
<Style name="s">
@ -45,25 +45,25 @@ map_ = '''<Map>
</Map>'''
def test_filter_init():
m = mapnik.Map(1,1)
mapnik.load_map_from_string(m,map_)
m = mapnik2.Map(1,1)
mapnik2.load_map_from_string(m,map_)
filters = []
filters.append(mapnik.Filter("([region]>=0) and ([region]<=50)"))
filters.append(mapnik.Filter("(([region]>=0) and ([region]<=50))"))
filters.append(mapnik.Filter("((([region]>=0) and ([region]<=50)))"))
filters.append(mapnik.Filter('((([region]>=0) and ([region]<=50)))'))
filters.append(mapnik.Filter('''((([region]>=0) and ([region]<=50)))'''))
filters.append(mapnik.Filter('''
filters.append(mapnik2.Filter("([region]>=0) and ([region]<=50)"))
filters.append(mapnik2.Filter("(([region]>=0) and ([region]<=50))"))
filters.append(mapnik2.Filter("((([region]>=0) and ([region]<=50)))"))
filters.append(mapnik2.Filter('((([region]>=0) and ([region]<=50)))'))
filters.append(mapnik2.Filter('''((([region]>=0) and ([region]<=50)))'''))
filters.append(mapnik2.Filter('''
((([region]>=0)
and
([region]<=50)))
'''))
filters.append(mapnik.Filter('''
filters.append(mapnik2.Filter('''
([region]>=0)
and
([region]<=50)
'''))
filters.append(mapnik.Filter('''
filters.append(mapnik2.Filter('''
([region]
>=
0)

View file

@ -2,7 +2,7 @@
from nose.tools import *
import mapnik, pickle
import mapnik2, pickle
# Tests that exercise fonts.
@ -10,4 +10,4 @@ import mapnik, pickle
# Todo: Add logic to use this TextSymbolizer in a rendering
#@raises(UserWarning)
#def test_invalid_font():
# ts = mapnik.TextSymbolizer('Name', 'Invalid Font Name', int(8), mapnik.Color('black'))
# ts = mapnik2.TextSymbolizer('Name', 'Invalid Font Name', int(8), mapnik2.Color('black'))

View file

@ -3,11 +3,11 @@
from nose.tools import *
from utilities import Todo
import mapnik
import mapnik2
def test_introspect_symbolizers():
# create a symbolizer
p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/dummy.png"))
p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/dummy.png"))
p.allow_overlap = True
p.opacity = 0.5
@ -22,11 +22,11 @@ def test_introspect_symbolizers():
eq_(p.filename,'../data/images/dummy.png')
# contruct objects to hold it
r = mapnik.Rule()
r = mapnik2.Rule()
r.symbols.append(p)
s = mapnik.Style()
s = mapnik2.Style()
s.rules.append(r)
m = mapnik.Map(0,0)
m = mapnik2.Map(0,0)
m.append_style('s',s)
# try to figure out what is
@ -44,7 +44,7 @@ def test_introspect_symbolizers():
sym = syms[0]
# this is hackish at best
p2 = sym.symbol()
assert isinstance(p2,mapnik.PointSymbolizer)
assert isinstance(p2,mapnik2.PointSymbolizer)
eq_(p2.allow_overlap, True)
eq_(p2.opacity, 0.5)
@ -53,7 +53,7 @@ def test_introspect_symbolizers():
## but we need to be able to do:
p2 = syms[0] # get the actual symbolizer, not the variant object
# this will throw for now...
assert isinstance(p2,mapnik.PointSymbolizer)
assert isinstance(p2,mapnik2.PointSymbolizer)
eq_(p2.allow_overlap, True)
eq_(p2.opacity, 0.5)

View file

@ -3,7 +3,7 @@
from nose.tools import *
from utilities import execution_path
import os, sys, glob, mapnik
import os, sys, glob, mapnik2
def setup():
# All of the paths used are relative, if we run the tests
@ -13,15 +13,15 @@ def setup():
# We expect these files to not raise any
# exceptions at all
def assert_loads_successfully(file):
m = mapnik.Map(512, 512)
m = mapnik2.Map(512, 512)
strict = True
mapnik.load_map(m, file, strict)
mapnik2.load_map(m, file, strict)
# libxml2 is not smart about paths, and clips the last directory off
# of a path if it does not end in a trailing slash
base_path = os.path.dirname(file) + '/'
mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
mapnik2.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
# We expect these files to raise a RuntimeError
@ -29,10 +29,10 @@ def assert_loads_successfully(file):
# of exception)
@raises(RuntimeError)
def assert_raises_runtime_error(file):
m = mapnik.Map(512, 512)
m = mapnik2.Map(512, 512)
strict = True
mapnik.load_map(m, file, strict)
mapnik2.load_map(m, file, strict)
def test_broken_files():
broken_files = glob.glob("../data/broken_maps/*.xml")

View file

@ -3,29 +3,29 @@
from nose.tools import *
from utilities import Todo
import mapnik, pickle
import mapnik2, pickle
# Tests that exercise the functionality of Mapnik classes.
# ShieldSymbolizer initialization
def test_shieldsymbolizer_init():
s = mapnik.ShieldSymbolizer(mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../data/images/dummy.png'))
s = mapnik2.ShieldSymbolizer(mapnik2.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik2.Color('#000000'), mapnik2.PathExpression('../data/images/dummy.png'))
# ShieldSymbolizer missing image file
# images paths are now PathExpressions are evaluated at runtime
# so it does not make sense to throw...
#@raises(RuntimeError)
#def test_shieldsymbolizer_missing_image():
# s = mapnik.ShieldSymbolizer(mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../#data/images/broken.png'))
# s = mapnik2.ShieldSymbolizer(mapnik2.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik2.Color('#000000'), mapnik2.PathExpression('../#data/images/broken.png'))
# PointSymbolizer initialization
def test_pointsymbolizer_init():
p = mapnik.PointSymbolizer()
p = mapnik2.PointSymbolizer()
eq_(p.allow_overlap, False)
eq_(p.opacity,1)
eq_(p.filename,'')
p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/dummy.png"))
p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/dummy.png"))
eq_(p.allow_overlap, False)
eq_(p.opacity, 1)
eq_(p.filename,'../data/images/dummy.png')
@ -35,11 +35,11 @@ def test_pointsymbolizer_init():
# so it does not make sense to throw...
#@raises(RuntimeError)
#def test_pointsymbolizer_missing_image():
# p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/broken.png"))
# p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/broken.png"))
# PointSymbolizer pickling
def test_pointsymbolizer_pickle():
p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/dummy.png"))
p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/dummy.png"))
p2 = pickle.loads(pickle.dumps(p,pickle.HIGHEST_PROTOCOL))
# image type, width, and height only used in contructor...
eq_(p.filename, p2.filename)
@ -48,19 +48,19 @@ def test_pointsymbolizer_pickle():
# PolygonSymbolizer initialization
def test_polygonsymbolizer_init():
p = mapnik.PolygonSymbolizer()
p = mapnik2.PolygonSymbolizer()
eq_(p.fill, mapnik.Color('gray'))
eq_(p.fill, mapnik2.Color('gray'))
eq_(p.fill_opacity, 1)
p = mapnik.PolygonSymbolizer(mapnik.Color('blue'))
p = mapnik2.PolygonSymbolizer(mapnik2.Color('blue'))
eq_(p.fill, mapnik.Color('blue'))
eq_(p.fill, mapnik2.Color('blue'))
eq_(p.fill_opacity, 1)
# PolygonSymbolizer pickling
def test_polygonsymbolizer_pickle():
p = mapnik.PolygonSymbolizer(mapnik.Color('black'))
p = mapnik2.PolygonSymbolizer(mapnik2.Color('black'))
p.fill_opacity = .5
# does not work for some reason...
#eq_(pickle.loads(pickle.dumps(p)), p)
@ -71,25 +71,25 @@ def test_polygonsymbolizer_pickle():
# Stroke initialization
def test_stroke_init():
s = mapnik.Stroke()
s = mapnik2.Stroke()
eq_(s.width, 1)
eq_(s.opacity, 1)
eq_(s.color, mapnik.Color('black'))
eq_(s.line_cap, mapnik.line_cap.BUTT_CAP)
eq_(s.line_join, mapnik.line_join.MITER_JOIN)
eq_(s.color, mapnik2.Color('black'))
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
s = mapnik.Stroke(mapnik.Color('blue'), 5.0)
s = mapnik2.Stroke(mapnik2.Color('blue'), 5.0)
eq_(s.width, 5)
eq_(s.opacity, 1)
eq_(s.color, mapnik.Color('blue'))
eq_(s.line_cap, mapnik.line_cap.BUTT_CAP)
eq_(s.line_join, mapnik.line_join.MITER_JOIN)
eq_(s.color, mapnik2.Color('blue'))
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
# Stroke dashes
def test_stroke_dash_arrays():
s = mapnik.Stroke()
s = mapnik2.Stroke()
s.add_dash(1,2)
s.add_dash(3,4)
s.add_dash(5,6)
@ -98,10 +98,10 @@ def test_stroke_dash_arrays():
# Stroke pickling
def test_stroke_pickle():
s = mapnik.Stroke(mapnik.Color('black'),4.5)
s = mapnik2.Stroke(mapnik2.Color('black'),4.5)
eq_(s.width, 4.5)
eq_(s.color, mapnik.Color('black'))
eq_(s.color, mapnik2.Color('black'))
s.add_dash(1,2)
s.add_dash(3,4)
@ -118,34 +118,34 @@ def test_stroke_pickle():
# LineSymbolizer initialization
def test_linesymbolizer_init():
l = mapnik.LineSymbolizer()
l = mapnik2.LineSymbolizer()
eq_(l.stroke.width, 1)
eq_(l.stroke.opacity, 1)
eq_(l.stroke.color, mapnik.Color('black'))
eq_(l.stroke.line_cap, mapnik.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik.line_join.MITER_JOIN)
eq_(l.stroke.color, mapnik2.Color('black'))
eq_(l.stroke.line_cap, mapnik2.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik2.line_join.MITER_JOIN)
l = mapnik.LineSymbolizer(mapnik.Color('blue'), 5.0)
l = mapnik2.LineSymbolizer(mapnik2.Color('blue'), 5.0)
eq_(l.stroke.width, 5)
eq_(l.stroke.opacity, 1)
eq_(l.stroke.color, mapnik.Color('blue'))
eq_(l.stroke.line_cap, mapnik.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik.line_join.MITER_JOIN)
eq_(l.stroke.color, mapnik2.Color('blue'))
eq_(l.stroke.line_cap, mapnik2.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik2.line_join.MITER_JOIN)
s = mapnik.Stroke(mapnik.Color('blue'), 5.0)
l = mapnik.LineSymbolizer(s)
s = mapnik2.Stroke(mapnik2.Color('blue'), 5.0)
l = mapnik2.LineSymbolizer(s)
eq_(l.stroke.width, 5)
eq_(l.stroke.opacity, 1)
eq_(l.stroke.color, mapnik.Color('blue'))
eq_(l.stroke.line_cap, mapnik.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik.line_join.MITER_JOIN)
eq_(l.stroke.color, mapnik2.Color('blue'))
eq_(l.stroke.line_cap, mapnik2.line_cap.BUTT_CAP)
eq_(l.stroke.line_join, mapnik2.line_join.MITER_JOIN)
# LineSymbolizer pickling
def test_linesymbolizer_pickle():
p = mapnik.LineSymbolizer()
p = mapnik2.LineSymbolizer()
p2 = pickle.loads(pickle.dumps(p,pickle.HIGHEST_PROTOCOL))
# line and stroke eq fails, so we compare attributes for now..
s,s2 = p.stroke, p2.stroke
@ -158,7 +158,7 @@ def test_linesymbolizer_pickle():
# Shapefile initialization
def test_shapefile_init():
s = mapnik.Shapefile(file='../../demo/data/boundaries')
s = mapnik2.Shapefile(file='../../demo/data/boundaries')
e = s.envelope()
@ -169,7 +169,7 @@ def test_shapefile_init():
# Shapefile properties
def test_shapefile_properties():
s = mapnik.Shapefile(file='../../demo/data/boundaries', encoding='latin1')
s = mapnik2.Shapefile(file='../../demo/data/boundaries', encoding='latin1')
f = s.features_at_point(s.envelope().center()).features[0]
eq_(f.properties['CGNS_FID'], u'6f733341ba2011d892e2080020a0f4c9')
@ -182,21 +182,21 @@ def test_shapefile_properties():
# TextSymbolizer initialization
def test_textsymbolizer_init():
ts = mapnik.TextSymbolizer(mapnik.Expression('[Field_Name]'), 'Font Name', 8, mapnik.Color('black'))
ts = mapnik2.TextSymbolizer(mapnik2.Expression('[Field_Name]'), 'Font Name', 8, mapnik2.Color('black'))
eq_(str(ts.name), str(mapnik.Expression('Field_Name')))
eq_(str(ts.name), str(mapnik2.Expression('Field_Name')))
eq_(ts.face_name, 'Font Name')
eq_(ts.text_size, 8)
eq_(ts.fill, mapnik.Color('black'))
eq_(ts.fill, mapnik2.Color('black'))
# TextSymbolizer pickling
def test_textsymbolizer_pickle():
ts = mapnik.TextSymbolizer(mapnik.Expression('[Field_Name]'), 'Font Name', 8, mapnik.Color('black'))
ts = mapnik2.TextSymbolizer(mapnik2.Expression('[Field_Name]'), 'Font Name', 8, mapnik2.Color('black'))
eq_(str(ts.name), str(mapnik.Expression('Field_Name')))
eq_(str(ts.name), str(mapnik2.Expression('Field_Name')))
eq_(ts.face_name, 'Font Name')
eq_(ts.text_size, 8)
eq_(ts.fill, mapnik.Color('black'))
eq_(ts.fill, mapnik2.Color('black'))
ts2 = pickle.loads(pickle.dumps(ts,pickle.HIGHEST_PROTOCOL))
eq_(ts.name, ts2.name)
@ -228,19 +228,19 @@ def test_textsymbolizer_pickle():
eq_(ts.justify_alignment, ts2.justify_alignment)
eq_(ts.opacity, ts2.opacity)
raise Todo("FontSet pickling support needed: http://trac.mapnik.org/ticket/348")
raise Todo("FontSet pickling support needed: http://trac.mapnik2.org/ticket/348")
eq_(ts.fontset, ts2.fontset)
# Map initialization
def test_map_init():
m = mapnik.Map(256, 256)
m = mapnik2.Map(256, 256)
eq_(m.width, 256)
eq_(m.height, 256)
eq_(m.srs, '+proj=latlong +datum=WGS84')
m = mapnik.Map(256, 256, '+proj=latlong')
m = mapnik2.Map(256, 256, '+proj=latlong')
eq_(m.width, 256)
eq_(m.height, 256)
@ -269,11 +269,11 @@ def test_map_init_from_string():
</Layer>
</Map>'''
m = mapnik.Map(600, 300)
m = mapnik2.Map(600, 300)
mapnik.load_map_from_string(m, map_string)
mapnik.load_map_from_string(m, map_string, False, "")
mapnik.load_map_from_string(m, map_string, True, "")
mapnik2.load_map_from_string(m, map_string)
mapnik2.load_map_from_string(m, map_string, False, "")
mapnik2.load_map_from_string(m, map_string, True, "")
raise(Todo("Need to write more map property tests in 'object_test.py'..."))
# Map pickling
@ -281,17 +281,17 @@ def test_map_pickle():
# Fails due to scale() not matching, possibly other things
raise(Todo("Map does not support pickling yet (Tickets #345)."))
m = mapnik.Map(256, 256)
m = mapnik2.Map(256, 256)
eq_(pickle.loads(pickle.dumps(m)), m)
m = mapnik.Map(256, 256, '+proj=latlong')
m = mapnik2.Map(256, 256, '+proj=latlong')
eq_(pickle.loads(pickle.dumps(m)), m)
# Color initialization
def test_color_init():
c = mapnik.Color('blue')
c = mapnik2.Color('blue')
eq_(c.a, 255)
eq_(c.r, 0)
@ -300,7 +300,7 @@ def test_color_init():
eq_(c.to_hex_string(), '#0000ff')
c = mapnik.Color('#f2eff9')
c = mapnik2.Color('#f2eff9')
eq_(c.a, 255)
eq_(c.r, 242)
@ -309,7 +309,7 @@ def test_color_init():
eq_(c.to_hex_string(), '#f2eff9')
c = mapnik.Color('rgb(50%,50%,50%)')
c = mapnik2.Color('rgb(50%,50%,50%)')
eq_(c.a, 255)
eq_(c.r, 128)
@ -318,7 +318,7 @@ def test_color_init():
eq_(c.to_hex_string(), '#808080')
c = mapnik.Color(0, 64, 128)
c = mapnik2.Color(0, 64, 128)
eq_(c.a, 255)
eq_(c.r, 0)
@ -327,7 +327,7 @@ def test_color_init():
eq_(c.to_hex_string(), '#004080')
c = mapnik.Color(0, 64, 128, 192)
c = mapnik2.Color(0, 64, 128, 192)
eq_(c.a, 192)
eq_(c.r, 0)
@ -338,9 +338,9 @@ def test_color_init():
# Color equality
def test_color_equality():
c1 = mapnik.Color('blue')
c2 = mapnik.Color('blue')
c3 = mapnik.Color('black')
c1 = mapnik2.Color('blue')
c2 = mapnik2.Color('blue')
c3 = mapnik2.Color('black')
c3.r = 0
c3.g = 0
@ -350,9 +350,9 @@ def test_color_equality():
eq_(c1, c2)
eq_(c1, c3)
c1 = mapnik.Color(0, 64, 128)
c2 = mapnik.Color(0, 64, 128)
c3 = mapnik.Color(0, 0, 0)
c1 = mapnik2.Color(0, 64, 128)
c2 = mapnik2.Color(0, 64, 128)
c3 = mapnik2.Color(0, 0, 0)
c3.r = 0
c3.g = 64
@ -361,9 +361,9 @@ def test_color_equality():
eq_(c1, c2)
eq_(c1, c3)
c1 = mapnik.Color(0, 64, 128, 192)
c2 = mapnik.Color(0, 64, 128, 192)
c3 = mapnik.Color(0, 0, 0, 255)
c1 = mapnik2.Color(0, 64, 128, 192)
c2 = mapnik2.Color(0, 64, 128, 192)
c3 = mapnik2.Color(0, 0, 0, 255)
c3.r = 0
c3.g = 64
@ -373,10 +373,10 @@ def test_color_equality():
eq_(c1, c2)
eq_(c1, c3)
c1 = mapnik.Color('rgb(50%,50%,50%)')
c2 = mapnik.Color(128, 128, 128, 255)
c3 = mapnik.Color('#808080')
c4 = mapnik.Color('gray')
c1 = mapnik2.Color('rgb(50%,50%,50%)')
c2 = mapnik2.Color(128, 128, 128, 255)
c3 = mapnik2.Color('#808080')
c4 = mapnik2.Color('gray')
eq_(c1, c2)
eq_(c1, c3)
@ -384,15 +384,15 @@ def test_color_equality():
# Color pickling
def test_color_pickle():
c = mapnik.Color('blue')
c = mapnik2.Color('blue')
eq_(pickle.loads(pickle.dumps(c)), c)
c = mapnik.Color(0, 64, 128)
c = mapnik2.Color(0, 64, 128)
eq_(pickle.loads(pickle.dumps(c)), c)
c = mapnik.Color(0, 64, 128, 192)
c = mapnik2.Color(0, 64, 128, 192)
eq_(pickle.loads(pickle.dumps(c)), c)
@ -401,35 +401,35 @@ def test_rule_init():
min_scale = 5
max_scale = 10
r = mapnik.Rule()
r = mapnik2.Rule()
eq_(r.name, '')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
r = mapnik.Rule("Name")
r = mapnik2.Rule("Name")
eq_(r.name, 'Name')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
r = mapnik.Rule("Name", "Title")
r = mapnik2.Rule("Name", "Title")
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
r = mapnik.Rule("Name", "Title", min_scale)
r = mapnik2.Rule("Name", "Title", min_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, float('inf'))
r = mapnik.Rule("Name", "Title", min_scale, max_scale)
r = mapnik2.Rule("Name", "Title", min_scale, max_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
@ -438,14 +438,14 @@ def test_rule_init():
# Coordinate initialization
def test_coord_init():
c = mapnik.Coord(100, 100)
c = mapnik2.Coord(100, 100)
eq_(c.x, 100)
eq_(c.y, 100)
# Coordinate multiplication
def test_coord_multiplication():
c = mapnik.Coord(100, 100)
c = mapnik2.Coord(100, 100)
c *= 2
eq_(c.x, 200)
@ -453,7 +453,7 @@ def test_coord_multiplication():
# Box2d initialization
def test_envelope_init():
e = mapnik.Box2d(100, 100, 200, 200)
e = mapnik2.Box2d(100, 100, 200, 200)
assert_true(e.contains(100, 100))
assert_true(e.contains(100, 200))
@ -483,13 +483,13 @@ def test_envelope_init():
# Box2d pickling
def test_envelope_pickle():
e = mapnik.Box2d(100, 100, 200, 200)
e = mapnik2.Box2d(100, 100, 200, 200)
eq_(pickle.loads(pickle.dumps(e)), e)
# Box2d multiplication
def test_envelope_multiplication():
e = mapnik.Box2d(100, 100, 200, 200)
e = mapnik2.Box2d(100, 100, 200, 200)
e *= 2
assert_true(e.contains(50, 50))

View file

@ -2,16 +2,16 @@
from nose.tools import *
import mapnik, pickle
import mapnik2, pickle
# Tests that exercise map projections.
# Trac Ticket #128
def test_wgs84_inverse_forward():
p = mapnik.Projection('+init=epsg:4326')
p = mapnik2.Projection('+init=epsg:4326')
c = mapnik.Coord(3.01331418311, 43.3333092669)
e = mapnik.Box2d(-122.54345245, 45.12312553, 68.2335581353, 48.231231233)
c = mapnik2.Coord(3.01331418311, 43.3333092669)
e = mapnik2.Box2d(-122.54345245, 45.12312553, 68.2335581353, 48.231231233)
# It appears that the y component changes very slightly, is this OK?
# so we test for 'almost equal float values'

View file

@ -2,23 +2,23 @@
from nose.tools import *
import os, mapnik
import os, mapnik2
from utilities import Todo
def test_simplest_render():
m = mapnik.Map(256, 256)
i = mapnik.Image(m.width, m.height)
m = mapnik2.Map(256, 256)
i = mapnik2.Image(m.width, m.height)
mapnik.render(m, i)
mapnik2.render(m, i)
s = i.tostring()
eq_(s, 256 * 256 * '\x00\x00\x00\x00')
def test_render_image_to_string():
i = mapnik.Image(256, 256)
i = mapnik2.Image(256, 256)
i.background = mapnik.Color('black')
i.background = mapnik2.Color('black')
s = i.tostring()
@ -27,9 +27,9 @@ def test_render_image_to_string():
s = i.tostring('png')
def test_render_image_to_file():
i = mapnik.Image(256, 256)
i = mapnik2.Image(256, 256)
i.background = mapnik.Color('black')
i.background = mapnik2.Color('black')
i.save('test.jpg')
i.save('test.png', 'png')
@ -46,17 +46,17 @@ def test_render_image_to_file():
def get_paired_images(w,h,mapfile):
tmp_map = 'tmp_map.xml'
m = mapnik.Map(w,h)
mapnik.load_map(m,mapfile)
i = mapnik.Image(w,h)
m = mapnik2.Map(w,h)
mapnik2.load_map(m,mapfile)
i = mapnik2.Image(w,h)
m.zoom_all()
mapnik.render(m,i)
mapnik.save_map(m,tmp_map)
m2 = mapnik.Map(w,h)
mapnik.load_map(m2,tmp_map)
i2 = mapnik.Image(w,h)
mapnik2.render(m,i)
mapnik2.save_map(m,tmp_map)
m2 = mapnik2.Map(w,h)
mapnik2.load_map(m2,tmp_map)
i2 = mapnik2.Image(w,h)
m2.zoom_all()
mapnik.render(m2,i2)
mapnik2.render(m2,i2)
os.remove(tmp_map)
return i,i2
@ -69,27 +69,27 @@ def test_render_from_serialization():
def test_render_points():
# Test for effectivenes of ticket #402 (borderline points get lost on reprojection)
raise Todo("See: http://trac.mapnik.org/ticket/402")
raise Todo("See: http://trac.mapnik2.org/ticket/402")
if not mapnik.has_pycairo(): return
if not mapnik2.has_pycairo(): return
# create and populate point datasource (WGS84 lat-lon coordinates)
places_ds = mapnik.PointDatasource()
places_ds = mapnik2.PointDatasource()
places_ds.add_point(142.48,-38.38,'Name','Westernmost Point') # westernmost
places_ds.add_point(143.10,-38.60,'Name','Southernmost Point') # southernmost
# create layer/rule/style
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.PointSymbolizer()
s = mapnik2.Style()
r = mapnik2.Rule()
symb = mapnik2.PointSymbolizer()
symb.allow_overlap = True
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer('Places','+proj=latlon +datum=WGS84')
lyr = mapnik2.Layer('Places','+proj=latlon +datum=WGS84')
lyr.datasource = places_ds
lyr.styles.append('places_labels')
# latlon bounding box corners
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
ul_lonlat = mapnik2.Coord(142.30,-38.20)
lr_lonlat = mapnik2.Coord(143.40,-38.80)
# render for different projections
projs = {
'latlon': '+proj=latlon +datum=WGS84',
@ -99,16 +99,16 @@ def test_render_points():
}
from cairo import SVGSurface
for projdescr in projs.iterkeys():
m = mapnik.Map(1000, 500, projs[projdescr])
m = mapnik2.Map(1000, 500, projs[projdescr])
m.append_style('places_labels',s)
m.layers.append(lyr)
p = mapnik.Projection(projs[projdescr])
m.zoom_to_box(p.forward(mapnik.Box2d(ul_lonlat,lr_lonlat)))
p = mapnik2.Projection(projs[projdescr])
m.zoom_to_box(p.forward(mapnik2.Box2d(ul_lonlat,lr_lonlat)))
# Render to SVG so that it can be checked how many points are there with string comparison
import StringIO
svg_memory_file = StringIO.StringIO()
surface = SVGSurface(svg_memory_file, m.width, m.height)
mapnik.render(m, surface)
mapnik2.render(m, surface)
surface.flush()
surface.finish()
svg = svg_memory_file.getvalue()

View file

@ -3,7 +3,7 @@
from nose.tools import *
from utilities import execution_path
import os, sys, glob, mapnik
import os, sys, glob, mapnik2
def setup():
# All of the paths used are relative, if we run the tests
@ -16,18 +16,18 @@ def test():
# 2. Save map as XML
# 3. Load map to a second object
# 4. Compare both map objects
map = mapnik.Map(256, 256)
map = mapnik2.Map(256, 256)
in_map = "../data/good_maps/osm-styles.xml"
mapnik.load_map(map, in_map)
mapnik2.load_map(map, in_map)
test_map = "test_map.xml"
mapnik.save_map(map, test_map)
new_map = mapnik.Map(256, 256)
mapnik2.save_map(map, test_map)
new_map = mapnik2.Map(256, 256)
mapnik.load_map(new_map, test_map)
mapnik2.load_map(new_map, test_map)
eq_(open(test_map).read(),mapnik.save_map_to_string(new_map))
eq_(open(test_map).read(),mapnik2.save_map_to_string(new_map))
if os.path.exists(test_map):
os.remove(test_map)

View file

@ -41,13 +41,13 @@ def main():
# Allow python to find libraries for testing on the buildbot
sys.path.insert(0, os.path.join(prefix, "lib/python%s/site-packages" % sys.version[:3]))
import mapnik
import mapnik2
if not quiet:
print "- mapnik path: %s" % mapnik.__file__
print "- _mapnik.so path: %s" % mapnik._mapnik.__file__
print "- Input plugins path: %s" % mapnik.inputpluginspath
print "- Font path: %s" % mapnik.fontscollectionpath
print "- mapnik2 path: %s" % mapnik2.__file__
print "- _mapnik2.so path: %s" % mapnik2._mapnik2.__file__
print "- Input plugins path: %s" % mapnik2.inputpluginspath
print "- Font path: %s" % mapnik2.fontscollectionpath
print
print "- Running nosetests:"
print