#NEWLINE# def populate( datatype = 'string' , size = 10 , start = None , end = None , converter = None , choice_from = None , **kwargs ) : #NEWLINE# #INDENT# "Utility function for populating lists with random data.\nUseful for populating database with data for fuzzy testing.\nSupported data-types\n\n* *string*\n    For example::\n\n        populate('string',100, min_len=3, max_len=10)\n\n    create a 100 elements list with random strings\n    with random length between 3 and 10\n\n* *date*\n    For example::\n\n        from datetime import date\n        populate('date',200, start = date(1997,1,1), end = date.today())\n\n    create a 200 elements list with random datetime.date objects\n    between *start* and *end*\n\n* *integer*\n    For example::\n\n        populate('integer',200, start = 0, end = 1000)\n\n    create a 200 elements list with random int between *start* and *end*\n\n* *float*\n    For example::\n\n        populate('float', 200, start = 0, end = 10)\n\n    create a 200 elements list with random floats between *start* and *end*\n\n* *choice* (elements of an iterable)\n    For example::\n\n        populate('choice', 200, choice_from = ['pippo','pluto','blob'])\n\n    create a 200 elements list with random elements from *choice_from*.\n    " #NEWLINE# data = [ ] #NEWLINE# converter = ( converter or def_converter ) #NEWLINE# if ( datatype == 'date' ) : #NEWLINE# #INDENT# date_end = ( end or date . today ( ) ) #NEWLINE# date_start = ( start or date ( 1990 , 1 , 1 ) ) #NEWLINE# delta = ( date_end - date_start ) #NEWLINE# for s in range ( size ) : #NEWLINE# #INDENT# data . append ( converter ( random_date ( date_start , delta . days ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( datatype == 'integer' ) : #NEWLINE# #INDENT# start = ( start or 0 ) #NEWLINE# end = ( end or 1000000 ) #NEWLINE# for s in range ( size ) : #NEWLINE# #INDENT# data . append ( converter ( randint ( start , end ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( datatype == 'float' ) : #NEWLINE# #INDENT# start = ( start or 0 ) #NEWLINE# end = ( end or 10 ) #NEWLINE# for s in range ( size ) : #NEWLINE# #INDENT# data . append ( converter ( uniform ( start , end ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( datatype == 'choice' ) and choice_from ) : #NEWLINE# #INDENT# for s in range ( size ) : #NEWLINE# #INDENT# data . append ( choice ( list ( choice_from ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for s in range ( size ) : #NEWLINE# #INDENT# data . append ( converter ( random_string ( ** kwargs ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return data