Improve the error message when importing ImageGrab on non-Windows (#901)

This commit is contained in:
Hugo 2014-09-16 16:05:22 +03:00
parent 1ecc3195d9
commit 99887a5467
2 changed files with 29 additions and 1 deletions

View File

@ -17,6 +17,9 @@
from PIL import Image
import sys
if sys.platform != "win32":
raise ImportError("ImageGrab is Windows only")
try:
# built-in driver (1.1.3 and later)
@ -40,7 +43,7 @@ def grab(bbox=None):
def grabclipboard():
debug = 0 # temporary interface
debug = 0 # temporary interface
data = Image.core.grabclipboard(debug)
if isinstance(data, bytes):
from PIL import BmpImagePlugin

View File

@ -1,5 +1,8 @@
from helper import unittest, PillowTestCase
import exceptions
import sys
try:
from PIL import ImageGrab
@ -19,6 +22,28 @@ except 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 exception:
pass
# Assert
if sys.platform == 'win32':
self.assertIsNone(exception, None)
else:
self.assertIsInstance(exception, exceptions.ImportError)
self.assertEqual(exception.message,
"ImageGrab is Windows only")
if __name__ == '__main__':
unittest.main()