Adding tests for common mapnik classes.

This commit is contained in:
Beau Gunderson 2009-04-15 23:06:18 +00:00
parent 3c13918ce8
commit 4b60da2fec
4 changed files with 127 additions and 3 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path

View file

@ -0,0 +1,123 @@
#!/usr/bin/env python
from nose.tools import *
import mapnik
# Tests that exercise the functionality of Mapnik classes.
# Rule initialization
def test_rule_init():
min_scale = 5
max_scale = 10
r = mapnik.Rule()
eq_(r.name, '')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
r = mapnik.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")
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)
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)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, max_scale)
# Coordinate initialization
def test_coord_init():
c = mapnik.Coord(100, 100)
eq_(c.x, 100)
eq_(c.y, 100)
# Coordinate multiplication
def test_coord_multiplication():
c = mapnik.Coord(100, 100)
c *= 2
eq_(c.x, 200)
eq_(c.y, 200)
# Envelope initialization
def test_envelope_init():
e = mapnik.Envelope(100, 100, 200, 200)
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)
# Envelope multiplication
def test_envelope_multiplication():
e = mapnik.Envelope(100, 100, 200, 200)
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)

View file

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path

View file

@ -28,7 +28,7 @@ def main():
elif o in ("-p", "--prefix"):
prefix = a
else:
assert False, "unhandled option"
assert False, "Unhandled option"
if quiet and verbose:
usage()
@ -55,6 +55,7 @@ def main():
argv.append('-v')
if verbose:
# 3 * '-v' gets us debugging information from nose
argv.append('-v')
argv.append('-v')