<s> import filecmp , math , os , tempfile <EOL> from nose . tools import assert_raises <EOL> from synapseclient . multipart_upload import find_parts_to_upload , count_completed_parts , calculate_part_size , get_file_chunk <EOL> from synapseclient . utils import MB , GB , make_bogus_binary_file <EOL> def test_find_parts_to_upload ( ) : <EOL> assert find_parts_to_upload ( "<STR_LIT>" ) == [ ] <EOL> assert find_parts_to_upload ( "<STR_LIT>" ) == [ ] <EOL> assert find_parts_to_upload ( "<STR_LIT>" ) == [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT> ] <EOL> assert find_parts_to_upload ( "<STR_LIT>" ) == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> def test_count_completed_parts ( ) : <EOL> assert count_completed_parts ( "<STR_LIT>" ) == <NUM_LIT:0> <EOL> assert count_completed_parts ( "<STR_LIT>" ) == <NUM_LIT:12> <EOL> assert count_completed_parts ( "<STR_LIT>" ) == <NUM_LIT:0> <EOL> assert count_completed_parts ( "<STR_LIT>" ) == <NUM_LIT:5> <EOL> def test_calculate_part_size ( ) : <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT:3> * MB , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT> ) == <NUM_LIT:5> * MB <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT:6> * MB , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT:2> ) == <NUM_LIT:5> * MB <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT:11> * MB , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT:2> ) == <NUM_LIT:11> * MB / <NUM_LIT> <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT:100> * MB , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT:2> ) >= ( <NUM_LIT:100> * MB ) / <NUM_LIT> <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT:11> * MB + <NUM_LIT> , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT:2> ) >= ( <NUM_LIT:11> * MB + <NUM_LIT> ) / <NUM_LIT> <EOL> assert <NUM_LIT:5> * MB <= calculate_part_size ( fileSize = <NUM_LIT> * GB + <NUM_LIT> , partSize = None , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT> ) >= ( <NUM_LIT> * GB + <NUM_LIT> ) / <NUM_LIT> <EOL> assert calculate_part_size ( <NUM_LIT:6> * MB , partSize = <NUM_LIT:10> * MB , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT> ) == <NUM_LIT:10> * MB <EOL> assert_raises ( ValueError , calculate_part_size , fileSize = <NUM_LIT:100> * MB , partSize = <NUM_LIT:1> * MB , min_part_size = <NUM_LIT:5> * MB , max_parts = <NUM_LIT> ) <EOL> assert_raises ( ValueError , calculate_part_size , fileSize = <NUM_LIT> * MB , partSize = <NUM_LIT:1> * MB , min_part_size = <NUM_LIT:1> * MB , max_parts = <NUM_LIT:20> ) <EOL> def test_chunks ( ) : <EOL> try : <EOL> file_size = <NUM_LIT:1> * MB <EOL> filepath = make_bogus_binary_file ( n = file_size ) <EOL> chunksize = <NUM_LIT:64> * <NUM_LIT> <EOL> nchunks = int ( math . ceil ( float ( file_size ) / chunksize ) ) <EOL> with tempfile . NamedTemporaryFile ( mode = '<STR_LIT:wb>' , delete = False ) as out : <EOL> for i in range ( <NUM_LIT:1> , nchunks + <NUM_LIT:1> ) : <EOL> out . write ( get_file_chunk ( filepath , i , chunksize ) ) <EOL> assert filecmp . cmp ( filepath , out . name ) <EOL> finally : <EOL> if '<STR_LIT>' in locals ( ) and filepath : <EOL> os . remove ( filepath ) <EOL> if '<STR_LIT>' in locals ( ) and out : <EOL> os . remove ( out . name ) </s>
