<s> import datetime <EOL> import unittest <EOL> from mock import Mock <EOL> from awscli . customizations . s3 . comparator import Comparator <EOL> from awscli . customizations . s3 . filegenerator import FileStat <EOL> class ComparatorTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . sync_strategy = Mock ( ) <EOL> self . not_at_src_sync_strategy = Mock ( ) <EOL> self . not_at_dest_sync_strategy = Mock ( ) <EOL> self . comparator = Comparator ( self . sync_strategy , <EOL> self . not_at_dest_sync_strategy , <EOL> self . not_at_src_sync_strategy ) <EOL> def test_compare_key_equal_should_not_sync ( self ) : <EOL> """<STR_LIT>""" <EOL> self . sync_strategy . determine_should_sync . return_value = False <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> time = datetime . datetime . now ( ) <EOL> src_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> dest_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> src_files . append ( src_file ) <EOL> dest_files . append ( dest_file ) <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> self . sync_strategy . determine_should_sync . return_value = True <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> ref_list . append ( src_file ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> def test_compare_key_less ( self ) : <EOL> """<STR_LIT>""" <EOL> self . not_at_src_sync_strategy . determine_should_sync . return_value = False <EOL> self . not_at_dest_sync_strategy . determine_should_sync . return_value = True <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> time = datetime . datetime . now ( ) <EOL> src_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> dest_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> src_files . append ( src_file ) <EOL> dest_files . append ( dest_file ) <EOL> ref_list . append ( src_file ) <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> self . not_at_dest_sync_strategy . determine_should_sync . return_value = False <EOL> result_list = [ ] <EOL> ref_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> def test_compare_key_greater ( self ) : <EOL> """<STR_LIT>""" <EOL> self . not_at_dest_sync_strategy . determine_should_sync . return_value = False <EOL> self . not_at_src_sync_strategy . determine_should_sync . return_value = True <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> time = datetime . datetime . now ( ) <EOL> src_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> dest_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> src_files . append ( src_file ) <EOL> dest_files . append ( dest_file ) <EOL> ref_list . append ( dest_file ) <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> self . not_at_src_sync_strategy . determine_should_sync . return_value = False <EOL> result_list = [ ] <EOL> ref_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> def test_empty_src ( self ) : <EOL> """<STR_LIT>""" <EOL> self . not_at_src_sync_strategy . determine_should_sync . return_value = True <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> time = datetime . datetime . now ( ) <EOL> dest_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> dest_files . append ( dest_file ) <EOL> ref_list . append ( dest_file ) <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> self . not_at_src_sync_strategy . determine_should_sync . return_value = False <EOL> result_list = [ ] <EOL> ref_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> def test_empty_dest ( self ) : <EOL> """<STR_LIT>""" <EOL> self . not_at_dest_sync_strategy . determine_should_sync . return_value = True <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> time = datetime . datetime . now ( ) <EOL> src_file = FileStat ( src = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> compare_key = '<STR_LIT>' , size = <NUM_LIT:10> , <EOL> last_update = time , src_type = '<STR_LIT>' , <EOL> dest_type = '<STR_LIT>' , operation_name = '<STR_LIT>' ) <EOL> src_files . append ( src_file ) <EOL> ref_list . append ( src_file ) <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> self . not_at_dest_sync_strategy . determine_should_sync . return_value = False <EOL> result_list = [ ] <EOL> ref_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> def test_empty_src_dest ( self ) : <EOL> """<STR_LIT>""" <EOL> src_files = [ ] <EOL> dest_files = [ ] <EOL> ref_list = [ ] <EOL> result_list = [ ] <EOL> files = self . comparator . call ( iter ( src_files ) , iter ( dest_files ) ) <EOL> for filename in files : <EOL> result_list . append ( filename ) <EOL> self . assertEqual ( result_list , ref_list ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
