-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathcolor_test.py
More file actions
102 lines (97 loc) · 2.45 KB
/
color_test.py
File metadata and controls
102 lines (97 loc) · 2.45 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
import os
import mapnik
def test_color_init():
c = mapnik.Color(12, 128, 255)
assert c.r == 12
assert c.g == 128
assert c.b == 255
assert c.a == 255
assert not c.get_premultiplied()
c = mapnik.Color(16, 32, 64, 128)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert not c.get_premultiplied()
c = mapnik.Color(16, 32, 64, 128, True)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert c.get_premultiplied()
c = mapnik.Color('rgba(16,32,64,0.5)')
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert not c.get_premultiplied()
c = mapnik.Color('rgba(16,32,64,0.5)', True)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert c.get_premultiplied()
hex_str = '#10204080'
c = mapnik.Color(hex_str)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert hex_str == c.to_hex_string()
assert not c.get_premultiplied()
c = mapnik.Color(hex_str, True)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert hex_str == c.to_hex_string()
assert c.get_premultiplied()
rgba_int = 2151686160
c = mapnik.Color(rgba_int)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert rgba_int == c.packed()
assert not c.get_premultiplied()
c = mapnik.Color(rgba_int, True)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
assert rgba_int == c.packed()
assert c.get_premultiplied()
def test_color_properties():
c = mapnik.Color(16, 32, 64, 128)
assert c.r == 16
assert c.g == 32
assert c.b == 64
assert c.a == 128
c.r = 17
assert c.r == 17
c.g = 33
assert c.g == 33
c.b = 65
assert c.b == 65
c.a = 128
assert c.a == 128
def test_color_premultiply():
c = mapnik.Color(16, 33, 255, 128)
assert c.premultiply()
assert c.r == 8
assert c.g == 17
assert c.b == 128
assert c.a == 128
# Repeating it again should do nothing
assert not c.premultiply()
assert c.r == 8
assert c.g == 17
assert c.b == 128
assert c.a == 128
c.demultiply()
c.demultiply()
# This will not return the same values as before but we expect that
assert c.r == 15
assert c.g == 33
assert c.b == 255
assert c.a == 128