2009-04-15 23:06:18 +00:00
#!/usr/bin/env python
2011-10-10 21:04:34 +00:00
# -*- coding: utf-8 -*-
2009-04-15 23:06:18 +00:00
2011-08-30 22:51:42 +00:00
import os
2009-04-15 23:06:18 +00:00
from nose . tools import *
2011-08-30 22:51:42 +00:00
from utilities import execution_path
2009-04-16 17:22:38 +00:00
from utilities import Todo
2011-11-30 02:15:25 +00:00
import tempfile
2009-04-15 23:06:18 +00:00
2011-12-02 23:21:35 +00:00
import mapnik
2009-04-15 23:06:18 +00:00
2011-08-30 22:51:42 +00: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 ( ' . ' ) )
2009-04-15 23:06:18 +00:00
# Tests that exercise the functionality of Mapnik classes.
2011-09-09 23:45:49 +00:00
# LineSymbolizer initialization
def test_line_symbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
s = mapnik . LineSymbolizer ( )
eq_ ( s . rasterizer , mapnik . line_rasterizer . FULL )
2011-09-09 23:45:49 +00:00
2009-04-17 04:10:45 +00:00
# ShieldSymbolizer initialization
def test_shieldsymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
s = mapnik . ShieldSymbolizer ( mapnik . Expression ( ' [Field Name] ' ) , ' DejaVu Sans Bold ' , 6 , mapnik . Color ( ' #000000 ' ) , mapnik . PathExpression ( ' ../data/images/dummy.png ' ) )
2010-12-11 01:21:46 +00:00
eq_ ( s . displacement , ( 0.0 , 0.0 ) )
2010-10-13 01:23:56 +00:00
eq_ ( s . allow_overlap , False )
2010-12-10 22:09:34 +00:00
eq_ ( s . avoid_edges , False )
eq_ ( s . character_spacing , 0 )
2012-01-19 23:45:15 +00:00
#eq_(str(s.name), str(mapnik2.Expression('[Field Name]'))) name field is no longer supported
2010-12-10 22:09:34 +00:00
eq_ ( s . face_name , ' DejaVu Sans Bold ' )
eq_ ( s . allow_overlap , False )
2011-11-23 11:33:58 +00:00
eq_ ( s . fill , mapnik . Color ( ' #000000 ' ) )
2010-12-10 22:09:34 +00:00
eq_ ( s . force_odd_labels , False )
2011-11-23 11:33:58 +00:00
eq_ ( s . halo_fill , mapnik . Color ( ' rgb(255,255,255) ' ) )
2010-12-10 22:09:34 +00:00
eq_ ( s . halo_radius , 0 )
2011-11-23 11:33:58 +00:00
eq_ ( s . label_placement , mapnik . label_placement . POINT_PLACEMENT )
2010-12-10 22:09:34 +00: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 18:37:13 +00:00
eq_ ( s . vertical_alignment , mapnik . vertical_alignment . AUTO )
2010-12-10 22:09:34 +00:00
eq_ ( s . label_spacing , 0 )
eq_ ( s . label_position_tolerance , 0 )
2011-05-04 05:24:57 +00:00
# 22.5 * M_PI/180.0 initialized by default
assert_almost_equal ( s . max_char_angle_delta , 0.39269908169872414 )
2012-02-24 21:13:56 +00:00
2010-12-10 22:09:34 +00:00
eq_ ( s . wrap_character , ' ' )
2011-11-23 11:33:58 +00:00
eq_ ( s . text_transform , mapnik . text_transform . NONE )
2010-12-10 22:09:34 +00:00
eq_ ( s . line_spacing , 0 )
eq_ ( s . character_spacing , 0 )
2012-02-24 21:13:56 +00:00
2010-10-13 01:23:56 +00:00
# r1341
2010-12-10 22:09:34 +00:00
eq_ ( s . wrap_before , False )
2012-01-28 18:37:13 +00:00
eq_ ( s . horizontal_alignment , mapnik . horizontal_alignment . AUTO )
2012-03-19 16:40:51 +00:00
eq_ ( s . justify_alignment , mapnik . justify_alignment . AUTO )
2010-12-10 22:09:34 +00:00
eq_ ( s . opacity , 1.0 )
2012-02-24 21:13:56 +00:00
2010-12-10 22:26:17 +00:00
# r2300
eq_ ( s . minimum_padding , 0.0 )
2012-02-24 21:13:56 +00:00
2010-12-10 22:26:17 +00:00
# was mixed with s.opacity
eq_ ( s . text_opacity , 1.0 )
2010-12-11 01:21:46 +00: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 ' )
2010-12-13 20:11:36 +00:00
eq_ ( s . transform , ' matrix(1, 0, 0, 1, 0, 0) ' )
2012-02-24 21:13:56 +00:00
2011-12-20 20:40:14 +00:00
eq_ ( len ( s . fontset . names ) , 0 )
2010-10-13 01:23:56 +00:00
2009-04-17 04:10:45 +00:00
# ShieldSymbolizer missing image file
2010-03-02 03:31:10 +00: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 11:33:58 +00:00
# s = mapnik.ShieldSymbolizer(mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../#data/images/broken.png'))
2009-04-17 04:10:45 +00:00
2011-02-01 19:53:03 +00:00
def test_polygonsymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
p = mapnik . PolygonSymbolizer ( )
2011-02-01 19:53:03 +00:00
2011-11-23 11:33:58 +00:00
eq_ ( p . fill , mapnik . Color ( ' gray ' ) )
2011-02-01 19:53:03 +00:00
eq_ ( p . fill_opacity , 1 )
2011-11-23 11:33:58 +00:00
eq_ ( p . placement , mapnik . point_placement . CENTROID )
2011-02-01 19:53:03 +00:00
2011-11-23 11:33:58 +00:00
p = mapnik . PolygonSymbolizer ( mapnik . Color ( ' blue ' ) )
p . placement = mapnik . point_placement . INTERIOR
2011-02-01 19:53:03 +00:00
2011-11-23 11:33:58 +00:00
eq_ ( p . fill , mapnik . Color ( ' blue ' ) )
2011-02-01 19:53:03 +00:00
eq_ ( p . fill_opacity , 1 )
2011-11-23 11:33:58 +00:00
eq_ ( p . placement , mapnik . point_placement . INTERIOR )
2011-02-01 19:53:03 +00:00
2009-04-17 04:10:45 +00:00
# PointSymbolizer initialization
def test_pointsymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
p = mapnik . PointSymbolizer ( )
2009-04-17 04:10:45 +00:00
eq_ ( p . allow_overlap , False )
2009-09-27 17:45:52 +00:00
eq_ ( p . opacity , 1 )
eq_ ( p . filename , ' ' )
2010-10-15 02:16:37 +00:00
eq_ ( p . ignore_placement , False )
2011-11-23 11:33:58 +00:00
eq_ ( p . placement , mapnik . point_placement . CENTROID )
2009-04-17 04:10:45 +00:00
2011-11-23 11:33:58 +00:00
p = mapnik . PointSymbolizer ( mapnik . PathExpression ( " ../data/images/dummy.png " ) )
2010-10-15 02:16:37 +00:00
p . allow_overlap = True
p . opacity = 0.5
p . ignore_placement = True
2011-11-23 11:33:58 +00:00
p . placement = mapnik . point_placement . INTERIOR
2010-10-15 02:16:37 +00:00
eq_ ( p . allow_overlap , True )
eq_ ( p . opacity , 0.5 )
2009-09-27 17:45:52 +00:00
eq_ ( p . filename , ' ../data/images/dummy.png ' )
2010-10-15 02:16:37 +00:00
eq_ ( p . ignore_placement , True )
2011-11-23 11:33:58 +00:00
eq_ ( p . placement , mapnik . point_placement . INTERIOR )
2009-04-17 04:10:45 +00:00
# PointSymbolizer missing image file
2010-03-02 03:31:10 +00: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 11:33:58 +00:00
# p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/broken.png"))
2009-04-17 04:10:45 +00:00
# PolygonSymbolizer initialization
def test_polygonsymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
p = mapnik . PolygonSymbolizer ( )
2009-04-17 04:10:45 +00:00
2011-11-23 11:33:58 +00:00
eq_ ( p . fill , mapnik . Color ( ' gray ' ) )
2009-04-17 04:10:45 +00:00
eq_ ( p . fill_opacity , 1 )
2011-11-23 11:33:58 +00:00
p = mapnik . PolygonSymbolizer ( mapnik . Color ( ' blue ' ) )
2009-04-17 04:10:45 +00:00
2011-11-23 11:33:58 +00:00
eq_ ( p . fill , mapnik . Color ( ' blue ' ) )
2009-04-17 04:10:45 +00:00
eq_ ( p . fill_opacity , 1 )
# Stroke initialization
def test_stroke_init ( ) :
2011-11-23 11:33:58 +00:00
s = mapnik . Stroke ( )
2009-04-17 04:10:45 +00:00
eq_ ( s . width , 1 )
eq_ ( s . opacity , 1 )
2011-11-23 11:33:58 +00: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 01:46:14 +00:00
eq_ ( s . gamma , 1.0 )
2009-04-17 04:10:45 +00:00
2011-11-23 11:33:58 +00:00
s = mapnik . Stroke ( mapnik . Color ( ' blue ' ) , 5.0 )
2011-02-02 01:46:14 +00:00
s . gamma = .5
2009-04-17 04:10:45 +00:00
eq_ ( s . width , 5 )
eq_ ( s . opacity , 1 )
2011-11-23 11:33:58 +00:00
eq_ ( s . color , mapnik . Color ( ' blue ' ) )
2011-02-02 01:46:14 +00:00
eq_ ( s . gamma , .5 )
2011-11-23 11:33:58 +00:00
eq_ ( s . line_cap , mapnik . line_cap . BUTT_CAP )
eq_ ( s . line_join , mapnik . line_join . MITER_JOIN )
2009-04-17 04:10:45 +00:00
2009-05-24 04:14:35 +00:00
# Stroke dashes
def test_stroke_dash_arrays ( ) :
2011-11-23 11:33:58 +00:00
s = mapnik . Stroke ( )
2009-05-24 04:14:35 +00: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 04:10:45 +00:00
# LineSymbolizer initialization
def test_linesymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
l = mapnik . LineSymbolizer ( )
2012-02-24 21:13:56 +00:00
2009-04-17 04:10:45 +00:00
eq_ ( l . stroke . width , 1 )
eq_ ( l . stroke . opacity , 1 )
2011-11-23 11:33:58 +00:00
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 )
2009-04-17 04:10:45 +00:00
2011-11-23 11:33:58 +00:00
l = mapnik . LineSymbolizer ( mapnik . Color ( ' blue ' ) , 5.0 )
2009-04-17 04:10:45 +00:00
eq_ ( l . stroke . width , 5 )
eq_ ( l . stroke . opacity , 1 )
2011-11-23 11:33:58 +00:00
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 )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
s = mapnik . Stroke ( mapnik . Color ( ' blue ' ) , 5.0 )
l = mapnik . LineSymbolizer ( s )
2012-02-24 21:13:56 +00:00
2009-04-17 04:10:45 +00:00
eq_ ( l . stroke . width , 5 )
eq_ ( l . stroke . opacity , 1 )
2011-11-23 11:33:58 +00:00
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 )
2009-04-17 04:10:45 +00:00
2009-04-16 17:22:38 +00:00
# TextSymbolizer initialization
def test_textsymbolizer_init ( ) :
2011-11-23 11:33:58 +00:00
ts = mapnik . TextSymbolizer ( mapnik . Expression ( ' [Field_Name] ' ) , ' Font Name ' , 8 , mapnik . Color ( ' black ' ) )
2009-04-16 17:22:38 +00:00
2012-01-19 23:45:15 +00:00
# eq_(str(ts.name), str(mapnik2.Expression('[Field_Name]'))) name field is no longer supported
2012-02-21 08:52:14 +00:00
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 )
2009-04-16 17:22:38 +00:00
2011-03-02 15:17:55 +00:00
# Map initialization
def test_layer_init ( ) :
2011-11-23 11:33:58 +00:00
l = mapnik . Layer ( ' test ' )
2011-03-02 15:17:55 +00:00
eq_ ( l . name , ' test ' )
2011-11-23 11:33:58 +00:00
eq_ ( l . envelope ( ) , mapnik . Box2d ( ) )
2011-03-02 15:17:55 +00:00
eq_ ( l . clear_label_cache , False )
eq_ ( l . cache_features , False )
2011-04-14 21:01:37 +00:00
eq_ ( l . visible ( 1 ) , True )
2011-03-02 15:17:55 +00:00
eq_ ( l . active , True )
eq_ ( l . datasource , None )
eq_ ( l . queryable , False )
eq_ ( l . srs , ' +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ' )
2009-04-16 17:22:38 +00:00
# Map initialization
def test_map_init ( ) :
2011-11-23 11:33:58 +00:00
m = mapnik . Map ( 256 , 256 )
2012-02-24 21:13:56 +00:00
2009-04-16 17:22:38 +00:00
eq_ ( m . width , 256 )
eq_ ( m . height , 256 )
2010-08-10 18:18:31 +00:00
eq_ ( m . srs , ' +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ' )
2011-05-25 23:51:08 +00:00
eq_ ( m . base , ' ' )
2009-04-16 17:22:38 +00:00
2011-11-23 11:33:58 +00:00
m = mapnik . Map ( 256 , 256 , ' +proj=latlong ' )
2009-04-16 17:22:38 +00:00
eq_ ( m . srs , ' +proj=latlong ' )
# Map initialization from string
def test_map_init_from_string ( ) :
2011-05-25 23:51:08 +00:00
map_string = ''' <Map background-color= " steelblue " base= " ./ " srs= " +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs " >
2009-04-16 17:22:38 +00:00
< Style name = " My Style " >
< Rule >
2012-03-13 14:42:33 +00:00
< PolygonSymbolizer fill = " #f2eff9 " / >
< LineSymbolizer stroke = " rgb(50 % ,50 % ,50 % ) " stroke - width = " 0.1 " / >
2009-04-16 17:22:38 +00: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 11:33:58 +00:00
m = mapnik . Map ( 600 , 300 )
2011-05-25 23:51:08 +00:00
eq_ ( m . base , ' ' )
try :
2011-11-23 11:33:58 +00:00
mapnik . load_map_from_string ( m , map_string )
2011-10-29 00:06:23 +00:00
eq_ ( m . base , ' ./ ' )
2011-11-23 11:33:58 +00:00
mapnik . load_map_from_string ( m , map_string , False , " " ) # this "" will have no effect
2011-10-29 00:06:23 +00:00
eq_ ( m . base , ' ./ ' )
2012-02-24 21:13:56 +00:00
2011-11-30 02:15:25 +00:00
tmp_dir = tempfile . gettempdir ( )
2011-10-29 00:06:23 +00:00
try :
2011-11-30 02:15:25 +00:00
mapnik . load_map_from_string ( m , map_string , False , tmp_dir )
2011-10-29 00:06:23 +00:00
except RuntimeError :
pass # runtime error expected because shapefile path should be wrong and datasource will throw
2011-11-30 02:15:25 +00:00
eq_ ( m . base , tmp_dir ) # tmp_dir will be set despite the exception because load_map mostly worked
2011-10-29 00:06:23 +00:00
m . base = ' foo '
2011-11-23 11:33:58 +00:00
mapnik . load_map_from_string ( m , map_string , True , " . " )
2011-10-29 00:06:23 +00:00
eq_ ( m . base , ' . ' )
raise ( Todo ( " Need to write more map property tests in ' object_test.py ' ... " ) )
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 17:22:38 +00:00
# Color initialization
2011-07-05 23:01:51 +00:00
@raises ( Exception ) # Boost.Python.ArgumentError
def test_color_init_errors ( ) :
2011-11-23 11:33:58 +00:00
c = mapnik . Color ( )
2011-07-05 23:01:51 +00:00
@raises ( RuntimeError )
def test_color_init_errors ( ) :
2011-11-23 11:33:58 +00:00
c = mapnik . Color ( ' foo ' ) # mapnik config
2011-07-05 23:01:51 +00:00
2009-04-16 17:22:38 +00:00
def test_color_init ( ) :
2011-11-23 11:33:58 +00:00
c = mapnik . Color ( ' blue ' )
2009-04-16 17:22:38 +00: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 11:33:58 +00:00
c = mapnik . Color ( ' #f2eff9 ' )
2012-02-24 21:13:56 +00:00
2009-04-17 04:10:45 +00: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 11:33:58 +00:00
c = mapnik . Color ( ' rgb(50 % ,50 % ,50 % ) ' )
2009-04-17 04:10:45 +00: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 11:33:58 +00:00
c = mapnik . Color ( 0 , 64 , 128 )
2009-04-16 17:22:38 +00: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 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
c = mapnik . Color ( 0 , 64 , 128 , 192 )
2009-04-16 17:22:38 +00:00
eq_ ( c . a , 192 )
eq_ ( c . r , 0 )
eq_ ( c . g , 64 )
eq_ ( c . b , 128 )
2011-06-07 19:50:30 +00:00
eq_ ( c . to_hex_string ( ) , ' #004080c0 ' )
2009-04-16 17:22:38 +00:00
2009-04-17 04:10:45 +00:00
# Color equality
def test_color_equality ( ) :
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
c1 = mapnik . Color ( ' blue ' )
c2 = mapnik . Color ( 0 , 0 , 255 )
c3 = mapnik . Color ( ' black ' )
2012-02-24 21:13:56 +00:00
2009-04-17 04:10:45 +00:00
c3 . r = 0
c3 . g = 0
c3 . b = 255
c3 . a = 255
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2011-11-23 11:33:58 +00:00
c1 = mapnik . Color ( 0 , 64 , 128 )
c2 = mapnik . Color ( 0 , 64 , 128 )
c3 = mapnik . Color ( 0 , 0 , 0 )
2012-02-24 21:13:56 +00:00
2009-04-17 04:10:45 +00:00
c3 . r = 0
c3 . g = 64
c3 . b = 128
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2011-11-23 11:33:58 +00: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 04:10:45 +00:00
c3 . r = 0
c3 . g = 64
c3 . b = 128
c3 . a = 192
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00: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 21:13:56 +00:00
2009-04-17 04:10:45 +00:00
eq_ ( c1 , c2 )
eq_ ( c1 , c3 )
eq_ ( c1 , c4 )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00: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 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
eq_ ( c1 , mapnik . Color ( ' red ' ) )
eq_ ( c2 , mapnik . Color ( ' lime ' ) )
eq_ ( c3 , mapnik . Color ( 0 , 0 , 255 , 128 ) )
2009-04-16 17:22:38 +00:00
2009-04-15 23:06:18 +00:00
# Rule initialization
def test_rule_init ( ) :
min_scale = 5
max_scale = 10
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
r = mapnik . Rule ( )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
eq_ ( r . name , ' ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 17:38:27 +00:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
r = mapnik . Rule ( )
2012-02-24 21:13:56 +00:00
2011-08-30 17:38:27 +00:00
r . set_else ( True )
eq_ ( r . has_else ( ) , True )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
r = mapnik . Rule ( )
2012-02-24 21:13:56 +00:00
2011-08-30 17:38:27 +00:00
r . set_also ( True )
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , True )
2012-02-24 21:13:56 +00:00
2011-11-23 11:33:58 +00:00
r = mapnik . Rule ( " Name " )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 17:38:27 +00:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2011-12-16 15:22:52 +00:00
r = mapnik . Rule ( " Name " )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , 0 )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 17:38:27 +00:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2011-12-16 15:22:52 +00:00
r = mapnik . Rule ( " Name " , min_scale )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , float ( ' inf ' ) )
2011-08-30 17:38:27 +00:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2011-12-16 15:22:52 +00:00
r = mapnik . Rule ( " Name " , min_scale , max_scale )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
eq_ ( r . name , ' Name ' )
eq_ ( r . min_scale , min_scale )
eq_ ( r . max_scale , max_scale )
2011-08-30 17:38:27 +00:00
eq_ ( r . has_else ( ) , False )
eq_ ( r . has_also ( ) , False )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
# Coordinate initialization
def test_coord_init ( ) :
2011-11-23 11:33:58 +00:00
c = mapnik . Coord ( 100 , 100 )
2009-04-15 23:06:18 +00:00
eq_ ( c . x , 100 )
eq_ ( c . y , 100 )
# Coordinate multiplication
def test_coord_multiplication ( ) :
2011-11-23 11:33:58 +00:00
c = mapnik . Coord ( 100 , 100 )
2009-04-15 23:06:18 +00:00
c * = 2
eq_ ( c . x , 200 )
eq_ ( c . y , 200 )
2009-12-16 20:02:06 +00:00
# Box2d initialization
2009-04-15 23:06:18 +00:00
def test_envelope_init ( ) :
2011-11-23 11:33:58 +00:00
e = mapnik . Box2d ( 100 , 100 , 200 , 200 )
2009-04-15 23:06:18 +00: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 ( ) ) )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
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 )
2012-02-24 21:13:56 +00:00
2010-11-15 03:27:04 +00:00
eq_ ( e [ 0 ] , 100 )
eq_ ( e [ 1 ] , 100 )
eq_ ( e [ 2 ] , 200 )
eq_ ( e [ 3 ] , 200 )
eq_ ( e [ 0 ] , e [ - 4 ] )
eq_ ( e [ 1 ] , e [ - 3 ] )
eq_ ( e [ 2 ] , e [ - 2 ] )
eq_ ( e [ 3 ] , e [ - 1 ] )
2012-02-24 21:13:56 +00:00
2010-11-15 03:27:04 +00:00
c = e . center ( )
eq_ ( c . x , 150 )
eq_ ( c . y , 150 )
# Box2d static initialization
def test_envelope_static_init ( ) :
2011-11-23 11:33:58 +00:00
e = mapnik . Box2d . from_string ( ' 100 100 200 200 ' )
e2 = mapnik . Box2d . from_string ( ' 100,100,200,200 ' )
e3 = mapnik . Box2d . from_string ( ' 100 , 100 , 200 , 200 ' )
2010-11-15 03:27:04 +00:00
eq_ ( e , e2 )
eq_ ( e , e3 )
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 ( ) ) )
2012-02-24 21:13:56 +00:00
2010-11-15 03:27:04 +00:00
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 )
2012-02-24 21:13:56 +00:00
2010-09-16 14:41:29 +00:00
eq_ ( e [ 0 ] , 100 )
eq_ ( e [ 1 ] , 100 )
eq_ ( e [ 2 ] , 200 )
eq_ ( e [ 3 ] , 200 )
eq_ ( e [ 0 ] , e [ - 4 ] )
eq_ ( e [ 1 ] , e [ - 3 ] )
eq_ ( e [ 2 ] , e [ - 2 ] )
eq_ ( e [ 3 ] , e [ - 1 ] )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
c = e . center ( )
eq_ ( c . x , 150 )
eq_ ( c . y , 150 )
2009-12-16 20:02:06 +00:00
# Box2d multiplication
2009-04-15 23:06:18 +00:00
def test_envelope_multiplication ( ) :
2011-11-23 11:33:58 +00:00
e = mapnik . Box2d ( 100 , 100 , 200 , 200 )
2009-04-15 23:06:18 +00:00
e * = 2
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
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 ( ) ) )
2012-02-24 21:13:56 +00:00
2009-04-15 23:06:18 +00:00
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 )
2011-04-13 19:19:23 +00:00
# Box2d clipping
2011-12-02 23:21:35 +00:00
def test_envelope_clipping ( ) :
2011-11-23 11:33:58 +00:00
e1 = mapnik . Box2d ( - 180 , - 90 , 180 , 90 )
e2 = mapnik . Box2d ( - 120 , 40 , - 110 , 48 )
2011-04-13 19:19:23 +00:00
e1 . clip ( e2 )
eq_ ( e1 , e2 )
2012-02-24 21:13:56 +00:00
2011-04-13 19:19:23 +00:00
# madagascar in merc
2011-11-23 11:33:58 +00:00
e1 = mapnik . Box2d ( 4772116.5490 , - 2744395.0631 , 5765186.4203 , - 1609458.0673 )
e2 = mapnik . Box2d ( 5124338.3753 , - 2240522.1727 , 5207501.8621 , - 2130452.8520 )
2011-04-13 19:19:23 +00:00
e1 . clip ( e2 )
eq_ ( e1 , e2 )
2012-02-24 21:13:56 +00:00
2011-04-13 19:19:23 +00:00
# nz in lon/lat
2011-11-23 11:33:58 +00:00
e1 = mapnik . Box2d ( 163.8062 , - 47.1897 , 179.3628 , - 33.9069 )
e2 = mapnik . Box2d ( 173.7378 , - 39.6395 , 174.4849 , - 38.9252 )
2011-04-13 19:19:23 +00:00
e1 . clip ( e2 )
eq_ ( e1 , e2 )
2011-08-30 22:51:42 +00:00
if __name__ == " __main__ " :
setup ( )
[ eval ( run ) ( ) for run in dir ( ) if ' test_ ' in run ]