mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Merge pull request #906 from hugovk/ImageGrab
Improve error message for ImageGrab on non-Windows
This commit is contained in:
commit
5dc418b8de
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
import sys
|
||||||
|
if sys.platform != "win32":
|
||||||
|
raise ImportError("ImageGrab is Windows only")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# built-in driver (1.1.3 and later)
|
# built-in driver (1.1.3 and later)
|
||||||
|
@ -40,7 +43,7 @@ def grab(bbox=None):
|
||||||
|
|
||||||
|
|
||||||
def grabclipboard():
|
def grabclipboard():
|
||||||
debug = 0 # temporary interface
|
debug = 0 # temporary interface
|
||||||
data = Image.core.grabclipboard(debug)
|
data = Image.core.grabclipboard(debug)
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
from PIL import BmpImagePlugin
|
from PIL import BmpImagePlugin
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from helper import unittest, PillowTestCase
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
|
|
||||||
|
@ -19,6 +21,27 @@ except ImportError:
|
||||||
self.skipTest("ImportError")
|
self.skipTest("ImportError")
|
||||||
|
|
||||||
|
|
||||||
|
class TestImageGrabImport(PillowTestCase):
|
||||||
|
|
||||||
|
def test_import(self):
|
||||||
|
# Arrange
|
||||||
|
exception = None
|
||||||
|
|
||||||
|
# Act
|
||||||
|
try:
|
||||||
|
from PIL import ImageGrab
|
||||||
|
ImageGrab.__name__ # dummy to prevent Pyflakes warning
|
||||||
|
except Exception as e:
|
||||||
|
exception = e
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
self.assertIsNone(exception, None)
|
||||||
|
else:
|
||||||
|
self.assertIsInstance(exception, ImportError)
|
||||||
|
self.assertEqual(str(exception), "ImageGrab is Windows only")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user