1- #!/usr/bin/env python
2- # -*- coding: utf-8 -*-
3-
41import os
5-
6- from nose .tools import eq_
7-
82import mapnik
3+ import pytest
4+ from .utilities import execution_path
95
10- from .utilities import execution_path , run_all
11-
12-
6+ @pytest .fixture (scope = "module" )
137def setup ():
148 # All of the paths used are relative, if we run the tests
159 # from another directory we need to chdir()
@@ -47,7 +41,7 @@ def gen_filepath(name, format):
4741
4842 generate = os .environ .get ('UPDATE' )
4943
50- def test_expected_encodings ():
44+ def test_expected_encodings (setup ):
5145 # blank image
5246 im = mapnik .Image (256 , 256 )
5347 for opt in opts :
@@ -58,9 +52,7 @@ def test_expected_encodings():
5852 im .save (expected , opt )
5953 else :
6054 im .save (actual , opt )
61- eq_ (mapnik .Image .open (actual ).tostring ('png32' ),
62- mapnik .Image .open (expected ).tostring ('png32' ),
63- '%s (actual) not == to %s (expected)' % (actual , expected ))
55+ assert mapnik .Image .open (actual ).tostring ('png32' ) == mapnik .Image .open (expected ).tostring ('png32' ), '%s (actual) not == to %s (expected)' % (actual , expected )
6456
6557 # solid image
6658 im .fill (mapnik .Color ('green' ))
@@ -72,9 +64,7 @@ def test_expected_encodings():
7264 im .save (expected , opt )
7365 else :
7466 im .save (actual , opt )
75- eq_ (mapnik .Image .open (actual ).tostring ('png32' ),
76- mapnik .Image .open (expected ).tostring ('png32' ),
77- '%s (actual) not == to %s (expected)' % (actual , expected ))
67+ assert mapnik .Image .open (actual ).tostring ('png32' ) == mapnik .Image .open (expected ).tostring ('png32' ), '%s (actual) not == to %s (expected)' % (actual , expected )
7868
7969 # aerial
8070 im = mapnik .Image .open ('./images/support/transparency/aerial_rgba.png' )
@@ -86,9 +76,7 @@ def test_expected_encodings():
8676 im .save (expected , opt )
8777 else :
8878 im .save (actual , opt )
89- eq_ (mapnik .Image .open (actual ).tostring ('png32' ),
90- mapnik .Image .open (expected ).tostring ('png32' ),
91- '%s (actual) not == to %s (expected)' % (actual , expected ))
79+ assert mapnik .Image .open (actual ).tostring ('png32' ) == mapnik .Image .open (expected ).tostring ('png32' ), '%s (actual) not == to %s (expected)' % (actual , expected )
9280
9381 def test_transparency_levels ():
9482 # create partial transparency image
@@ -112,121 +100,95 @@ def test_transparency_levels():
112100 im .save (t0 , format )
113101 im_in = mapnik .Image .open (t0 )
114102 t0_len = len (im_in .tostring (format ))
115- eq_ (t0_len , len (mapnik .Image .open (
116- 'images/support/transparency/white0.png' ).tostring (format )))
103+ assert t0_len == len (mapnik .Image .open ('images/support/transparency/white0.png' ).tostring (format ))
117104 format = 'png8:m=o:t=1'
118105 im .save (t1 , format )
119106 im_in = mapnik .Image .open (t1 )
120107 t1_len = len (im_in .tostring (format ))
121- eq_ (len (im .tostring (format )), len (mapnik .Image .open (
122- 'images/support/transparency/white1.png' ).tostring (format )))
108+ assert len (im .tostring (format )) == len (mapnik .Image .open ('images/support/transparency/white1.png' ).tostring (format ))
123109 format = 'png8:m=o:t=2'
124110 im .save (t2 , format )
125111 im_in = mapnik .Image .open (t2 )
126112 t2_len = len (im_in .tostring (format ))
127- eq_ (len (im .tostring (format )), len (mapnik .Image .open (
128- 'images/support/transparency/white2.png' ).tostring (format )))
129-
130- eq_ (t0_len < t1_len < t2_len , True )
113+ assert len (im .tostring (format )) == len (mapnik .Image .open ('images/support/transparency/white2.png' ).tostring (format ))
114+ assert t0_len < t1_len < t2_len
131115
132116 # hextree
133117 format = 'png8:m=h:t=0'
134118 im .save (t0 , format )
135119 im_in = mapnik .Image .open (t0 )
136120 t0_len = len (im_in .tostring (format ))
137- eq_ (t0_len , len (mapnik .Image .open (
138- 'images/support/transparency/white0.png' ).tostring (format )))
121+ assert t0_len == len (mapnik .Image .open ('images/support/transparency/white0.png' ).tostring (format ))
139122 format = 'png8:m=h:t=1'
140123 im .save (t1 , format )
141124 im_in = mapnik .Image .open (t1 )
142125 t1_len = len (im_in .tostring (format ))
143- eq_ (len (im .tostring (format )), len (mapnik .Image .open (
144- 'images/support/transparency/white1.png' ).tostring (format )))
126+ assert len (im .tostring (format )) == len (mapnik .Image .open ('images/support/transparency/white1.png' ).tostring (format ))
145127 format = 'png8:m=h:t=2'
146128 im .save (t2 , format )
147129 im_in = mapnik .Image .open (t2 )
148130 t2_len = len (im_in .tostring (format ))
149- eq_ (len (im .tostring (format )), len (mapnik .Image .open (
150- 'images/support/transparency/white2.png' ).tostring (format )))
151-
152- eq_ (t0_len < t1_len < t2_len , True )
131+ assert len (im .tostring (format )) == len (mapnik .Image .open ('images/support/transparency/white2.png' ).tostring (format ))
132+ assert t0_len < t1_len < t2_len
153133
154134 def test_transparency_levels_aerial ():
155135 im = mapnik .Image .open ('../data/images/12_654_1580.png' )
156136 im_in = mapnik .Image .open (
157137 './images/support/transparency/aerial_rgba.png' )
158- eq_ ( len (im .tostring ('png8' )), len (im_in .tostring ('png8' ) ))
159- eq_ ( len (im .tostring ('png32' )), len (im_in .tostring ('png32' ) ))
138+ assert len (im .tostring ('png8' )) == len (im_in .tostring ('png8' ))
139+ assert len (im .tostring ('png32' )) == len (im_in .tostring ('png32' ))
160140
161141 im_in = mapnik .Image .open (
162142 './images/support/transparency/aerial_rgb.png' )
163- eq_ ( len (im .tostring ('png32' )), len (im_in .tostring ('png32' ) ))
164- eq_ ( len (im .tostring ('png32:t=0' )), len (im_in .tostring ('png32:t=0' ) ))
165- eq_ ( len (im .tostring ('png32:t=0' )) == len (im_in .tostring ('png32' )), False )
166- eq_ ( len (im .tostring ('png8' )), len (im_in .tostring ('png8' ) ))
167- eq_ ( len (im .tostring ('png8:t=0' )), len (im_in .tostring ('png8:t=0' ) ))
143+ assert len (im .tostring ('png32' )) == len (im_in .tostring ('png32' ))
144+ assert len (im .tostring ('png32:t=0' )) == len (im_in .tostring ('png32:t=0' ))
145+ assert not len (im .tostring ('png32:t=0' )) == len (im_in .tostring ('png32' ))
146+ assert len (im .tostring ('png8' )) == len (im_in .tostring ('png8' ))
147+ assert len (im .tostring ('png8:t=0' )) == len (im_in .tostring ('png8:t=0' ))
168148 # unlike png32 paletted images without alpha will look the same even if
169149 # no alpha is forced
170- eq_ (len (im .tostring ('png8:t=0' )) == len (im_in .tostring ('png8' )), True )
171- eq_ (len (im .tostring ('png8:t=0:m=o' )) ==
172- len (im_in .tostring ('png8:m=o' )), True )
150+ assert len (im .tostring ('png8:t=0' )) == len (im_in .tostring ('png8' ))
151+ assert len (im .tostring ('png8:t=0:m=o' )) == len (im_in .tostring ('png8:m=o' ))
173152
174153 def test_9_colors_hextree ():
175154 expected = './images/support/encoding-opts/png8-9cols.png'
176155 im = mapnik .Image .open (expected )
177156 t0 = tmp_dir + 'png-encoding-9-colors.result-hextree.png'
178157 im .save (t0 , 'png8:m=h' )
179- eq_ (mapnik .Image .open (t0 ).tostring (),
180- mapnik .Image .open (expected ).tostring (),
181- '%s (actual) not == to %s (expected)' % (t0 , expected ))
158+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
182159
183160 def test_9_colors_octree ():
184161 expected = './images/support/encoding-opts/png8-9cols.png'
185162 im = mapnik .Image .open (expected )
186163 t0 = tmp_dir + 'png-encoding-9-colors.result-octree.png'
187164 im .save (t0 , 'png8:m=o' )
188- eq_ (mapnik .Image .open (t0 ).tostring (),
189- mapnik .Image .open (expected ).tostring (),
190- '%s (actual) not == to %s (expected)' % (t0 , expected ))
165+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
191166
192167 def test_17_colors_hextree ():
193168 expected = './images/support/encoding-opts/png8-17cols.png'
194169 im = mapnik .Image .open (expected )
195170 t0 = tmp_dir + 'png-encoding-17-colors.result-hextree.png'
196171 im .save (t0 , 'png8:m=h' )
197- eq_ (mapnik .Image .open (t0 ).tostring (),
198- mapnik .Image .open (expected ).tostring (),
199- '%s (actual) not == to %s (expected)' % (t0 , expected ))
172+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
200173
201174 def test_17_colors_octree ():
202175 expected = './images/support/encoding-opts/png8-17cols.png'
203176 im = mapnik .Image .open (expected )
204177 t0 = tmp_dir + 'png-encoding-17-colors.result-octree.png'
205178 im .save (t0 , 'png8:m=o' )
206- eq_ (mapnik .Image .open (t0 ).tostring (),
207- mapnik .Image .open (expected ).tostring (),
208- '%s (actual) not == to %s (expected)' % (t0 , expected ))
179+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
209180
210181 def test_2px_regression_hextree ():
211182 im = mapnik .Image .open ('./images/support/encoding-opts/png8-2px.A.png' )
212183 expected = './images/support/encoding-opts/png8-2px.png'
213184
214185 t0 = tmp_dir + 'png-encoding-2px.result-hextree.png'
215186 im .save (t0 , 'png8:m=h' )
216- eq_ (mapnik .Image .open (t0 ).tostring (),
217- mapnik .Image .open (expected ).tostring (),
218- '%s (actual) not == to %s (expected)' % (t0 , expected ))
187+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
219188
220189 def test_2px_regression_octree ():
221190 im = mapnik .Image .open ('./images/support/encoding-opts/png8-2px.A.png' )
222191 expected = './images/support/encoding-opts/png8-2px.png'
223192 t0 = tmp_dir + 'png-encoding-2px.result-octree.png'
224193 im .save (t0 , 'png8:m=o' )
225- eq_ (mapnik .Image .open (t0 ).tostring (),
226- mapnik .Image .open (expected ).tostring (),
227- '%s (actual) not == to %s (expected)' % (t0 , expected ))
228-
229-
230- if __name__ == "__main__" :
231- setup ()
232- exit (run_all (eval (x ) for x in dir () if x .startswith ("test_" )))
194+ assert mapnik .Image .open (t0 ).tostring () == mapnik .Image .open (expected ).tostring (), '%s (actual) not == to %s (expected)' % (t0 , expected )
0 commit comments