Use more specific error by radarhere · Pull Request #8168 · python-pillow/Pillow
I was just looking at
| def test_unbound_local() -> None: | |
| # prepatch, a malformed jp2 file could cause an UnboundLocalError exception. | |
| with pytest.raises(OSError): | |
| with Image.open("Tests/images/unbound_variable.jp2"): | |
| pass |
which triggers a SyntaxError
| if size is None or mode is None: | |
| msg = "Malformed JP2 header" | |
| raise SyntaxError(msg) |
and wondering why that didn't lead to an UnidentifiedImageError.
The answer was that it did, but UnidentifiedImageError inherits from OSError, so the test passed without a problem.
| class UnidentifiedImageError(OSError): |
This PR just updated the test to check for UnidentifiedImageError, to be clearer.