Updated error catching

This commit is contained in:
Andrew Murray 2019-12-28 23:39:50 +11:00
parent 5253b0cd57
commit 2543719e12

View File

@ -36,15 +36,9 @@ class TestImageGrab:
@pytest.mark.skipif(not Image.core.HAVE_XCB, reason="requires XCB") @pytest.mark.skipif(not Image.core.HAVE_XCB, reason="requires XCB")
def test_grab_invalid_xdisplay(self): def test_grab_invalid_xdisplay(self):
exception = None with pytest.raises(IOError) as e:
try:
ImageGrab.grab(xdisplay="error.test:0.0") ImageGrab.grab(xdisplay="error.test:0.0")
except Exception as e: assert str(e.value).startswith("X connection failed")
exception = e
assert isinstance(exception, IOError)
assert str(exception).startswith("X connection failed")
def test_grabclipboard(self): def test_grabclipboard(self):
if sys.platform == "darwin": if sys.platform == "darwin":
@ -59,15 +53,11 @@ $bmp = New-Object Drawing.Bitmap 200, 200
) )
p.communicate() p.communicate()
else: else:
exception = None with pytest.raises(NotImplementedError) as e:
try:
ImageGrab.grabclipboard() ImageGrab.grabclipboard()
except IOError as e: self.assertEqual(
exception = e str(e.value), "ImageGrab.grabclipboard() is macOS and Windows only"
)
assert isinstance(exception, IOError)
assert str(exception) == "ImageGrab.grabclipboard() is macOS and Windows only"
return return
im = ImageGrab.grabclipboard() im = ImageGrab.grabclipboard()