Best Python code snippet using pyscreenshot_python
main.py
Source:main.py
...8 fd = open(filename, 'rb').read()9 return (imghdr.what(None, fd) == 'jpeg')10 except:11 return False12def test_pil(filename):13 from PIL import Image14 from cStringIO import StringIO15 try:16 file_data = StringIO(open(filename, 'rb').read())17 im = Image.open(file_data)18 im.verify()19 return (im.format == 'JPEG')20 except:21 return False22if __name__ == '__main__':23 assert test_imghdr('valid.jpg') and test_pil('valid.jpg')24 assert not test_imghdr('unvalid.jpg') and not test_pil('unvalid.jpg')25 assert not test_imghdr('notfound.jpg') and not test_pil('notfound.jpg')26 print "test_imghdr %.2f" % timeit.timeit("test_imghdr('valid.jpg')",27 setup="from __main__ import test_imghdr")28 print "test_pil %.2f" % timeit.timeit("test_pil('valid.jpg')",...
csci1100pythonmodulestest.py
Source:csci1100pythonmodulestest.py
1"""2This module tests PIL library installation3"""45import doctest6from io import BytesIO7from PIL import Image8import requests910def test_doctest(x):11 """12 test_doctest(x) returns13 the value x passed in.1415 >>> test_doctest(1)16 117 >>> test_doctest(0)18 019 """20 return x2122def test_PIL():23 """24 test_PIL() loads the image logo, and then rotates and displays it25 Return value: None26 """27 img_file = "http://www.ecse.rpi.edu/~agung/logo.jpg"28 response = requests.get(img_file)29 resized_image = Image.open(BytesIO(response.content))30 cropped_image = resized_image.crop((0, 0, resized_image.size[1], resized_image.size[1]))31 cropped_image.rotate(90).show()32 print("Testing PIL: RPI logo rotated 90 degrees is shown.")3334if __name__ == "__main__":35 doctest.testmod(verbose=True)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!