-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_Goulib_colors.py
317 lines (245 loc) · 9.98 KB
/
test_Goulib_colors.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env python
# coding: utf8
from __future__ import division #"true division" everywhere
from nose.tools import assert_equal
from nose import SkipTest
#lines above are inserted automatically by pythoscope. Line below overrides them
from Goulib.tests import *
from Goulib.colors import *
from Goulib.itertools2 import reshape
import os
path=os.path.dirname(os.path.abspath(__file__))
class TestRgb2Hex:
def test_rgb2hex(self):
assert_equal( rgb2hex((0,16/255,1)),'#0010ff')
class TestHex2Rgb:
def test_hex2rgb(self):
assert_equal(hex2rgb('#0010ff'),(0,16./255,1))
class TestRgb2Cmyk:
def test_rgb2cmyk(self):
assert_equal(rgb2cmyk((0,0,0)),(0,0,0,1))
assert_equal(rgb2cmyk((.8,.6,.4)),(0,0.25,.5,0.2))
class TestNearestColor:
def test_nearest_color(self):
assert_equal(nearest_color('#414142'),color['darkslategray'])
cmyk=Color((.45,.12,.67,.05),space='cmyk')
p=nearest_color(cmyk,pantone)
assert_equal(p.name,'802C')
dE=deltaE
class TestAci:
def test_color_to_aci(self):
assert_equal(color_to_aci('red'), 1)
assert_equal(color_to_aci(acadcolors[123]), 123)
c=color_to_aci('#414142',True)
assert_equal(acadcolors[c].hex,'#414141')
class TestColorRange:
def test_color_range(self):
c=color_range(5,'red','blue')
assert_equal(c[0],color['red'])
assert_equal(c[1],color['yellow'])
assert_equal(c[2],color['lime'])
assert_equal(c[3],color['cyan'])
assert_equal(c[4],color['blue'])
class TestColor:
@classmethod
def setup_class(self):
self.blue=Color('blue')
self.blues=[ #many ways to define the same color
self.blue,
Color('#0000ff'),
Color((0,0,1)),
Color((0,0,255)),
Color(self.blue),
]
self.red=Color('red')
self.green=Color('lime') # 'green' has hex 80 value, not ff
self.white=color['white']
self.cmyk=Color((.45,.12,.67,.05),space='cmyk') # a random cmyk color
def test___init__(self):
#check all constructors make the same color
for b in self.blues:
assert_equal(b,self.blue)
def test___add__(self):
assert_equal(self.red+self.green+self.blue,'white')
assert_equal(self.red+self.green+self.blue,'white')
def test___sub__(self):
white=Color('white')
green=Color('lime') # 'green' has hex 80 value, not ff
blue=Color('blue')
assert_equal(white-green-blue,'red')
def test___eq__(self):
pass #tested above
def test___repr__(self):
assert_equal(repr(Color('blue')),"Color('blue')")
def test__repr_html_(self):
assert_equal(Color('blue')._repr_html_(),'<span style="color:#0000ff">blue</span>')
def test_native(self):
pass #tested in convert
def test_rgb(self):
pass #tested above
def test_hex(self):
assert_equal(self.cmyk.hex,'#85d550')
def test_hsv(self):
pass #tested in convert
def test_lab(self):
pass #tested in convert
def test_luv(self):
pass #tested in convert
def test_xyY(self):
pass #tested in convert
def test_xyz(self):
pass #tested in convert
def test_cmyk(self):
assert_equal(Color('black').cmyk,(0,0,0,1))
assert_equal(Color('blue').cmyk,(1,1,0,0))
assert_equal(Color((0,.5,.5)).cmyk,(1,0,0,.5)) #teal
def test_convert(self):
""" test all possible round trip conversions for selected colors"""
for color in ('green','red','blue','yellow','magenta','cyan','black','white'):
c=Color(color)
for startmode in colorspaces:
start=Color(c.convert(startmode),startmode)
for destmode in colorspaces:
dest=Color(start.convert(destmode),destmode)
back=Color(dest.convert(startmode),startmode)
if not back.isclose(start):
logging.error('round trip of %s from %s to %s failed with dE=%s'%
(color,startmode,destmode,back.deltaE(start))
)
def test_name(self):
# color = Color(value, space, name)
# assert_equal(expected, color.name())
raise SkipTest # implement your test here
def test___hash__(self):
# color = Color(value, space, name)
# assert_equal(expected, color.__hash__())
raise SkipTest # implement your test here
def test___neg__(self):
# color = Color(value, space, name)
# assert_equal(expected, color.__neg__())
raise SkipTest # implement your test here
def test_deltaE(self):
# color = Color(value, space, name)
# assert_equal(expected, color.deltaE(other))
raise SkipTest # implement your test here
def test_str(self):
c=self.blue
res='\n'.join('%s = %s'%(k,c.str(k)) for k in c._values)
assert_true(res)
def test_isclose(self):
# color = Color(value, space, name)
# assert_equal(expected, color.isclose(other, abs_tol))
raise SkipTest # implement your test here
def test___mul__(self):
# color = Color(value, space, name)
# assert_equal(expected, color.__mul__(factor))
raise SkipTest # implement your test here
def test___radd__(self):
# color = Color(value, space, name)
# assert_equal(expected, color.__radd__(other))
raise SkipTest # implement your test here
def test_compose(self):
# color = Color(value, space, name)
# assert_equal(expected, color.compose(other, f, mode))
raise SkipTest # implement your test here
from matplotlib import cm #colormaps
class TestPalette:
@classmethod
def setup_class(self):
self.spectral=Palette(cm.spectral)
self.cmyk=Palette(['cyan','magenta','yellow','black'],'CMYK') #indexed by letters
self.cmyk_int=Palette(['cyan','magenta','yellow','black']) #indexed by ints
def test___init__(self):
assert_equal(len(self.spectral),256)
assert_equal(len(self.cmyk),4)
assert_equal(self.cmyk['M'].name,'magenta')
assert_equal(self.cmyk_int[2].name,'yellow')
def test_index(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.index(c, dE))
raise SkipTest # implement your test here
def test_update(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.update(data, n))
raise SkipTest # implement your test here
def test_palette(self):
# assert_equal(expected, palette(im, ncolors))
raise SkipTest # implement your test here
def test_pil(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.pil())
raise SkipTest # implement your test here
def test__repr_html_(self):
res=self.spectral._repr_html_()
assert_true(res) #TODO: more
def test_sorted(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.sorted(key))
raise SkipTest # implement your test here
def test___repr__(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.__repr__())
raise SkipTest # implement your test here
def test_patches(self):
# palette = Palette(data, n)
# assert_equal(expected, palette.patches(wide, size))
raise SkipTest # implement your test here
class TestColorLookup:
def test_color_lookup(self):
c=color['blue']
c2=color_lookup[c.hex]
assert_equal(c,c2)
class TestColorToAci:
def test_color_to_aci(self):
# assert_equal(expected, color_to_aci(x, nearest))
raise SkipTest
class TestAciToColor:
def test_aci_to_color(self):
# assert_equal(expected, aci_to_color(x, block_color, layer_color))
raise SkipTest
class TestPantone:
def test_pantone(self):
from Goulib.table import Table,Cell
from Goulib.itertools2 import reshape
t=[Cell(name,style={'background-color':pantone[name].hex}) for name in sorted(pantone)]
t=Table(reshape(t,(0,10)))
with open(path+'\\results\\colors.pantone.html', 'w') as f:
f.write(t.html())
class TestRgb2cmyk:
def test_rgb2cmyk(self):
cmyk=rgb2cmyk(color['green'].rgb)
assert_equal(cmyk,(1,0,1,127/255))
class TestCmyk2rgb:
def test_cmyk2rgb(self):
rgb=cmyk2rgb((1,0,1,.5))
assert_equal(rgb,(0,.5,0))
class TestXyz2xyy:
def test_xyz2xyy(self):
# assert_equal(expected, xyz2xyy(xyz))
raise SkipTest # implement your test here
class TestConvert:
def test_convert(self):
# assert_equal(expected, convert(color, source, target))
raise SkipTest # implement your test here
class TestDeltaE:
def test_delta_e(self):
# assert_equal(expected, deltaE(c1, c2))
raise SkipTest # implement your test here
class TestColorTable:
def test_color_table(self):
# assert_equal(expected, ColorTable(colors, key, width))
raise SkipTest # implement your test here
class TestXyy2xyz:
def test_xyy2xyz(self):
# assert_equal(expected, xyy2xyz(xyY))
raise SkipTest # implement your test here
class TestRgb2hex:
def test_rgb2hex(self):
# assert_equal(expected, rgb2hex(c, illuminant))
raise SkipTest # implement your test here
class TestHex2rgb:
def test_hex2rgb(self):
# assert_equal(expected, hex2rgb(c, illuminant))
raise SkipTest # implement your test here
if __name__ == "__main__":
runmodule()