1- #!/usr/bin/env python
2- # -*- coding: utf-8 -*-
3-
4- import os
5-
6- from nose .tools import eq_
7-
81import mapnik
92
10- from .utilities import execution_path , run_all
11-
12-
13- def setup ():
14- # All of the paths used are relative, if we run the tests
15- # from another directory we need to chdir()
16- os .chdir (execution_path ('.' ))
17-
18-
193def test_image_16_8_simple ():
204 im = mapnik .Image (2 , 2 , mapnik .ImageType .gray16 )
215 im .set_pixel (0 , 0 , 256 )
226 im .set_pixel (0 , 1 , 999 )
237 im .set_pixel (1 , 0 , 5 )
248 im .set_pixel (1 , 1 , 2 )
259 im2 = im .copy (mapnik .ImageType .gray8 )
26- eq_ ( im2 .get_pixel (0 , 0 ), 255 )
27- eq_ ( im2 .get_pixel (0 , 1 ), 255 )
28- eq_ ( im2 .get_pixel (1 , 0 ), 5 )
29- eq_ ( im2 .get_pixel (1 , 1 ), 2 )
10+ assert im2 .get_pixel (0 , 0 ) == 255
11+ assert im2 .get_pixel (0 , 1 ) == 255
12+ assert im2 .get_pixel (1 , 0 ) == 5
13+ assert im2 .get_pixel (1 , 1 ) == 2
3014 # Cast back!
3115 im = im2 .copy (mapnik .ImageType .gray16 )
32- eq_ ( im .get_pixel (0 , 0 ), 255 )
33- eq_ ( im .get_pixel (0 , 1 ), 255 )
34- eq_ ( im .get_pixel (1 , 0 ), 5 )
35- eq_ ( im .get_pixel (1 , 1 ), 2 )
16+ assert im .get_pixel (0 , 0 ) == 255
17+ assert im .get_pixel (0 , 1 ) == 255
18+ assert im .get_pixel (1 , 0 ) == 5
19+ assert im .get_pixel (1 , 1 ) == 2
3620
3721
3822def test_image_32f_8_simple ():
@@ -42,20 +26,20 @@ def test_image_32f_8_simple():
4226 im .set_pixel (1 , 0 , 120.6 )
4327 im .set_pixel (1 , 1 , 360.2 )
4428 im2 = im .copy (mapnik .ImageType .gray8 )
45- eq_ ( im2 .get_pixel (0 , 0 ), 120 )
46- eq_ ( im2 .get_pixel (0 , 1 ), 0 )
47- eq_ ( im2 .get_pixel (1 , 0 ), 120 ) # Notice this is truncated!
48- eq_ ( im2 .get_pixel (1 , 1 ), 255 )
29+ assert im2 .get_pixel (0 , 0 ) == 120
30+ assert im2 .get_pixel (0 , 1 ) == 0
31+ assert im2 .get_pixel (1 , 0 ) == 120 # Notice this is truncated!
32+ assert im2 .get_pixel (1 , 1 ) == 255
4933
5034
5135def test_image_offset_and_scale ():
5236 im = mapnik .Image (2 , 2 , mapnik .ImageType .gray16 )
53- eq_ ( im .offset , 0.0 )
54- eq_ ( im .scaling , 1.0 )
37+ assert im .offset == 0.0
38+ assert im .scaling == 1.0
5539 im .offset = 1.0
5640 im .scaling = 2.0
57- eq_ ( im .offset , 1.0 )
58- eq_ ( im .scaling , 2.0 )
41+ assert im .offset == 1.0
42+ assert im .scaling == 2.0
5943
6044
6145def test_image_16_8_scale_and_offset ():
@@ -67,17 +51,17 @@ def test_image_16_8_scale_and_offset():
6751 offset = 255
6852 scaling = 3
6953 im2 = im .copy (mapnik .ImageType .gray8 , offset , scaling )
70- eq_ ( im2 .get_pixel (0 , 0 ), 0 )
71- eq_ ( im2 .get_pixel (0 , 1 ), 1 )
72- eq_ ( im2 .get_pixel (1 , 0 ), 255 )
73- eq_ ( im2 .get_pixel (1 , 1 ), 120 )
54+ assert im2 .get_pixel (0 , 0 ) == 0
55+ assert im2 .get_pixel (0 , 1 ) == 1
56+ assert im2 .get_pixel (1 , 0 ) == 255
57+ assert im2 .get_pixel (1 , 1 ) == 120
7458 # pixels will be a little off due to offsets in reverting!
7559 im3 = im2 .copy (mapnik .ImageType .gray16 )
76- eq_ ( im3 .get_pixel (0 , 0 ), 255 ) # Rounding error with ints
77- eq_ ( im3 .get_pixel (0 , 1 ), 258 ) # same
60+ assert im3 .get_pixel (0 , 0 ) == 255 # Rounding error with ints
61+ assert im3 .get_pixel (0 , 1 ) == 258 # same
7862 # The other one was way out of range for our scale/offset
79- eq_ ( im3 .get_pixel (1 , 0 ), 1020 )
80- eq_ ( im3 .get_pixel (1 , 1 ), 615 ) # same
63+ assert im3 .get_pixel (1 , 0 ) == 1020
64+ assert im3 .get_pixel (1 , 1 ) == 615 # same
8165
8266
8367def test_image_16_32f_scale_and_offset ():
@@ -89,16 +73,12 @@ def test_image_16_32f_scale_and_offset():
8973 offset = 255
9074 scaling = 3.2
9175 im2 = im .copy (mapnik .ImageType .gray32f , offset , scaling )
92- eq_ ( im2 .get_pixel (0 , 0 ), 0.3125 )
93- eq_ ( im2 .get_pixel (0 , 1 ), 0.9375 )
94- eq_ ( im2 .get_pixel (1 , 0 ), - 79.6875 )
95- eq_ ( im2 .get_pixel (1 , 1 ), 112.5 )
76+ assert im2 .get_pixel (0 , 0 ) == 0.3125
77+ assert im2 .get_pixel (0 , 1 ) == 0.9375
78+ assert im2 .get_pixel (1 , 0 ) == - 79.6875
79+ assert im2 .get_pixel (1 , 1 ) == 112.5
9680 im3 = im2 .copy (mapnik .ImageType .gray16 )
97- eq_ (im3 .get_pixel (0 , 0 ), 256 )
98- eq_ (im3 .get_pixel (0 , 1 ), 258 )
99- eq_ (im3 .get_pixel (1 , 0 ), 0 )
100- eq_ (im3 .get_pixel (1 , 1 ), 615 )
101-
102- if __name__ == "__main__" :
103- setup ()
104- exit (run_all (eval (x ) for x in dir () if x .startswith ("test_" )))
81+ assert im3 .get_pixel (0 , 0 ) == 256
82+ assert im3 .get_pixel (0 , 1 ) == 258
83+ assert im3 .get_pixel (1 , 0 ) == 0
84+ assert im3 .get_pixel (1 , 1 ) == 615
0 commit comments