def _delete_dir(dir_path, dir_type): try: EdgeUtils.delete_dir(dir_path) except OSError as ex: msg = 'Error deleting {0} directory {1}'.format(dir_type, dir_path) log.error(msg) raise edgectl.errors.EdgeFileAccessError(msg, dir_path)
def test_delete_dir_raises_oserror_when_rmtree_fails( self, mock_exists, mock_rmtree): """ Tests invocation of API delete_dir raises OSError when rmtree raises OSError""" # arrange dir_path = 'blah' mock_exists.return_value = True mock_rmtree.side_effect = OSError('rmtree error') # act, assert with self.assertRaises(OSError): EdgeUtils.delete_dir(dir_path)
def test_delete_dir_when_dir_does_not_exist(self, mock_exists, mock_rmtree): """ Test a valid invocation of API delete_dir when dir to be deleted does not exist""" # arrange dir_path = 'blah' mock_exists.return_value = False # act EdgeUtils.delete_dir(dir_path) # assert mock_exists.assert_called_with(dir_path) mock_rmtree.assert_not_called()
def test_delete_dir_when_dir_exists(self, mock_exists, mock_rmtree): """ Test a valid invocation of API delete_dir when dir to be deleted exists""" # arrange dir_path = 'blah' mock_exists.return_value = True # act EdgeUtils.delete_dir(dir_path) # assert mock_exists.assert_called_with(dir_path) mock_rmtree.assert_called_with( dir_path, onerror=EdgeUtils._remove_readonly_callback)