#NEWLINE# def make_bogus_binary_file( n = ( 1 * MB ) , filepath = None , printprogress = False ) : #NEWLINE# #INDENT# "\n    Makes a bogus binary data file for testing.\n    It is the caller's responsibility to clean up the file when finished.\n\n    :param n:       How many bytes to write\n\n    :returns: The name of the file\n    " #NEWLINE# with ( open ( filepath , 'wb' ) if filepath else tempfile . NamedTemporaryFile ( mode = 'wb' , suffix = '.dat' , delete = False ) ) as f : #NEWLINE# #INDENT# if ( not filepath ) : #NEWLINE# #INDENT# filepath = f . name #NEWLINE# #UNINDENT# progress = 0 #NEWLINE# remaining = n #NEWLINE# while ( remaining > 0 ) : #NEWLINE# #INDENT# buff_size = int ( min ( remaining , ( 1 * MB ) ) ) #NEWLINE# f . write ( os . urandom ( buff_size ) ) #NEWLINE# remaining -= buff_size #NEWLINE# if printprogress : #NEWLINE# #INDENT# progress += buff_size #NEWLINE# printTransferProgress ( progress , n , 'Generated ' , filepath ) #NEWLINE# #UNINDENT# #UNINDENT# return filepath