Skip to content

Commit 3bda54a

Browse files
committed
conv: Use NotImplementedError when no backends are available
to_bgr888() raised ValueError when no requested backend was installed and NotImplementedError when an installed backend could not handle the format. Both mean "we can't convert this", so collapse them into one exception type. The tests that probe backends or skip on missing backends can now catch a single exception type instead of matching on the ValueError message string. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
1 parent bb9bcdf commit 3bda54a

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

pixutils/conv/conv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def to_bgr888(
100100
# Get list of backends to try
101101
backends = get_backends(options.get('backends') if options else None)
102102
if not backends:
103-
raise ValueError('No backends available')
103+
raise NotImplementedError('No backends available')
104104

105105
size = 0
106106

tests/test_conv.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ def test_function(self):
230230
rgb_buf = buffer_to_bgr888(
231231
test_case.pixel_format, WIDTH, HEIGHT, 0, src_buf, test_case.options
232232
)
233-
except ValueError as e:
234-
if str(e) == 'No backends available':
235-
self.skipTest('No backend available')
236-
raise
233+
except NotImplementedError as e:
234+
raise unittest.SkipTest('No backend available') from e
237235

238236
src_sha = hashlib.sha256(src_buf.tobytes()).hexdigest()
239237
rgb_sha = hashlib.sha256(rgb_buf.tobytes()).hexdigest()
@@ -283,10 +281,8 @@ def test_function(self):
283281

284282
try:
285283
rgb_buf = buffer_to_bgr888(fmt, WIDTH, HEIGHT, bpl, test_buf, test_case.options)
286-
except ValueError as e:
287-
if str(e) == 'No backends available':
288-
self.skipTest('No backend available')
289-
raise
284+
except NotImplementedError as e:
285+
raise unittest.SkipTest('No backend available') from e
290286

291287
rgb_sha = hashlib.sha256(rgb_buf.tobytes()).hexdigest()
292288
self.assertEqual(
@@ -345,10 +341,8 @@ def test_function(self):
345341

346342
try:
347343
rgb_buf = buffer_to_bgr888(fmt, WIDTH, HEIGHT, bpl, test_buf, test_case.options)
348-
except ValueError as e:
349-
if str(e) == 'No backends available':
350-
self.skipTest('No backend available')
351-
raise
344+
except NotImplementedError as e:
345+
raise unittest.SkipTest('No backend available') from e
352346

353347
rgb_sha = hashlib.sha256(rgb_buf.tobytes()).hexdigest()
354348
self.assertEqual(

0 commit comments

Comments
 (0)