mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	tests for close and context manager
This commit is contained in:
		
							parent
							
								
									8c6a4c0299
								
							
						
					
					
						commit
						471cecb523
					
				| 
						 | 
					@ -2,6 +2,8 @@ from tester import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from PIL import Image
 | 
					from PIL import Image
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_sanity():
 | 
					def test_sanity():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    im = lena()
 | 
					    im = lena()
 | 
				
			||||||
| 
						 | 
					@ -9,3 +11,17 @@ def test_sanity():
 | 
				
			||||||
    pix = im.load()
 | 
					    pix = im.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert_equal(pix[0, 0], (223, 162, 133))
 | 
					    assert_equal(pix[0, 0], (223, 162, 133))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_close():    
 | 
				
			||||||
 | 
					    im = Image.open("Images/lena.gif")
 | 
				
			||||||
 | 
					    assert_no_exception(lambda: im.close())
 | 
				
			||||||
 | 
					    assert_exception(ValueError, lambda: im.load())
 | 
				
			||||||
 | 
					    assert_exception(ValueError, lambda: im.getpixel((0,0)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_contextmanager():
 | 
				
			||||||
 | 
					    fn = None
 | 
				
			||||||
 | 
					    with Image.open("Images/lena.gif") as im:
 | 
				
			||||||
 | 
					        fn = im.fp.fileno()
 | 
				
			||||||
 | 
					        assert_no_exception(lambda: os.fstat(fn))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert_exception(OSError, lambda: os.fstat(fn))    
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user