Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_colorsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Comment thread
tomasr8 marked this conversation as resolved.

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):
Expand Down Expand Up @@ -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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use unittest.subTest(the support decorator instead is fine, too) here, see the documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please have a look

with self.subTest(rgb=rgb, yiq=yiq):
self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))

def test_yiq_values(self):
values = [
# rgb, yiq
Expand Down
Loading