Improve colorsys coverage (#153982)

tomasr8 <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/54b00c055210d738f5c3fb590ab85bde80b46ac6
commit: 54b00c055210d738f5c3fb590ab85bde80b46ac6
branch: main
author: MonadChains <[email protected]>
committer: tomasr8 <[email protected]>
date: 2026-07-19T11:48:02+02:00
summary:

Improve colorsys coverage (#153982)

* improve colorsys coverage

* add subtest

files:
M Lib/test/test_colorsys.py

diff --git a/Lib/test/test_colorsys.py b/Lib/test/test_colorsys.py
index 74d76294b0b4d4..9dfaef44a6a450 100644
--- a/Lib/test/test_colorsys.py
+++ b/Lib/test/test_colorsys.py
@@ -42,6 +42,10 @@ def test_hsv_values(self):
             self.assertTripleEqual(hsv, colorsys.rgb_to_hsv(*rgb))
             self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(*hsv))
 
+            # test 360 phase shift in hue
+            h, s, v = hsv
+            self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(h + 1.0, s, v))
+
     def test_hls_roundtrip(self):
         for r in frange(0.0, 1.0, 0.2):
             for g in frange(0.0, 1.0, 0.2):
@@ -89,6 +93,18 @@ def test_yiq_roundtrip(self):
                         colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                     )
 
+    def test_yiq_to_rgb_clamping(self):
+        values = [
+            # rgb, yiq (invalid YIQ values clamped to RGB range)
+            ((1.0, 0.0, 1.0), (0.0, 0.5, 1.0)),
+            ((0.0, 1.0, 0.0), (0.25, -1.0, -1.0)),
+            ((0.0, 0.0, 1.0), (0.0, -1.0, 0.5))
+        ]
+
+        for (rgb, yiq) in values:
+            with self.subTest(rgb=rgb, yiq=yiq):
+                self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
+
     def test_yiq_values(self):
         values = [
             # rgb, yiq

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.