mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	and replaces them with a new API verify(). As a result the regression suite will also perform its tests in optimization mode. Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			932 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			932 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import os
 | 
						|
 | 
						|
from test_support import verify, TESTFN
 | 
						|
from UserList import UserList
 | 
						|
 | 
						|
# verify writelines with instance sequence
 | 
						|
l = UserList(['1', '2'])
 | 
						|
f = open(TESTFN, 'wb')
 | 
						|
f.writelines(l)
 | 
						|
f.close()
 | 
						|
f = open(TESTFN, 'rb')
 | 
						|
buf = f.read()
 | 
						|
f.close()
 | 
						|
verify(buf == '12')
 | 
						|
 | 
						|
# verify writelines with integers
 | 
						|
f = open(TESTFN, 'wb')
 | 
						|
try:
 | 
						|
    f.writelines([1, 2, 3])
 | 
						|
except TypeError:
 | 
						|
    pass
 | 
						|
else:
 | 
						|
    print "writelines accepted sequence of integers"
 | 
						|
f.close()
 | 
						|
 | 
						|
# verify writelines with integers in UserList
 | 
						|
f = open(TESTFN, 'wb')
 | 
						|
l = UserList([1,2,3])
 | 
						|
try:
 | 
						|
    f.writelines(l)
 | 
						|
except TypeError:
 | 
						|
    pass
 | 
						|
else:
 | 
						|
    print "writelines accepted sequence of integers"
 | 
						|
f.close()
 | 
						|
 | 
						|
# verify writelines with non-string object
 | 
						|
class NonString: pass
 | 
						|
 | 
						|
f = open(TESTFN, 'wb')
 | 
						|
try:
 | 
						|
    f.writelines([NonString(), NonString()])
 | 
						|
except TypeError:
 | 
						|
    pass
 | 
						|
else:
 | 
						|
    print "writelines accepted sequence of non-string objects"
 | 
						|
f.close()
 | 
						|
 | 
						|
os.unlink(TESTFN)
 |