-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathcolor_test.py
More file actions
121 lines (108 loc) · 2.62 KB
/
Copy pathcolor_test.py
File metadata and controls
121 lines (108 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from nose.tools import eq_
import mapnik
from .utilities import execution_path, run_all
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_color_init():
c = mapnik.Color(12, 128, 255)
eq_(c.r, 12)
eq_(c.g, 128)
eq_(c.b, 255)
eq_(c.a, 255)
eq_(False, c.get_premultiplied())
c = mapnik.Color(16, 32, 64, 128)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(False, c.get_premultiplied())
c = mapnik.Color(16, 32, 64, 128, True)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(True, c.get_premultiplied())
c = mapnik.Color('rgba(16,32,64,0.5)')
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(False, c.get_premultiplied())
c = mapnik.Color('rgba(16,32,64,0.5)', True)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(True, c.get_premultiplied())
hex_str = '#10204080'
c = mapnik.Color(hex_str)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(hex_str, c.to_hex_string())
eq_(False, c.get_premultiplied())
c = mapnik.Color(hex_str, True)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(hex_str, c.to_hex_string())
eq_(True, c.get_premultiplied())
rgba_int = 2151686160
c = mapnik.Color(rgba_int)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(rgba_int, c.packed())
eq_(False, c.get_premultiplied())
c = mapnik.Color(rgba_int, True)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
eq_(rgba_int, c.packed())
eq_(True, c.get_premultiplied())
def test_color_properties():
c = mapnik.Color(16, 32, 64, 128)
eq_(c.r, 16)
eq_(c.g, 32)
eq_(c.b, 64)
eq_(c.a, 128)
c.r = 17
eq_(c.r, 17)
c.g = 33
eq_(c.g, 33)
c.b = 65
eq_(c.b, 65)
c.a = 128
eq_(c.a, 128)
def test_color_premultiply():
c = mapnik.Color(16, 33, 255, 128)
eq_(c.premultiply(), True)
eq_(c.r, 8)
eq_(c.g, 17)
eq_(c.b, 128)
eq_(c.a, 128)
# Repeating it again should do nothing
eq_(c.premultiply(), False)
eq_(c.r, 8)
eq_(c.g, 17)
eq_(c.b, 128)
eq_(c.a, 128)
c.demultiply()
c.demultiply()
# This will not return the same values as before but we expect that
eq_(c.r, 15)
eq_(c.g, 33)
eq_(c.b, 255)
eq_(c.a, 128)
if __name__ == "__main__":
setup()
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))