Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/machinevisiontoolbox/base/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,20 +963,20 @@ def XYZ2RGBxform(
if isinstance(white, str):
try:
white_xy = np.array(_whites[white.lower()])
except:
except KeyError as exc:
raise ValueError(
"unknown white value, must be one of" ", ".join(_whites.keys())
)
f"unknown white value, must be one of {', '.join(_whites)}"
) from exc
else:
white_xy = smb.getvector(white, 2)

if isinstance(primaries, str):
try:
primary_xy = _xy_primaries[primaries.lower()]
except:
except KeyError as exc:
raise ValueError(
"unknown primary value, must be one of" ", ".join(_xy_primaries.keys())
)
f"unknown primary value, must be one of {', '.join(_xy_primaries)}"
) from exc
else:
primary_xy = smb.getmatrix(primaries, (3, 2))

Expand Down
24 changes: 24 additions & 0 deletions tests/test_color_lookup_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest

from machinevisiontoolbox.base.color import XYZ2RGBxform


class TestColorLookupErrors(unittest.TestCase):
def test_unknown_white_lists_supported_values(self):
"""Report supported white points once, separated by commas."""
with self.assertRaises(ValueError) as raised:
XYZ2RGBxform(white="unknown")
self.assertEqual(
str(raised.exception), "unknown white value, must be one of d65, e"
)
self.assertIsInstance(raised.exception.__cause__, KeyError)

def test_unknown_primaries_lists_supported_values(self):
"""Report supported primaries once, separated by commas."""
with self.assertRaises(ValueError) as raised:
XYZ2RGBxform(primaries="unknown")
self.assertEqual(
str(raised.exception),
"unknown primary value, must be one of itu-709, cie, srgb",
)
self.assertIsInstance(raised.exception.__cause__, KeyError)
Loading