1
1
import json
2
2
import os
3
3
from pathlib import Path
4
+ from typing import List
4
5
5
6
import pytest
6
7
@@ -42,7 +43,8 @@ def test_color_brewer_reverse():
42
43
assert scheme [::- 1 ] == scheme_r
43
44
44
45
45
- def test_color_brewer_extendability ():
46
+ @pytest .mark .parametrize ("sname" , core_schemes )
47
+ def test_color_brewer_extendability (sname ):
46
48
"""
47
49
The non-qualitative schemes should be extendable.
48
50
@@ -54,21 +56,20 @@ def test_color_brewer_extendability():
54
56
Indeed, in color_brewer, the key searched in the scheme database was not found,
55
57
thus, it was passing `None` instead of a real scheme vector to linear_gradient.
56
58
"""
57
- for sname in core_schemes :
58
- for n in range (color_brewer_minimum_n , color_brewer_maximum_n + 1 ):
59
- try :
60
- scheme = ut .color_brewer (sname , n = n )
61
- except Exception as e :
62
- if scheme_info [sname ] == "Qualitative" and isinstance (e , ValueError ):
63
- continue
64
- raise
59
+ for n in range (color_brewer_minimum_n , color_brewer_maximum_n + 1 ):
60
+ try :
61
+ scheme = ut .color_brewer (sname , n = n )
62
+ except Exception as e :
63
+ if scheme_info [sname ] == "Qualitative" and isinstance (e , ValueError ):
64
+ continue
65
+ raise
65
66
66
- assert len (scheme ) == n
67
+ assert len (scheme ) == n
67
68
68
- # When we try to extend a scheme,
69
- # the reverse is not always the exact reverse vector of the original one.
70
- # Thus, we do not test this property!
71
- _ = ut .color_brewer (sname + "_r" , n = n )
69
+ # When we try to extend a scheme,
70
+ # the reverse is not always the exact reverse vector of the original one.
71
+ # Thus, we do not test this property!
72
+ _ = ut .color_brewer (sname + "_r" , n = n )
72
73
73
74
74
75
def test_color_avoid_unexpected_error ():
@@ -169,3 +170,18 @@ def test_write_png_rgb():
169
170
]
170
171
png = b'\x89 PNG\r \n \x1a \n \x00 \x00 \x00 \r IHDR\x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \x08 \x06 \x00 \x00 \x00 \x7f \xa8 }c\x00 \x00 \x00 -IDATx\xda \x01 "\x00 \xdd \xff \x00 \xff \xa7 G\xff p\xff +\xff \x9e \x1c H\xff 9\x90 $\xff \x00 \x93 \xe9 \xb8 \xff \x0c z\xe2 \xff \xc6 \xca \xff \xff \xd4 W\xd0 \xff Yw\x15 \x95 \xcf \xb9 @D\x00 \x00 \x00 \x00 IEND\xae B`\x82 ' # noqa E501
171
172
assert ut .write_png (image_rgb ) == png
173
+
174
+
175
+ @pytest .mark .parametrize (
176
+ "hex_list, n_colors, expected_output" ,
177
+ [
178
+ (["#000000" , "#FFFFFF" ], 2 , ["#000000" , "#ffffff" ]),
179
+ (["#FF0000" , "#00FF00" , "#0000FF" ], 3 , ["#ff0000" , "#00ff00" , "#0000ff" ]),
180
+ (["#000000" , "#0000FF" ], 5 , ['#000000' , '#00003f' , '#00007f' , '#0000bf' , '#0000ff' ]),
181
+ (["#FFFFFF" , "#000000" ], 5 , ['#ffffff' , '#bfbfbf' , '#7f7f7f' , '#3f3f3f' , '#000000' ]),
182
+ (["#FF0000" , "#00FF00" , "#0000FF" ], 7 , ['#ff0000' , '#aa5400' , '#55a900' , '#00ff00' , '#00aa54' , '#0055a9' , '#0000ff' ]),
183
+ ]
184
+ )
185
+ def test_linear_gradient (hex_list : List [str ], n_colors : int , expected_output : List [str ]):
186
+ result = ut .linear_gradient (hex_list , n_colors )
187
+ assert result == expected_output
0 commit comments