From 87ab38479b2ce4bb65414a0e3f67d7ace4cb8f11 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 11 Mar 2020 22:53:35 +1100 Subject: [PATCH] Updated tests --- Tests/test_imagegrab.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index aca72ceb0d7..e3521501f4b 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -1,6 +1,7 @@ import subprocess import sys +import pytest from PIL import Image, ImageGrab from .helper import PillowTestCase, assert_image, unittest @@ -36,23 +37,19 @@ def test_grab_x11(self): @unittest.skipIf(Image.core.HAVE_XCB, "tests missing XCB") def test_grab_no_xcb(self): if sys.platform not in ("win32", "darwin"): - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab() - self.assertTrue( - str(e.exception).startswith("Pillow was built without XCB support") - ) + assert str(e.value).startswith("Pillow was built without XCB support") - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab(xdisplay="") - self.assertTrue( - str(e.exception).startswith("Pillow was built without XCB support") - ) + assert str(e.value).startswith("Pillow was built without XCB support") @unittest.skipUnless(Image.core.HAVE_XCB, "requires XCB") def test_grab_invalid_xdisplay(self): - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab(xdisplay="error.test:0.0") - assert str(e.exception).startswith("X connection failed") + assert str(e.value).startswith("X connection failed") def test_grabclipboard(self): if sys.platform == "darwin": @@ -67,11 +64,9 @@ def test_grabclipboard(self): ) p.communicate() else: - with self.assertRaises(NotImplementedError) as e: + with pytest.raises(NotImplementedError) as e: ImageGrab.grabclipboard() - self.assertEqual( - str(e.exception), "ImageGrab.grabclipboard() is macOS and Windows only" - ) + assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only" return im = ImageGrab.grabclipboard()