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_im(self):
slashFp = open('slash.png' ,'rb')
haystack1Fp = open('haystack1.png' ,'rb')
haystack2Fp = open('haystack2.png' ,'rb')
colorNoiseFp = open('colornoise.png' ,'rb')
slashIm = Image.open(slashFp)
haystack1Im = Image.open(haystack1Fp)
haystack2Im = Image.open(haystack2Fp)
colorNoiseIm = Image.open(colorNoiseFp)
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im)))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im)))
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im, grayscale=True)))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im, grayscale=True)))
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate(slashIm, colorNoiseIm)
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True)
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True), None)
slashFp.close()
haystack1Fp.close()
haystack2Fp.close()
colorNoiseFp.close()
def locateTest():
largeNoiseFp = open('largenoise.png' ,'rb')
largeNoiseIm = Image.open(largeNoiseFp)
imageWidth, imageHeight = largeNoiseIm.size
bottomRightCorner100x100 = largeNoiseIm.crop((imageWidth - 100, imageHeight - 100, imageWidth, imageHeight))
for step in (1, 2, 4, 8, 16, 32):
startTime = time.time()
result = pyscreeze.locate(bottomRightCorner100x100, largeNoiseIm, step=step)
print('bottomRightCorner100x100 (step %s) located at %s in: %s seconds' % (step, result, round(time.time() - startTime, 2)))
largeNoiseFp.close()
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)
slashIm = Image.open(slashFp)
haystack1Im = Image.open(haystack1Fp)
haystack2Im = Image.open(haystack2Fp)
colorNoiseIm = Image.open(colorNoiseFp)
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im)))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im)))
self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im, grayscale=True)))
self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im, grayscale=True)))
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate(slashIm, colorNoiseIm)
with self.assertRaises(pyscreeze.ImageNotFoundException):
pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True)
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True), None)
slashFp.close()
haystack1Fp.close()
haystack2Fp.close()
colorNoiseFp.close()
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_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_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 _locate(*args, **kwargs):
return pyscreeze.locate(*args, **kwargs)
def locate(*args, **kwargs):
return pyscreeze.locate(*args, **kwargs)