@@ -39,15 +39,26 @@ def test_parse_color(input_data, expected):
3939@pytest .mark .parametrize (
4040 "input_data, expected" ,
4141 [
42+ # these are byte values as ints and should be normalized and converted
4243 ((0 , 0 , 0 ), (0.0 , 0.0 , 0.0 , 1.0 )),
4344 ((255 , 255 , 255 ), (1.0 , 1.0 , 1.0 , 1.0 )),
4445 ((255 , 0 , 0 ), (1.0 , 0.0 , 0.0 , 1.0 )),
46+ # a special case: ints that are 0 or 1 should be considered bytes
47+ ((0 , 0 , 1 ), (0.0 , 0.0 , 1 / 255 , 1.0 )),
48+ ((0 , 0 , 0 , 1 ), (0.0 , 0.0 , 0.0 , 1 / 255 )),
49+ # these already are normalized floats
4550 ((0.0 , 0.0 , 0.0 ), (0.0 , 0.0 , 0.0 , 1.0 )),
51+ ((0.0 , 0.0 , 1.0 ), (0.0 , 0.0 , 1.0 , 1.0 )),
4652 ((0.5 , 0.5 , 0.5 ), (0.5 , 0.5 , 0.5 , 1.0 )),
4753 ((0.1 , 0.2 , 0.3 , 0.4 ), (0.1 , 0.2 , 0.3 , 0.4 )),
4854 ((0.0 , 1.0 , 0.0 , 0.5 ), (0.0 , 1.0 , 0.0 , 0.5 )),
55+ # these are byte values as floats and should be normalized
4956 ((0 , 0 , 0 , 255.0 ), (0.0 , 0.0 , 0.0 , 1.0 )),
5057 ((0 , 0 , 255.0 , 0.0 ), (0.0 , 0.0 , 1.0 , 0.0 )),
58+ # if floats and ints are mixed, assume they are intended as floats
59+ ((0 , 0 , 1.0 ), (0.0 , 0.0 , 1.0 , 1.0 )),
60+ # unless some of them are between 1 and 255
61+ ((0 , 0 , 1.0 , 128 ), (0.0 , 0.0 , 1 / 255 , 128 / 255 )),
5162 ],
5263)
5364def test_parse_color_as_numerical_sequence (input_data , expected ):
0 commit comments