Add test for image.fromstring - refs #1805

This commit is contained in:
Dane Springmeyer 2013-05-08 20:13:20 -07:00 committed by artemp
parent 0fb7898e5e
commit dc2ab8506f

View file

@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os, mapnik
from timeit import Timer, time
from nose.tools import *
from utilities import execution_path
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 test_image_open_from_string():
filepath = '../data/images/dummy.png'
im1 = mapnik.Image.open(filepath)
im2 = mapnik.Image.fromstring(open(filepath,'rb').read())
eq_(im1.width(),im2.width())
length = len(im1.tostring())
eq_(length,len(im2.tostring()))
eq_(len(mapnik.Image.fromstring(im1.tostring('png')).tostring()),length)
eq_(len(mapnik.Image.fromstring(im1.tostring('jpeg')).tostring()),length)
eq_(len(mapnik.Image.fromstring(im1.tostring('tiff')).tostring()),length)
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]