summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-11 15:47:15 (GMT)
committerGitHub <noreply@github.com>2023-07-11 15:47:15 (GMT)
commitc594e25cd76b9d2be04eaebc13df2becbdda7aed (patch)
tree0461a23572192c8b5efc94e8a57ca9aa4bc20732 /Lib/test
parent6968f9e4d3593610b60c1140f04de275ff40cd41 (diff)
downloadcpython-c594e25cd76b9d2be04eaebc13df2becbdda7aed.zip
cpython-c594e25cd76b9d2be04eaebc13df2becbdda7aed.tar.gz
cpython-c594e25cd76b9d2be04eaebc13df2becbdda7aed.tar.bz2
[3.12] gh-106498: Revert incorrect colorsys.rgb_to_hls change (GH-106627) (#106632)
gh-106498: Revert incorrect colorsys.rgb_to_hls change (GH-106627) gh-86618 assumed a-b-c = a-(b+c) = a-d where d = b+d. For floats 2.0, 1.0, and 0.9999999999999999, this assumption is false. The net change of 1.1102230246251565e-16 to 0.0 results in division by 0. Revert the replacement. Add test. (cherry picked from commit a2d54d4e8ab12f967a220be88bde8ac8227c5ab3) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_colorsys.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_colorsys.py b/Lib/test/test_colorsys.py
index a24e3ad..74d7629 100644
--- a/Lib/test/test_colorsys.py
+++ b/Lib/test/test_colorsys.py
@@ -69,6 +69,16 @@ class ColorsysTest(unittest.TestCase):
self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
self.assertTripleEqual(rgb, colorsys.hls_to_rgb(*hls))
+ def test_hls_nearwhite(self): # gh-106498
+ values = (
+ # rgb, hls: these do not work in reverse
+ ((0.9999999999999999, 1, 1), (0.5, 1.0, 1.0)),
+ ((1, 0.9999999999999999, 0.9999999999999999), (0.0, 1.0, 1.0)),
+ )
+ for rgb, hls in values:
+ self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
+ self.assertTripleEqual((1.0, 1.0, 1.0), colorsys.hls_to_rgb(*hls))
+
def test_yiq_roundtrip(self):
for r in frange(0.0, 1.0, 0.2):
for g in frange(0.0, 1.0, 0.2):