#NEWLINE# @ mock . patch . object ( lockutils , 'external_lock' ) #NEWLINE# @ mock . patch . object ( libvirt_utils , 'update_mtime' ) #NEWLINE# @ mock . patch ( 'os.path.exists' , return_value = True ) #NEWLINE# @ mock . patch ( 'os.path.getmtime' ) #NEWLINE# @ mock . patch ( 'os.remove' ) #NEWLINE# def test_age_and_verify_swap_images( self , mock_remove , mock_getmtime , mock_exist , mock_mtime , mock_lock ) : #NEWLINE# #INDENT# image_cache_manager = imagecache . ImageCacheManager ( ) #NEWLINE# expected_remove = set ( ) #NEWLINE# expected_exist = set ( [ 'swap_128' , 'swap_256' ] ) #NEWLINE# image_cache_manager . back_swap_images . add ( 'swap_128' ) #NEWLINE# image_cache_manager . back_swap_images . add ( 'swap_256' ) #NEWLINE# image_cache_manager . used_swap_images . add ( 'swap_128' ) #NEWLINE# def getmtime( path ) : #NEWLINE# #INDENT# return ( time . time ( ) - 1000000 ) #NEWLINE# #UNINDENT# mock_getmtime . side_effect = getmtime #NEWLINE# def removefile( path ) : #NEWLINE# #INDENT# if ( not path . startswith ( '/tmp_age_test' ) ) : #NEWLINE# #INDENT# return os . remove ( path ) #NEWLINE# #UNINDENT# fn = os . path . split ( path ) [ ( - 1 ) ] #NEWLINE# expected_remove . add ( fn ) #NEWLINE# expected_exist . remove ( fn ) #NEWLINE# #UNINDENT# mock_remove . side_effect = removefile #NEWLINE# image_cache_manager . _age_and_verify_swap_images ( None , '/tmp_age_test' ) #NEWLINE# self . assertEqual ( 1 , len ( expected_exist ) ) #NEWLINE# self . assertEqual ( 1 , len ( expected_remove ) ) #NEWLINE# self . assertIn ( 'swap_128' , expected_exist ) #NEWLINE# self . assertIn ( 'swap_256' , expected_remove )