#NEWLINE# def test_segmented_file( self ) : #NEWLINE# #INDENT# with tempfile . NamedTemporaryFile ( mode = 'wb' ) as f : #NEWLINE# #INDENT# segment_length = 1024 #NEWLINE# segments = ( 'a' , 'b' , 'c' , 'd' ) #NEWLINE# for c in segments : #NEWLINE# #INDENT# f . write ( ( c * segment_length ) . encode ( ) ) #NEWLINE# #UNINDENT# f . flush ( ) #NEWLINE# for ( i , c ) in enumerate ( segments ) : #NEWLINE# #INDENT# contents = open ( f . name , 'rb' ) #NEWLINE# contents . seek ( ( i * segment_length ) ) #NEWLINE# data = u . LengthWrapper ( contents , segment_length , True ) #NEWLINE# read_data = b'' . join ( iter ( data . read , '' ) ) #NEWLINE# s = ( c * segment_length ) . encode ( ) #NEWLINE# self . assertEqual ( segment_length , len ( data ) ) #NEWLINE# self . assertEqual ( segment_length , len ( read_data ) ) #NEWLINE# self . assertEqual ( s , read_data ) #NEWLINE# self . assertEqual ( md5 ( s ) . hexdigest ( ) , data . get_md5sum ( ) ) #NEWLINE# data . reset ( ) #NEWLINE# self . assertEqual ( md5 ( ) . hexdigest ( ) , data . get_md5sum ( ) ) #NEWLINE# read_data = b'' . join ( iter ( data . read , '' ) ) #NEWLINE# self . assertEqual ( segment_length , len ( data ) ) #NEWLINE# self . assertEqual ( segment_length , len ( read_data ) ) #NEWLINE# self . assertEqual ( s , read_data ) #NEWLINE# self . assertEqual ( md5 ( s ) . hexdigest ( ) , data . get_md5sum ( ) )