Skip to content

Commit

Permalink
Merge pull request #17 from vorstrelok/fixinstall
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
asweigart committed Jan 19, 2017
2 parents 463fe19 + 37dca57 commit 96a436b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dist
_build
*.pyc
__pycache__
PyAutoGUI.egg-info
PyAutoGUI.egg-info
PyScreeze.egg-info
12 changes: 9 additions & 3 deletions pyscreeze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import sys
import time
import errno
from PIL import Image
from PIL import ImageOps
try:
from PIL import Image
from PIL import ImageOps
except ImportError:
pass

try:
import cv2, numpy
Expand Down Expand Up @@ -416,7 +419,10 @@ def pixel(x, y):
screenshot = _screenshot_osx
elif sys.platform == 'win32':
screenshot = _screenshot_win32
from PIL import ImageGrab
try:
from PIL import ImageGrab
except ImportError:
pass
else:
screenshot = _screenshot_linux

Expand Down
23 changes: 22 additions & 1 deletion tests/basicTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import os
import random

from PIL import Image
try:
from PIL import Image
except ImportError:
pass
sys.path.insert(0, os.path.abspath('..'))
import pyscreeze

Expand Down Expand Up @@ -94,6 +97,24 @@ def test_jpgMagicNumbers(self):
self.assertFalse(isJpg(__file__))

class TestGeneral(unittest.TestCase):
def test_pillowNotPresent(self):
# Testing that we can still import pyscreeze
# even if pillow is not present

# Setting module's dictionary entry to None will raise
# ImportError while deleting the entry will make the interpreter
# continue searching for module
sys.modules["PIL"] = None

if sys.version_info[0] == 2:
reload(pyscreeze)
elif sys.version_info[:2] <= (3, 3):
import imp
imp.reload(pyscreeze)
else:
import importlib
importlib.reload(pyscreeze)

def test_namesDefined(self):
pyscreeze.locateAll
pyscreeze.locate
Expand Down

0 comments on commit 96a436b

Please sign in to comment.