Skip to content

Commit f2f9ff1

Browse files
[3.14] Improve colorsys coverage (GH-153982) (#154077)
Improve colorsys coverage (GH-153982) * improve colorsys coverage * add subtest (cherry picked from commit 54b00c0) Co-authored-by: MonadChains <monadchains@gmail.com>
1 parent 19e2660 commit f2f9ff1

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/test/test_colorsys.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def test_hsv_values(self):
4242
self.assertTripleEqual(hsv, colorsys.rgb_to_hsv(*rgb))
4343
self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(*hsv))
4444

45+
# test 360 phase shift in hue
46+
h, s, v = hsv
47+
self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(h + 1.0, s, v))
48+
4549
def test_hls_roundtrip(self):
4650
for r in frange(0.0, 1.0, 0.2):
4751
for g in frange(0.0, 1.0, 0.2):
@@ -89,6 +93,18 @@ def test_yiq_roundtrip(self):
8993
colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
9094
)
9195

96+
def test_yiq_to_rgb_clamping(self):
97+
values = [
98+
# rgb, yiq (invalid YIQ values clamped to RGB range)
99+
((1.0, 0.0, 1.0), (0.0, 0.5, 1.0)),
100+
((0.0, 1.0, 0.0), (0.25, -1.0, -1.0)),
101+
((0.0, 0.0, 1.0), (0.0, -1.0, 0.5))
102+
]
103+
104+
for (rgb, yiq) in values:
105+
with self.subTest(rgb=rgb, yiq=yiq):
106+
self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
107+
92108
def test_yiq_values(self):
93109
values = [
94110
# rgb, yiq

0 commit comments

Comments
 (0)