From dc2ab8506fe6b826a5667a8a752a7e3c1fe06577 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 8 May 2013 20:13:20 -0700 Subject: [PATCH] Add test for image.fromstring - refs #1805 --- tests/python_tests/image_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/python_tests/image_test.py diff --git a/tests/python_tests/image_test.py b/tests/python_tests/image_test.py new file mode 100644 index 000000000..d83a41ac4 --- /dev/null +++ b/tests/python_tests/image_test.py @@ -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]