Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_locate_filename(self):
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate('slash.png', 'colornoise.png')
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
def test_imageNotFound(self):
colorNoiseFp = open('colornoise.png' ,'rb')
colorNoiseIm = Image.open(colorNoiseFp)
slashFp = open('slash.png' ,'rb')
slashIm = Image.open(slashFp)
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate(slashIm, colorNoiseIm)
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
colorNoiseFp.close()
slashFp.close()
def __wait_until_image_is_displayed(image_path):
# Wait for 60 seconds at maximum
for _ in range(60):
try:
point = gui.locateOnScreen(image_path)
if point:
return True
except ImageNotFoundException:
pass
time.sleep(1.0)
return False
def wrapper(*args, **kwargs):
try:
return wrappedFunction(*args, **kwargs)
except pyscreeze.ImageNotFoundException:
raise ImageNotFoundException # Raise PyAutoGUI's ImageNotFoundException.
def wrapper(*args, **kwargs):
try:
return wrappedFunction(*args, **kwargs)
except pyscreeze.ImageNotFoundException:
raise ImageNotFoundException # Raise PyAutoGUI's ImageNotFoundException.