2009-04-16 01:06:18 +02:00
#!/usr/bin/env python
2011-10-10 23:04:34 +02:00
# -*- coding: utf-8 -*-
2009-04-16 01:06:18 +02:00
2011-08-31 00:51:42 +02:00
import os
2009-04-16 01:06:18 +02:00
from nose . tools import *
2013-06-03 04:28:24 +02:00
from utilities import execution_path , run_all
2011-11-30 03:15:25 +01:00
import tempfile
2009-04-16 01:06:18 +02:00
2011-12-03 00:21:35 +01:00
import mapnik
2009-04-16 01:06:18 +02:00
2011-08-31 00:51:42 +02:00
def setup ( ) :
# All of the paths used are relative, if we run the tests
# from another directory we need to chdir()
os . chdir ( execution_path ( ' . ' ) )
2013-05-22 04:21:35 +02:00
def test_debug_symbolizer ( ) :
s = mapnik . DebugSymbolizer ( )
eq_ ( s . mode , mapnik . debug_symbolizer_mode . collision )
2012-10-02 01:15:28 +02:00
def test_raster_symbolizer ( ) :
s = mapnik . RasterSymbolizer ( )
eq_ ( s . comp_op , mapnik . CompositeOp . src_over ) # note: mode is deprecated
eq_ ( s . scaling , mapnik . scaling_method . NEAR )
eq_ ( s . opacity , 1.0 )
eq_ ( s . colorizer , None )
eq_ ( s . filter_factor , - 1 )
eq_ ( s . mesh_size , 16 )
eq_ ( s . premultiplied , None )
s . premultiplied = True
eq_ ( s . premultiplied , True )
2012-08-22 03:18:20 +02:00
def test_line_pattern ( ) :
s = mapnik . LinePatternSymbolizer ( mapnik . PathExpression ( ' ../data/images/dummy.png ' ) )
eq_ ( s . filename , ' ../data/images/dummy.png ' )
eq_ ( s . smooth , 0.0 )
eq_ ( s . transform , ' ' )
2013-08-21 17:40:40 +02:00
eq_ ( s . offset , 0.0 )
2012-08-22 03:18:20 +02:00
eq_ ( s . comp_op , mapnik . CompositeOp . src_over )
eq_ ( s . clip , True )
def test_line_symbolizer ( ) :
2011-11-23 12:33:58 +01:00
s = mapnik . LineSymbolizer ( )
eq_ ( s . rasterizer , mapnik . line_rasterizer . FULL )
2012-08-22 03:18:20 +02:00
eq_ ( s . smooth , 0.0 )
eq_ ( s . comp_op , mapnik . CompositeOp . src_over )
eq_ ( s . clip , True )
eq_ ( s . stroke . width , 1 )
eq_ ( s . stroke . opacity , 1 )
eq_ ( s . stroke . color , mapnik . Color ( ' black ' ) )
eq_ ( s . stroke . line_cap , mapnik . line_cap . BUTT_CAP )
eq_ ( s . stroke . line_join , mapnik . line_join . MITER_JOIN )
l = mapnik . LineSymbolizer ( mapnik . 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 )
s = mapnik . Stroke ( mapnik . Color ( ' blue ' ) , 5.0 )
l = mapnik . 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 )
2011-09-10 01:45:49 +02:00
2012-04-02 20:57:24 +02:00
def test_line_symbolizer_stroke_reference ( ) :
l = mapnik . LineSymbolizer ( mapnik . Color ( ' green ' ) , 0.1 )
l . stroke . add_dash ( .1 , .1 )
l . stroke . add_dash ( .1 , .1 )
eq_ ( l . stroke . get_dashes ( ) , [ ( .1 , .1 ) , ( .1 , .1 ) ] )
eq_ ( l . stroke . color , mapnik . Color ( ' green ' ) )
eq_ ( l . stroke . opacity , 1.0 )
assert_almost_equal ( l . stroke . width , 0.1 )
2012-08-22 00:59:31 +02:00
# https://github.com/mapnik/mapnik/issues/1427
def test_stroke_dash_api ( ) :
stroke = mapnik . Stroke ( )
dashes = [ ( 1.0 , 1.0 ) ]
stroke . dasharray = dashes
eq_ ( stroke . dasharray , dashes )
stroke . add_dash ( .1 , .1 )
dashes . append ( ( .1 , .1 ) )
eq_ ( stroke . dasharray , dashes )
2012-08-22 03:18:20 +02:00
def test_text_symbolizer ( ) :
2012-08-21 23:27:57 +02:00
s = mapnik . TextSymbolizer ( )
2012-08-22 03:18:20 +02:00
eq_ ( s . comp_op , mapnik . CompositeOp . src_over )
eq_ ( s . clip , True )
2013-03-09 05:32:39 +01:00
eq_ ( s . halo_rasterizer , mapnik . halo_rasterizer . FULL )
2012-08-22 03:18:20 +02:00
# https://github.com/mapnik/mapnik/issues/1420
2012-08-21 23:27:57 +02:00
eq_ ( s . text_transform , mapnik . text_transform . NONE )
2012-08-22 03:18:20 +02:00
2012-08-21 23:48:10 +02:00
# https://github.com/mapnik/mapnik/issues/1427
eq_ ( s . wrap_char , ord ( ' ' ) )
eq_ ( s . wrap_character , ord ( ' ' ) )
s . wrap_char = ord ( ' \n ' )
eq_ ( s . wrap_char , ord ( ' \n ' ) )
eq_ ( s . wrap_character , ord ( ' \n ' ) )
eq_ ( s . format . wrap_character , ord ( ' \n ' ) )
s . wrap_character = ord ( ' \r ' )
eq_ ( s . wrap_char , ord ( ' \r ' ) )
eq_ ( s . wrap_character , ord ( ' \r ' ) )
eq_ ( s . format . wrap_character , ord ( ' \r ' ) )
s . format . wrap_character = ord ( ' ' )
eq_ ( s . wrap_char , ord ( ' ' ) )
eq_ ( s . wrap_character , ord ( ' ' ) )
eq_ ( s . format . wrap_character , ord ( ' ' ) )
2012-08-21 23:27:57 +02:00
2012-08-22 03:18:20 +02:00
# old args required method
ts = mapnik . TextSymbolizer ( mapnik . Expression ( ' [Field_Name] ' ) , ' Font Name ' , 8 , mapnik . Color ( ' black ' ) )
# eq_(str(ts.name), str(mapnik2.Expression('[Field_Name]'))) name field is no longer supported
eq_ ( ts . format . face_name , ' Font Name ' )
eq_ ( ts . format . text_size , 8 )
eq_ ( ts . format . fill , mapnik . Color ( ' black ' ) )
eq_ ( ts . properties . label_placement , mapnik . label_placement . POINT_PLACEMENT )
eq_ ( ts . properties . horizontal_alignment , mapnik . horizontal_alignment . AUTO )
def test_shield_symbolizer_init ( ) :
2011-11-23 12:33:58 +01:00
s = mapnik . ShieldSymbolizer ( mapnik . Expression ( ' [Field Name] ' ) , ' DejaVu Sans Bold ' , 6 , mapnik . Color ( ' #000000 ' ) , mapnik . PathExpression ( ' ../data/images/dummy.png ' ) )
2012-08-22 03:18:20 +02:00
eq_ ( s . comp_op , mapnik . CompositeOp . src_over )
eq_ ( s . clip , True )
2010-12-11 02:21:46 +01:00
eq_ ( s . displacement , ( 0.0 , 0.0 ) )
2010-10-13 03:23:56 +02:00
eq_ ( s . allow_overlap , False )
2010-12-10 23:09:34 +01:00
eq_ ( s . avoid_edges , False )
eq_ ( s . character_spacing , 0 )
2012-01-20 00:45:15 +01:00
#eq_(str(s.name), str(mapnik2.Expression('[Field Name]'))) name field is no longer supported
2010-12-10 23:09:34 +01:00
eq_ ( s . face_name , ' DejaVu Sans Bold ' )
eq_ ( s . allow_overlap , False )
2011-11-23 12:33:58 +01:00
eq_ ( s . fill , mapnik . Color ( ' #000000 ' ) )
eq_ ( s . halo_fill , mapnik . Color ( ' rgb(255,255,255) ' ) )
2010-12-10 23:09:34 +01:00
eq_ ( s . halo_radius , 0 )
2011-11-23 12:33:58 +01:00
eq_ ( s . label_placement , mapnik . label_placement . POINT_PLACEMENT )
2010-12-10 23:09:34 +01:00
eq_ ( s . minimum_distance , 0.0 )
eq_ ( s . text_ratio , 0 )
eq_ ( s . text_size , 6 )
eq_ ( s . wrap_width , 0 )
2012-01-28 19:37:13 +01:00
eq_ ( s . vertical_alignment , mapnik . vertical_alignment . AUTO )
2010-12-10 23:09:34 +01:00
eq_ ( s . label_spacing , 0 )
eq_ ( s . label_position_tolerance , 0 )
2011-05-04 07:24:57 +02:00
# 22.5 * M_PI/180.0 initialized by default
assert_almost_equal ( s . max_char_angle_delta , 0.39269908169872414 )
2012-02-24 22:13:56 +01:00
2010-12-10 23:09:34 +01:00
eq_ ( s . wrap_character , ' ' )
2011-11-23 12:33:58 +01:00
eq_ ( s . text_transform , mapnik . text_transform . NONE )
2010-12-10 23:09:34 +01:00
eq_ ( s . line_spacing , 0 )
eq_ ( s . character_spacing , 0 )
2012-02-24 22:13:56 +01:00
2010-10-13 03:23:56 +02:00
# r1341
2010-12-10 23:09:34 +01:00
eq_ ( s . wrap_before , False )
2012-01-28 19:37:13 +01:00
eq_ ( s . horizontal_alignment , mapnik . horizontal_alignment . AUTO )
2012-03-19 17:40:51 +01:00
eq_ ( s . justify_alignment , mapnik . justify_alignment . AUTO )
2010-12-10 23:09:34 +01:00
eq_ ( s . opacity , 1.0 )
2012-02-24 22:13:56 +01:00
2010-12-10 23:26:17 +01:00
# r2300
eq_ ( s . minimum_padding , 0.0 )
2012-02-24 22:13:56 +01:00
2010-12-10 23:26:17 +01:00
# was mixed with s.opacity
eq_ ( s . text_opacity , 1.0 )
2010-12-11 02:21:46 +01:00
eq_ ( s . shield_displacement , ( 0.0 , 0.0 ) )
# TODO - the pattern in bindings seems to be to get/set
# strings for PathExpressions... should we pass objects?
eq_ ( s . filename , ' ../data/images/dummy.png ' )
2012-06-07 17:12:15 +02:00
# 11c34b1: default transform list is empty, not identity matrix
eq_ ( s . transform , ' ' )
2012-02-24 22:13:56 +01:00
2012-09-14 23:17:45 +02:00
eq_ ( s . fontset , None )
2010-10-13 03:23:56 +02:00
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():
2011-11-23 12:33:58 +01:00
# s = mapnik.ShieldSymbolizer(mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../#data/images/broken.png'))
2009-04-17 06:10:45 +02:00
2012-08-22 03:18:20 +02:00
def test_shield_symbolizer_modify ( ) :
2012-06-07 17:12:15 +02:00
s = mapnik . ShieldSymbolizer ( mapnik . Expression ( ' [Field Name] ' ) , ' DejaVu Sans Bold ' , 6 , mapnik . Color ( ' #000000 ' ) , mapnik . PathExpression ( ' ../data/images/dummy.png ' ) )
# transform expression
2012-08-20 02:24:34 +02:00
def check_transform ( expr , expect_str = None ) :
s . transform = expr
eq_ ( s . transform , expr if expect_str is None else expect_str )
2012-12-18 13:13:42 +01:00
check_transform ( " matrix(1 2 3 4 5 6) " , " matrix(1, 2, 3, 4, 5, 6) " )
2012-08-20 02:24:34 +02:00
check_transform ( " matrix(1, 2, 3, 4, 5, 6 +7) " , " matrix(1, 2, 3, 4, 5, (6+7)) " )
check_transform ( " rotate([a]) " )
check_transform ( " rotate([a] -2) " , " rotate(([a]-2)) " )
2012-12-18 13:13:42 +01:00
check_transform ( " rotate([a] -2 -3) " , " rotate([a], -2, -3) " )
2012-08-20 02:24:34 +02:00
check_transform ( " rotate([a] -2 -3 -4) " , " rotate(((([a]-2)-3)-4)) " )
check_transform ( " rotate([a] -2, 3, 4) " , " rotate(([a]-2), 3, 4) " )
check_transform ( " translate([tx]) rotate([a]) " )
check_transform ( " scale([sx], [sy]/2) " )
# TODO check expected failures
2012-06-07 17:12:15 +02:00
2012-08-22 03:18:20 +02:00
def test_point_symbolizer ( ) :
2012-08-21 03:17:00 +02:00
p = mapnik . PointSymbolizer ( )
2009-09-27 19:45:52 +02:00
eq_ ( p . filename , ' ' )
2012-08-22 03:18:20 +02:00
eq_ ( p . transform , ' ' )
eq_ ( p . opacity , 1.0 )
eq_ ( p . allow_overlap , False )
2010-10-15 04:16:37 +02:00
eq_ ( p . ignore_placement , False )
2012-08-22 03:18:20 +02:00
eq_ ( p . comp_op , mapnik . CompositeOp . src_over )
2011-11-23 12:33:58 +01:00
eq_ ( p . placement , mapnik . point_placement . CENTROID )
2009-04-17 06:10:45 +02:00
2011-11-23 12:33:58 +01:00
p = mapnik . PointSymbolizer ( mapnik . PathExpression ( " ../data/images/dummy.png " ) )
2010-10-15 04:16:37 +02:00
p . allow_overlap = True
p . opacity = 0.5
p . ignore_placement = True
2011-11-23 12:33:58 +01:00
p . placement = mapnik . point_placement . INTERIOR
2010-10-15 04:16:37 +02:00
eq_ ( p . allow_overlap , True )
eq_ ( p . opacity , 0.5 )
2009-09-27 19:45:52 +02:00
eq_ ( p . filename , ' ../data/images/dummy.png ' )
2010-10-15 04:16:37 +02:00
eq_ ( p . ignore_placement , True )
2011-11-23 12:33:58 +01:00
eq_ ( p . placement , mapnik . point_placement . INTERIOR )
2009-04-17 06:10:45 +02:00
2012-08-22 03:18:20 +02:00
def test_markers_symbolizer ( ) :
2012-08-07 12:36:44 +02:00
p = mapnik . MarkersSymbolizer ( )
2012-04-11 11:41:15 +02:00
eq_ ( p . allow_overlap , False )
2012-08-03 23:14:03 +02:00
eq_ ( p . opacity , 1.0 )
2012-07-31 03:31:21 +02:00
eq_ ( p . fill_opacity , None )
2012-07-13 04:21:04 +02:00
eq_ ( p . filename , ' shape://ellipse ' )
eq_ ( p . placement , mapnik . marker_placement . POINT_PLACEMENT )
2012-11-21 02:58:39 +01:00
eq_ ( p . multi_policy , mapnik . marker_multi_policy . EACH )
2012-07-13 04:21:04 +02:00
eq_ ( p . fill , None )
2012-06-04 22:42:51 +02:00
eq_ ( p . ignore_placement , False )
eq_ ( p . spacing , 100 )
eq_ ( p . max_error , 0.2 )
2012-07-13 04:21:04 +02:00
eq_ ( p . width , None )
eq_ ( p . height , None )
2012-08-22 03:18:20 +02:00
eq_ ( p . transform , ' ' )
eq_ ( p . clip , True )
eq_ ( p . comp_op , mapnik . CompositeOp . src_over )
2012-12-18 13:13:42 +01:00
2012-06-29 04:54:25 +02:00
p . width = mapnik . Expression ( ' 12 ' )
p . height = mapnik . Expression ( ' 12 ' )
eq_ ( str ( p . width ) , ' 12 ' )
eq_ ( str ( p . height ) , ' 12 ' )
p . width = mapnik . Expression ( ' [field] + 2 ' )
p . height = mapnik . Expression ( ' [field] + 2 ' )
eq_ ( str ( p . width ) , ' ([field]+2) ' )
eq_ ( str ( p . height ) , ' ([field]+2) ' )
2012-04-11 11:41:15 +02:00
stroke = mapnik . Stroke ( )
stroke . color = mapnik . Color ( ' black ' )
stroke . width = 1.0
2012-08-07 12:36:44 +02:00
2012-04-11 11:41:15 +02:00
p . stroke = stroke
p . fill = mapnik . Color ( ' white ' )
p . allow_overlap = True
p . opacity = 0.5
2012-08-07 12:36:44 +02:00
p . fill_opacity = 0.5
2012-11-21 02:58:39 +01:00
p . placement = mapnik . marker_placement . LINE_PLACEMENT
p . multi_policy = mapnik . marker_multi_policy . WHOLE
2012-04-11 11:41:15 +02:00
eq_ ( p . allow_overlap , True )
eq_ ( p . opacity , 0.5 )
2012-07-31 03:31:21 +02:00
eq_ ( p . fill_opacity , 0.5 )
2012-11-21 02:58:39 +01:00
eq_ ( p . multi_policy , mapnik . marker_multi_policy . WHOLE )
eq_ ( p . placement , mapnik . marker_placement . LINE_PLACEMENT )
2012-04-11 11:41:15 +02:00
2012-08-22 01:36:15 +02:00
#https://github.com/mapnik/mapnik/issues/1285
#https://github.com/mapnik/mapnik/issues/1427
p . marker_type = ' arrow '
eq_ ( p . marker_type , ' shape://arrow ' )
eq_ ( p . filename , ' shape://arrow ' )
2012-04-11 11:41:15 +02:00
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():
2011-11-23 12:33:58 +01:00
# p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/broken.png"))
2009-04-17 06:10:45 +02:00
2012-08-22 03:18:20 +02:00
def test_polygon_symbolizer ( ) :
2011-11-23 12:33:58 +01:00
p = mapnik . PolygonSymbolizer ( )
2012-08-22 03:18:20 +02:00
eq_ ( p . smooth , 0.0 )
eq_ ( p . comp_op , mapnik . CompositeOp . src_over )
eq_ ( p . clip , True )
2011-11-23 12:33:58 +01:00
eq_ ( p . fill , mapnik . Color ( ' gray ' ) )
2009-04-17 06:10:45 +02:00
eq_ ( p . fill_opacity , 1 )
2011-11-23 12:33:58 +01:00
p = mapnik . PolygonSymbolizer ( mapnik . Color ( ' blue ' ) )
2009-04-17 06:10:45 +02:00
2011-11-23 12:33:58 +01:00
eq_ ( p . fill , mapnik . Color ( ' blue ' ) )
2009-04-17 06:10:45 +02:00
eq_ ( p . fill_opacity , 1 )
2012-08-21 03:17:00 +02:00
def test_building_symbolizer_init ( ) :
p = mapnik . BuildingSymbolizer ( )
eq_ ( p . fill , mapnik . Color ( ' gray ' ) )
eq_ ( p . fill_opacity , 1 )
eq_ ( p . height , None )
2009-04-17 06:10:45 +02:00
def test_stroke_init ( ) :
2011-11-23 12:33:58 +01:00
s = mapnik . Stroke ( )
2009-04-17 06:10:45 +02:00
eq_ ( s . width , 1 )
eq_ ( s . opacity , 1 )
2011-11-23 12:33:58 +01:00
eq_ ( s . color , mapnik . Color ( ' black ' ) )
eq_ ( s . line_cap , mapnik . line_cap . BUTT_CAP )
eq_ ( s . line_join , mapnik . line_join . MITER_JOIN )
2011-02-02 02:46:14 +01:00
eq_ ( s . gamma , 1.0 )
2009-04-17 06:10:45 +02:00
2011-11-23 12:33:58 +01:00
s = mapnik . Stroke ( mapnik . Color ( ' blue ' ) , 5.0 )
2011-02-02 02:46:14 +01:00
s . gamma = .5
2009-04-17 06:10:45 +02:00
eq_ ( s . width , 5 )
eq_ ( s . opacity , 1 )
2011-11-23 12:33:58 +01:00
eq_ ( s . color , mapnik . Color ( ' blue ' ) )
2011-02-02 02:46:14 +01:00
eq_ ( s . gamma , .5 )
2011-11-23 12:33:58 +01:00
eq_ ( s . line_cap , mapnik . line_cap . BUTT_CAP )
eq_ ( s . line_join , mapnik . line_join . MITER_JOIN )
2009-04-17 06:10:45 +02:00
2009-05-24 06:14:35 +02:00
def test_stroke_dash_arrays ( ) :
2011-11-23 12:33:58 +01:00
s = mapnik . 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-16 19:22:38 +02:00
def test_map_init ( ) :
2011-11-23 12:33:58 +01:00
m = mapnik . Map ( 256 , 256 )
2012-02-24 22:13:56 +01:00
2009-04-16 19:22:38 +02:00
eq_ ( m . width , 256 )
eq_ ( m . height , 256 )
2010-08-10 20:18:31 +02:00
eq_ ( m . srs , ' +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ' )
2011-05-26 01:51:08 +02:00
eq_ ( m . base , ' ' )
2012-04-04 21:07:15 +02:00
eq_ ( m . maximum_extent , None )
2013-07-25 07:00:38 +02:00
eq_ ( m . background_image , None )
eq_ ( m . background_image_comp_op , mapnik . CompositeOp . src_over )
eq_ ( m . background_image_opacity , 1.0 )
2009-04-16 19:22:38 +02:00
2011-11-23 12:33:58 +01:00
m = mapnik . Map ( 256 , 256 , ' +proj=latlong ' )
2009-04-16 19:22:38 +02:00
eq_ ( m . srs , ' +proj=latlong ' )
2013-02-22 22:39:14 +01:00
def test_map_style_access ( ) :
m = mapnik . Map ( 256 , 256 )
sty = mapnik . Style ( )
m . append_style ( " style " , sty )
styles = list ( m . styles )
eq_ ( len ( styles ) , 1 )
eq_ ( styles [ 0 ] [ 0 ] , ' style ' )
# returns a copy so let's just check it is the right instance
eq_ ( isinstance ( styles [ 0 ] [ 1 ] , mapnik . Style ) , True )
2012-04-04 21:07:15 +02:00
def test_map_maximum_extent_modification ( ) :
m = mapnik . Map ( 256 , 256 )
eq_ ( m . maximum_extent , None )
m . maximum_extent = mapnik . Box2d ( )
eq_ ( m . maximum_extent , mapnik . Box2d ( ) )
m . maximum_extent = None
eq_ ( m . maximum_extent , None )
2009-04-16 19:22:38 +02:00
# Map initialization from string
def test_map_init_from_string ( ) :
2011-05-26 01:51:08 +02:00
map_string = ''' <Map background-color= " steelblue " base= " ./ " srs= " +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs " >
2009-04-16 19:22:38 +02:00
< Style name = " My Style " >
< Rule >
2012-03-13 15:42:33 +01:00
< PolygonSymbolizer fill = " #f2eff9 " / >
< LineSymbolizer stroke = " rgb(50 % ,50 % ,50 % ) " stroke - width = " 0.1 " / >
2009-04-16 19:22:38 +02:00
< / 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 > '''
2011-11-23 12:33:58 +01:00
m = mapnik . Map ( 600 , 300 )
2011-05-26 01:51:08 +02:00
eq_ ( m . base , ' ' )
try :
2011-11-23 12:33:58 +01:00
mapnik . load_map_from_string ( m , map_string )
2011-10-29 02:06:23 +02:00
eq_ ( m . base , ' ./ ' )
2011-11-23 12:33:58 +01:00
mapnik . load_map_from_string ( m , map_string , False , " " ) # this "" will have no effect
2011-10-29 02:06:23 +02:00
eq_ ( m . base , ' ./ ' )
2012-02-24 22:13:56 +01:00
2011-11-30 03:15:25 +01:00
tmp_dir = tempfile . gettempdir ( )
2011-10-29 02:06:23 +02:00
try :
2011-11-30 03:15:25 +01:00
mapnik . load_map_from_string ( m , map_string , False , tmp_dir )
2011-10-29 02:06:23 +02:00
except RuntimeError :
pass # runtime error expected because shapefile path should be wrong and datasource will throw
2011-11-30 03:15:25 +01:00
eq_ ( m . base , tmp_dir ) # tmp_dir will be set despite the exception because load_map mostly worked
2011-10-29 02:06:23 +02:00
m . base = ' foo '
2011-11-23 12:33:58 +01:00
mapnik . load_map_from_string ( m , map_string , True , " . " )
2011-10-29 02:06:23 +02:00
eq_ ( m . base , ' . ' )
except RuntimeError , e :
# only test datasources that we have installed
if not ' Could not create datasource ' in str ( e ) :
raise RuntimeError ( e )
2009-04-16 19:22:38 +02:00
# Color initialization
2011-07-06 01:01:51 +02:00
@raises ( Exception ) # Boost.Python.ArgumentError
def test_color_init_errors ( ) :
2011-11-23 12:33:58 +01:00
c = mapnik . Color ( )
2011-07-06 01:01:51 +02:00
@raises ( RuntimeError )
def test_color_init_errors ( ) :
2012-08-07 12:36:44 +02:00
c = mapnik . Color ( ' foo ' ) # mapnik config
2011-07-06 01:01:51 +02:00
2009-04-16 19:22:38 +02:00
def test_color_init ( ) :
2011-11-23 12:33:58 +01:00
c = mapnik . 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 ' )
2011-11-23 12:33:58 +01:00
c = mapnik . Color ( ' #f2eff9 ' )
2012-02-24 22:13:56 +01:00
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 ' )
2011-11-23 12:33:58 +01:00
c = mapnik . 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 ' )
2011-11-23 12:33:58 +01:00
c = mapnik . 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 ' )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
c = mapnik . 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 )
2011-06-07 21:50:30 +02:00
eq_ ( c . to_hex_string ( ) , ' #004080c0 ' )
2009-04-16 19:22:38 +02:00
2009-04-17 06:10:45 +02:00
def test_color_equality ( ) :
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
c1 = mapnik . Color ( ' blue ' )
c2 = mapnik . Color ( 0 , 0 , 255 )
c3 = mapnik . Color ( ' black ' )
2012-02-24 22:13:56 +01:00
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 )
2011-11-23 12:33:58 +01:00
c1 = mapnik . Color ( 0 , 64 , 128 )
c2 = mapnik . Color ( 0 , 64 , 128 )
c3 = mapnik . Color ( 0 , 0 , 0 )
2012-02-24 22:13:56 +01:00
2009-04-17 06:10:45 +02:00
c3 . r = 0
c3 . g = 64
c3 . b = 128
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2011-11-23 12:33:58 +01:00
c1 = mapnik . Color ( 0 , 64 , 128 , 192 )
c2 = mapnik . Color ( 0 , 64 , 128 , 192 )
c3 = mapnik . 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 )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
c1 = mapnik . Color ( ' rgb(50 % ,50 % ,50 % ) ' )
c2 = mapnik . Color ( 128 , 128 , 128 , 255 )
c3 = mapnik . Color ( ' #808080 ' )
c4 = mapnik . Color ( ' gray ' )
2012-02-24 22:13:56 +01:00
2009-04-17 06:10:45 +02:00
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
eq_ ( c1 , c4 )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
c1 = mapnik . Color ( ' hsl(0, 100 % , 50 % ) ' ) # red
c2 = mapnik . Color ( ' hsl(120, 100 % , 50 % ) ' ) # lime
c3 = mapnik . Color ( ' hsla(240, 100 % , 50 % , 0.5) ' ) # semi-transparent solid blue
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
eq_ ( c1 , mapnik . Color ( ' red ' ) )
eq_ ( c2 , mapnik . Color ( ' lime ' ) )
eq_ ( c3 , mapnik . Color ( 0 , 0 , 255 , 128 ) )
2009-04-16 19:22:38 +02:00
2009-04-16 01:06:18 +02:00
def test_rule_init ( ) :
min_scale = 5
max_scale = 10
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
r = mapnik . Rule ( )
2012-02-24 22:13:56 +01:00
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 19:38:27 +02:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
r = mapnik . Rule ( )
2012-02-24 22:13:56 +01:00
2011-08-30 19:38:27 +02:00
r . set_else ( True )
eq_ ( r . has_else ( ) , True )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
r = mapnik . Rule ( )
2012-02-24 22:13:56 +01:00
2011-08-30 19:38:27 +02:00
r . set_also ( True )
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , True )
2012-02-24 22:13:56 +01:00
2011-11-23 12:33:58 +01:00
r = mapnik . Rule ( " Name " )
2012-02-24 22:13:56 +01:00
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 19:38:27 +02:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-12-16 16:22:52 +01:00
r = mapnik . Rule ( " Name " )
2012-02-24 22:13:56 +01:00
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 19:38:27 +02:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-12-16 16:22:52 +01:00
r = mapnik . Rule ( " Name " , min_scale )
2012-02-24 22:13:56 +01:00
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 19:38:27 +02:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-12-16 16:22:52 +01:00
r = mapnik . Rule ( " Name " , min_scale , max_scale )
2012-02-24 22:13:56 +01:00
2009-04-16 01:06:18 +02:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , max_scale )
2011-08-30 19:38:27 +02:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 22:13:56 +01:00
2011-08-31 00:51:42 +02:00
if __name__ == " __main__ " :
setup ( )
2013-06-03 04:28:24 +02:00
run_all ( eval ( x ) for x in dir ( ) if x . startswith ( " test_ " ) )