<s> import unittest <EOL> from robotide . controller . project import Backup <EOL> class BackupTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> file_controller = lambda : None <EOL> file_controller . filename = '<STR_LIT>' <EOL> file_controller . refresh_stat = lambda : None <EOL> self . _backupper = _MyBackup ( file_controller ) <EOL> def test_backup_is_restored_when_save_raises_exception ( self ) : <EOL> try : <EOL> with self . _backupper : <EOL> raise _SaveFailed ( '<STR_LIT>' ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except _SaveFailed : <EOL> self . assertTrue ( self . _backupper . restored ) <EOL> def test_backup_is_not_restored_when_save_passes ( self ) : <EOL> with self . _backupper : <EOL> self . assertNotEqual ( None , self . _backupper . _backup ) <EOL> self . assertFalse ( self . _backupper . restored ) <EOL> self . assertEqual ( None , self . _backupper . _backup ) <EOL> def test_save_can_be_done_if_backup_move_fails ( self ) : <EOL> def move_fails ( * args ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> self . _backupper . _move = move_fails <EOL> save_done = False <EOL> with self . _backupper : <EOL> save_done = True <EOL> self . assertTrue ( save_done ) <EOL> class _SaveFailed ( Exception ) : <EOL> pass <EOL> class _MyBackup ( Backup ) : <EOL> def __init__ ( self , file_controller ) : <EOL> Backup . __init__ ( self , file_controller ) <EOL> self . _backup = object ( ) <EOL> self . restored = False <EOL> def _move ( self , from_path , to_path ) : <EOL> self . restored = ( self . _backup == from_path ) <EOL> def _remove_backup ( self ) : <EOL> self . _backup = None <EOL> def _remove_backup_dir ( self ) : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
