mapnik/tests/python_tests/pngsuite_test.py
Carl Simonson cd7ad3e15e Catch and throw PNG exceptions - fixes #1213
The png library uses setjmp/longjmp to throw exceptions when reading. If this
is not set up, the png library calls abort(). This change handles the errors
and throws a C++ exception instead.

This issue was found by testing images from pngsuite at
http://www.schaik.com/pngsuite/. These images are included and a unit test was
added to test both images that should be successful and images that should
throw an exception.
2012-06-06 17:52:41 -05:00

35 lines
905 B
Python

#!/usr/bin/env python
import os
import mapnik
from nose.tools import *
from utilities import execution_path
datadir = '../data/pngsuite'
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('.'))
def assert_broken_file(fname):
assert_raises(RuntimeError, lambda: mapnik.Image.open(fname))
def assert_good_file(fname):
assert mapnik.Image.open(fname)
def get_pngs(good):
files = [ x for x in os.listdir(datadir) if x.endswith('.png') ]
return [ os.path.join(datadir, x) for x in files if good != x.startswith('x') ]
def test_good_pngs():
for x in get_pngs(True):
yield assert_good_file, x
def test_broken_pngs():
for x in get_pngs(False):
yield assert_broken_file, x
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]