2009-04-16 01:06:18 +02:00
#!/usr/bin/env python
from nose . tools import *
2009-04-16 19:22:38 +02:00
from utilities import Todo
2009-04-16 01:06:18 +02:00
2010-03-11 19:12:22 +01:00
import mapnik2 , pickle
2009-04-16 01:06:18 +02:00
# Tests that exercise the functionality of Mapnik classes.
2009-04-17 06:10:45 +02:00
# ShieldSymbolizer initialization
def test_shieldsymbolizer_init ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . ShieldSymbolizer ( mapnik2 . Expression ( ' [Field Name] ' ) , ' DejaVu Sans Bold ' , 6 , mapnik2 . Color ( ' #000000 ' ) , mapnik2 . PathExpression ( ' ../data/images/dummy.png ' ) )
2009-04-17 06:10:45 +02:00
# ShieldSymbolizer missing image file
2010-03-02 04:31:10 +01:00
# images paths are now PathExpressions are evaluated at runtime
# so it does not make sense to throw...
#@raises(RuntimeError)
#def test_shieldsymbolizer_missing_image():
2010-03-11 19:12:22 +01:00
# s = mapnik2.ShieldSymbolizer(mapnik2.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik2.Color('#000000'), mapnik2.PathExpression('../#data/images/broken.png'))
2009-04-17 06:10:45 +02:00
# PointSymbolizer initialization
def test_pointsymbolizer_init ( ) :
2010-03-11 19:12:22 +01:00
p = mapnik2 . PointSymbolizer ( )
2009-04-17 06:10:45 +02:00
eq_ ( p . allow_overlap , False )
2009-09-27 19:45:52 +02:00
eq_ ( p . opacity , 1 )
eq_ ( p . filename , ' ' )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
p = mapnik2 . PointSymbolizer ( mapnik2 . PathExpression ( " ../data/images/dummy.png " ) )
2009-04-17 06:10:45 +02:00
eq_ ( p . allow_overlap , False )
eq_ ( p . opacity , 1 )
2009-09-27 19:45:52 +02:00
eq_ ( p . filename , ' ../data/images/dummy.png ' )
2009-04-17 06:10:45 +02:00
# PointSymbolizer missing image file
2010-03-02 04:31:10 +01:00
# images paths are now PathExpressions are evaluated at runtime
# so it does not make sense to throw...
#@raises(RuntimeError)
#def test_pointsymbolizer_missing_image():
2010-03-11 19:12:22 +01:00
# p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/broken.png"))
2009-04-17 06:10:45 +02:00
# PointSymbolizer pickling
def test_pointsymbolizer_pickle ( ) :
2010-03-11 19:12:22 +01:00
p = mapnik2 . PointSymbolizer ( mapnik2 . PathExpression ( " ../data/images/dummy.png " ) )
2009-08-27 23:11:17 +02:00
p2 = pickle . loads ( pickle . dumps ( p , pickle . HIGHEST_PROTOCOL ) )
# image type, width, and height only used in contructor...
eq_ ( p . filename , p2 . filename )
eq_ ( p . allow_overlap , p2 . allow_overlap )
eq_ ( p . opacity , p2 . opacity )
2009-05-26 03:50:58 +02:00
2009-04-17 06:10:45 +02:00
# PolygonSymbolizer initialization
def test_polygonsymbolizer_init ( ) :
2010-03-11 19:12:22 +01:00
p = mapnik2 . PolygonSymbolizer ( )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
eq_ ( p . fill , mapnik2 . Color ( ' gray ' ) )
2009-04-17 06:10:45 +02:00
eq_ ( p . fill_opacity , 1 )
2010-03-11 19:12:22 +01:00
p = mapnik2 . PolygonSymbolizer ( mapnik2 . Color ( ' blue ' ) )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
eq_ ( p . fill , mapnik2 . Color ( ' blue ' ) )
2009-04-17 06:10:45 +02:00
eq_ ( p . fill_opacity , 1 )
# PolygonSymbolizer pickling
def test_polygonsymbolizer_pickle ( ) :
2010-03-11 19:12:22 +01:00
p = mapnik2 . PolygonSymbolizer ( mapnik2 . Color ( ' black ' ) )
2009-09-25 18:57:03 +02:00
p . fill_opacity = .5
# does not work for some reason...
#eq_(pickle.loads(pickle.dumps(p)), p)
p2 = pickle . loads ( pickle . dumps ( p , pickle . HIGHEST_PROTOCOL ) )
eq_ ( p . fill , p2 . fill )
eq_ ( p . fill_opacity , p2 . fill_opacity )
2009-04-17 06:10:45 +02:00
# Stroke initialization
def test_stroke_init ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . Stroke ( )
2009-04-17 06:10:45 +02:00
eq_ ( s . width , 1 )
eq_ ( s . opacity , 1 )
2010-03-11 19:12:22 +01:00
eq_ ( s . color , mapnik2 . Color ( ' black ' ) )
eq_ ( s . line_cap , mapnik2 . line_cap . BUTT_CAP )
eq_ ( s . line_join , mapnik2 . line_join . MITER_JOIN )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
s = mapnik2 . Stroke ( mapnik2 . Color ( ' blue ' ) , 5.0 )
2009-04-17 06:10:45 +02:00
eq_ ( s . width , 5 )
eq_ ( s . opacity , 1 )
2010-03-11 19:12:22 +01:00
eq_ ( s . color , mapnik2 . Color ( ' blue ' ) )
eq_ ( s . line_cap , mapnik2 . line_cap . BUTT_CAP )
eq_ ( s . line_join , mapnik2 . line_join . MITER_JOIN )
2009-04-17 06:10:45 +02:00
2009-05-24 06:14:35 +02:00
# Stroke dashes
def test_stroke_dash_arrays ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . Stroke ( )
2009-05-24 06:14:35 +02:00
s . add_dash ( 1 , 2 )
s . add_dash ( 3 , 4 )
s . add_dash ( 5 , 6 )
eq_ ( s . get_dashes ( ) , [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) ] )
2009-04-17 06:10:45 +02:00
# Stroke pickling
def test_stroke_pickle ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . Stroke ( mapnik2 . Color ( ' black ' ) , 4.5 )
2009-04-17 06:10:45 +02:00
2009-05-26 03:50:58 +02:00
eq_ ( s . width , 4.5 )
2010-03-11 19:12:22 +01:00
eq_ ( s . color , mapnik2 . Color ( ' black ' ) )
2009-05-26 03:50:58 +02:00
s . add_dash ( 1 , 2 )
s . add_dash ( 3 , 4 )
s . add_dash ( 5 , 6 )
s2 = pickle . loads ( pickle . dumps ( s , pickle . HIGHEST_PROTOCOL ) )
2009-09-25 18:57:03 +02:00
eq_ ( s . color , s2 . color )
2009-05-26 03:50:58 +02:00
eq_ ( s . width , s2 . width )
2009-09-25 18:57:03 +02:00
eq_ ( s . opacity , s2 . opacity )
2009-05-26 03:50:58 +02:00
eq_ ( s . get_dashes ( ) , s2 . get_dashes ( ) )
eq_ ( s . line_cap , s2 . line_cap )
eq_ ( s . line_join , s2 . line_join )
2009-09-25 18:57:03 +02:00
2009-05-26 03:50:58 +02:00
2009-04-17 06:10:45 +02:00
# LineSymbolizer initialization
def test_linesymbolizer_init ( ) :
2010-03-11 19:12:22 +01:00
l = mapnik2 . LineSymbolizer ( )
2009-04-17 06:10:45 +02:00
eq_ ( l . stroke . width , 1 )
eq_ ( l . stroke . opacity , 1 )
2010-03-11 19:12:22 +01:00
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 )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
l = mapnik2 . LineSymbolizer ( mapnik2 . Color ( ' blue ' ) , 5.0 )
2009-04-17 06:10:45 +02:00
eq_ ( l . stroke . width , 5 )
eq_ ( l . stroke . opacity , 1 )
2010-03-11 19:12:22 +01:00
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 )
2009-04-17 06:10:45 +02:00
2010-03-11 19:12:22 +01:00
s = mapnik2 . Stroke ( mapnik2 . Color ( ' blue ' ) , 5.0 )
l = mapnik2 . LineSymbolizer ( s )
2009-04-17 06:10:45 +02:00
eq_ ( l . stroke . width , 5 )
eq_ ( l . stroke . opacity , 1 )
2010-03-11 19:12:22 +01:00
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 )
2009-04-17 06:10:45 +02:00
# LineSymbolizer pickling
def test_linesymbolizer_pickle ( ) :
2010-03-11 19:12:22 +01:00
p = mapnik2 . LineSymbolizer ( )
2009-09-25 18:57:03 +02:00
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
eq_ ( s . color , s2 . color )
eq_ ( s . opacity , s2 . opacity )
eq_ ( s . width , s2 . width )
eq_ ( s . get_dashes ( ) , s2 . get_dashes ( ) )
eq_ ( s . line_cap , s2 . line_cap )
eq_ ( s . line_join , s2 . line_join )
2009-04-17 06:10:45 +02:00
2009-04-16 19:22:38 +02:00
# Shapefile initialization
def test_shapefile_init ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . Shapefile ( file = ' ../../demo/data/boundaries ' )
2009-04-16 19:22:38 +02:00
e = s . envelope ( )
assert_almost_equal ( e . minx , - 11121.6896651 , places = 7 )
assert_almost_equal ( e . miny , - 724724.216526 , places = 6 )
assert_almost_equal ( e . maxx , 2463000.67866 , places = 5 )
assert_almost_equal ( e . maxy , 1649661.267 , places = 3 )
2009-04-17 06:10:45 +02:00
# Shapefile properties
def test_shapefile_properties ( ) :
2010-03-11 19:12:22 +01:00
s = mapnik2 . Shapefile ( file = ' ../../demo/data/boundaries ' , encoding = ' latin1 ' )
2009-05-01 03:21:29 +02:00
f = s . features_at_point ( s . envelope ( ) . center ( ) ) . features [ 0 ]
2009-04-17 06:10:45 +02:00
2010-03-12 14:33:46 +01:00
eq_ ( f [ ' CGNS_FID ' ] , u ' 6f733341ba2011d892e2080020a0f4c9 ' )
eq_ ( f [ ' COUNTRY ' ] , u ' CAN ' )
eq_ ( f [ ' F_CODE ' ] , u ' FA001 ' )
eq_ ( f [ ' NAME_EN ' ] , u ' Quebec ' )
eq_ ( f [ ' NOM_FR ' ] , u ' Qu \xe9 bec ' )
eq_ ( f [ ' Shape_Area ' ] , 1512185733150.0 )
eq_ ( f [ ' Shape_Leng ' ] , 19218883.724300001 )
# Check that the deprecated interface still works,
# remove me once the deprecated code is cleaned up
2009-04-17 06:10:45 +02:00
eq_ ( f . properties [ ' Shape_Leng ' ] , 19218883.724300001 )
2009-04-16 19:22:38 +02:00
# TextSymbolizer initialization
def test_textsymbolizer_init ( ) :
2010-03-11 19:12:22 +01:00
ts = mapnik2 . TextSymbolizer ( mapnik2 . Expression ( ' [Field_Name] ' ) , ' Font Name ' , 8 , mapnik2 . Color ( ' black ' ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
eq_ ( str ( ts . name ) , str ( mapnik2 . Expression ( ' Field_Name ' ) ) )
2009-04-16 19:22:38 +02:00
eq_ ( ts . face_name , ' Font Name ' )
eq_ ( ts . text_size , 8 )
2010-03-11 19:12:22 +01:00
eq_ ( ts . fill , mapnik2 . Color ( ' black ' ) )
2009-04-16 19:22:38 +02:00
2009-05-26 03:50:58 +02:00
# TextSymbolizer pickling
def test_textsymbolizer_pickle ( ) :
2010-03-11 19:12:22 +01:00
ts = mapnik2 . TextSymbolizer ( mapnik2 . Expression ( ' [Field_Name] ' ) , ' Font Name ' , 8 , mapnik2 . Color ( ' black ' ) )
2009-05-26 03:50:58 +02:00
2010-03-11 19:12:22 +01:00
eq_ ( str ( ts . name ) , str ( mapnik2 . Expression ( ' Field_Name ' ) ) )
2009-05-26 03:50:58 +02:00
eq_ ( ts . face_name , ' Font Name ' )
eq_ ( ts . text_size , 8 )
2010-03-11 19:12:22 +01:00
eq_ ( ts . fill , mapnik2 . Color ( ' black ' ) )
2009-05-26 03:50:58 +02:00
ts2 = pickle . loads ( pickle . dumps ( ts , pickle . HIGHEST_PROTOCOL ) )
eq_ ( ts . name , ts2 . name )
eq_ ( ts . face_name , ts2 . face_name )
eq_ ( ts . allow_overlap , ts2 . allow_overlap )
eq_ ( ts . get_displacement ( ) , ts2 . get_displacement ( ) )
eq_ ( ts . get_anchor ( ) , ts2 . get_anchor ( ) )
eq_ ( ts . fill , ts2 . fill )
eq_ ( ts . force_odd_labels , ts2 . force_odd_labels )
eq_ ( ts . halo_fill , ts2 . halo_fill )
eq_ ( ts . halo_radius , ts2 . halo_radius )
eq_ ( ts . label_placement , ts2 . label_placement )
eq_ ( ts . minimum_distance , ts2 . minimum_distance )
eq_ ( ts . text_ratio , ts2 . text_ratio )
eq_ ( ts . text_size , ts2 . text_size )
eq_ ( ts . wrap_width , ts2 . wrap_width )
eq_ ( ts . vertical_alignment , ts2 . vertical_alignment )
eq_ ( ts . label_spacing , ts2 . label_spacing )
eq_ ( ts . label_position_tolerance , ts2 . label_position_tolerance )
2009-08-18 00:54:50 +02:00
eq_ ( ts . wrap_character , ts2 . wrap_character )
eq_ ( ts . text_convert , ts2 . text_convert )
eq_ ( ts . line_spacing , ts2 . line_spacing )
eq_ ( ts . character_spacing , ts2 . character_spacing )
2010-01-11 20:00:56 +01:00
# r1341
eq_ ( ts . wrap_before , ts2 . wrap_before )
eq_ ( ts . horizontal_alignment , ts2 . horizontal_alignment )
eq_ ( ts . justify_alignment , ts2 . justify_alignment )
eq_ ( ts . opacity , ts2 . opacity )
2010-03-11 19:12:22 +01:00
raise Todo ( " FontSet pickling support needed: http://trac.mapnik2.org/ticket/348 " )
2009-05-26 03:50:58 +02:00
eq_ ( ts . fontset , ts2 . fontset )
2009-04-16 19:22:38 +02:00
# Map initialization
def test_map_init ( ) :
2010-03-11 19:12:22 +01:00
m = mapnik2 . Map ( 256 , 256 )
2009-04-16 19:22:38 +02:00
eq_ ( m . width , 256 )
eq_ ( m . height , 256 )
eq_ ( m . srs , ' +proj=latlong +datum=WGS84 ' )
2010-03-11 19:12:22 +01:00
m = mapnik2 . Map ( 256 , 256 , ' +proj=latlong ' )
2009-04-16 19:22:38 +02:00
eq_ ( m . width , 256 )
eq_ ( m . height , 256 )
eq_ ( m . srs , ' +proj=latlong ' )
# Map initialization from string
def test_map_init_from_string ( ) :
map_string = ''' <Map bgcolor= " steelblue " srs= " +proj=latlong +datum=WGS84 " >
< Style name = " My Style " >
< Rule >
< PolygonSymbolizer >
< CssParameter name = " fill " > #f2eff9</CssParameter>
< / PolygonSymbolizer >
< LineSymbolizer >
< CssParameter name = " stroke " > rgb ( 50 % , 50 % , 50 % ) < / CssParameter >
< CssParameter name = " stroke-width " > 0.1 < / CssParameter >
< / LineSymbolizer >
< / Rule >
< / Style >
< Layer name = " boundaries " >
< StyleName > My Style < / StyleName >
< Datasource >
< Parameter name = " type " > shape < / Parameter >
< Parameter name = " file " > . . / . . / demo / data / boundaries < / Parameter >
< / Datasource >
< / Layer >
< / Map > '''
2010-03-11 19:12:22 +01:00
m = mapnik2 . Map ( 600 , 300 )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
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 , " " )
2009-09-27 19:45:52 +02:00
raise ( Todo ( " Need to write more map property tests in ' object_test.py ' ... " ) )
2009-04-16 19:22:38 +02:00
# Map pickling
def test_map_pickle ( ) :
# Fails due to scale() not matching, possibly other things
2009-09-25 18:57:03 +02:00
raise ( Todo ( " Map does not support pickling yet (Tickets #345). " ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
m = mapnik2 . Map ( 256 , 256 )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( m ) ) , m )
2010-03-11 19:12:22 +01:00
m = mapnik2 . Map ( 256 , 256 , ' +proj=latlong ' )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( m ) ) , m )
# Color initialization
def test_color_init ( ) :
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( ' blue ' )
2009-04-16 19:22:38 +02:00
eq_ ( c . a , 255 )
eq_ ( c . r , 0 )
eq_ ( c . g , 0 )
eq_ ( c . b , 255 )
eq_ ( c . to_hex_string ( ) , ' #0000ff ' )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( ' #f2eff9 ' )
2009-04-17 06:10:45 +02:00
eq_ ( c . a , 255 )
eq_ ( c . r , 242 )
eq_ ( c . g , 239 )
eq_ ( c . b , 249 )
eq_ ( c . to_hex_string ( ) , ' #f2eff9 ' )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( ' rgb(50 % ,50 % ,50 % ) ' )
2009-04-17 06:10:45 +02:00
eq_ ( c . a , 255 )
eq_ ( c . r , 128 )
eq_ ( c . g , 128 )
eq_ ( c . b , 128 )
eq_ ( c . to_hex_string ( ) , ' #808080 ' )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( 0 , 64 , 128 )
2009-04-16 19:22:38 +02:00
eq_ ( c . a , 255 )
eq_ ( c . r , 0 )
eq_ ( c . g , 64 )
eq_ ( c . b , 128 )
eq_ ( c . to_hex_string ( ) , ' #004080 ' )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( 0 , 64 , 128 , 192 )
2009-04-16 19:22:38 +02:00
eq_ ( c . a , 192 )
eq_ ( c . r , 0 )
eq_ ( c . g , 64 )
eq_ ( c . b , 128 )
eq_ ( c . to_hex_string ( ) , ' #004080 ' )
2009-04-17 06:10:45 +02:00
# Color equality
def test_color_equality ( ) :
2010-03-11 19:12:22 +01:00
c1 = mapnik2 . Color ( ' blue ' )
c2 = mapnik2 . Color ( ' blue ' )
c3 = mapnik2 . Color ( ' black ' )
2009-04-17 06:10:45 +02:00
c3 . r = 0
c3 . g = 0
c3 . b = 255
c3 . a = 255
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2010-03-11 19:12:22 +01:00
c1 = mapnik2 . Color ( 0 , 64 , 128 )
c2 = mapnik2 . Color ( 0 , 64 , 128 )
c3 = mapnik2 . Color ( 0 , 0 , 0 )
2009-04-17 06:10:45 +02:00
c3 . r = 0
c3 . g = 64
c3 . b = 128
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2010-03-11 19:12:22 +01:00
c1 = mapnik2 . Color ( 0 , 64 , 128 , 192 )
c2 = mapnik2 . Color ( 0 , 64 , 128 , 192 )
c3 = mapnik2 . Color ( 0 , 0 , 0 , 255 )
2009-04-17 06:10:45 +02:00
c3 . r = 0
c3 . g = 64
c3 . b = 128
c3 . a = 192
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2010-03-11 19:12:22 +01:00
c1 = mapnik2 . Color ( ' rgb(50 % ,50 % ,50 % ) ' )
c2 = mapnik2 . Color ( 128 , 128 , 128 , 255 )
c3 = mapnik2 . Color ( ' #808080 ' )
c4 = mapnik2 . Color ( ' gray ' )
2009-04-17 06:10:45 +02:00
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
eq_ ( c1 , c4 )
2009-04-16 19:22:38 +02:00
# Color pickling
def test_color_pickle ( ) :
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( ' blue ' )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( c ) ) , c )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( 0 , 64 , 128 )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( c ) ) , c )
2010-03-11 19:12:22 +01:00
c = mapnik2 . Color ( 0 , 64 , 128 , 192 )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( c ) ) , c )
2009-04-16 01:06:18 +02:00
# Rule initialization
def test_rule_init ( ) :
min_scale = 5
max_scale = 10
2010-03-11 19:12:22 +01:00
r = mapnik2 . Rule ( )
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' ' )
eq_ ( r . title , ' ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
r = mapnik2 . Rule ( " Name " )
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . title , ' ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
r = mapnik2 . Rule ( " Name " , " Title " )
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . title , ' Title ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
r = mapnik2 . Rule ( " Name " , " Title " , min_scale )
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . title , ' Title ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , float ( ' inf ' ) )
2009-04-16 19:22:38 +02:00
2010-03-11 19:12:22 +01:00
r = mapnik2 . Rule ( " Name " , " Title " , min_scale , max_scale )
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . title , ' Title ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , max_scale )
2009-04-16 19:22:38 +02:00
2009-04-16 01:06:18 +02:00
# Coordinate initialization
def test_coord_init ( ) :
2010-03-11 19:12:22 +01:00
c = mapnik2 . Coord ( 100 , 100 )
2009-04-16 01:06:18 +02:00
eq_ ( c . x , 100 )
eq_ ( c . y , 100 )
# Coordinate multiplication
def test_coord_multiplication ( ) :
2010-03-11 19:12:22 +01:00
c = mapnik2 . Coord ( 100 , 100 )
2009-04-16 01:06:18 +02:00
c * = 2
eq_ ( c . x , 200 )
eq_ ( c . y , 200 )
2009-12-16 21:02:06 +01:00
# Box2d initialization
2009-04-16 01:06:18 +02:00
def test_envelope_init ( ) :
2010-03-11 19:12:22 +01:00
e = mapnik2 . Box2d ( 100 , 100 , 200 , 200 )
2009-04-16 01:06:18 +02:00
assert_true ( e . contains ( 100 , 100 ) )
assert_true ( e . contains ( 100 , 200 ) )
assert_true ( e . contains ( 200 , 200 ) )
assert_true ( e . contains ( 200 , 100 ) )
assert_true ( e . contains ( e . center ( ) ) )
assert_false ( e . contains ( 99.9 , 99.9 ) )
assert_false ( e . contains ( 99.9 , 200.1 ) )
assert_false ( e . contains ( 200.1 , 200.1 ) )
assert_false ( e . contains ( 200.1 , 99.9 ) )
eq_ ( e . width ( ) , 100 )
eq_ ( e . height ( ) , 100 )
eq_ ( e . minx , 100 )
eq_ ( e . miny , 100 )
eq_ ( e . maxx , 200 )
eq_ ( e . maxy , 200 )
c = e . center ( )
eq_ ( c . x , 150 )
eq_ ( c . y , 150 )
2009-12-16 21:02:06 +01:00
# Box2d pickling
2009-04-16 19:22:38 +02:00
def test_envelope_pickle ( ) :
2010-03-11 19:12:22 +01:00
e = mapnik2 . Box2d ( 100 , 100 , 200 , 200 )
2009-04-16 19:22:38 +02:00
eq_ ( pickle . loads ( pickle . dumps ( e ) ) , e )
2009-12-16 21:02:06 +01:00
# Box2d multiplication
2009-04-16 01:06:18 +02:00
def test_envelope_multiplication ( ) :
2010-03-11 19:12:22 +01:00
e = mapnik2 . Box2d ( 100 , 100 , 200 , 200 )
2009-04-16 01:06:18 +02:00
e * = 2
assert_true ( e . contains ( 50 , 50 ) )
assert_true ( e . contains ( 50 , 250 ) )
assert_true ( e . contains ( 250 , 250 ) )
assert_true ( e . contains ( 250 , 50 ) )
assert_false ( e . contains ( 49.9 , 49.9 ) )
assert_false ( e . contains ( 49.9 , 250.1 ) )
assert_false ( e . contains ( 250.1 , 250.1 ) )
assert_false ( e . contains ( 250.1 , 49.9 ) )
assert_true ( e . contains ( e . center ( ) ) )
eq_ ( e . width ( ) , 200 )
eq_ ( e . height ( ) , 200 )
eq_ ( e . minx , 50 )
eq_ ( e . miny , 50 )
eq_ ( e . maxx , 250 )
eq_ ( e . maxy , 250 )
c = e . center ( )
eq_ ( c . x , 150 )
eq_ ( c . y , 150 )