'File storage should be robust against file removal race conditions.'

def test_remove_race_handling(self):

    real_remove = os.remove
    def fake_remove(path):
        if (path == os.path.join(self.temp_dir, u'normal.file')):
            real_remove(path)
        elif (path == os.path.join(self.temp_dir, u'raced.file')):
            real_remove(path)
            raise OSError(errno.ENOENT, u'simulated    ENOENT')
        elif (path == os.path.join(self.temp_dir, u'error.file')):
            raise OSError(errno.EACCES, u'simulated    EACCES')
        else:
            self.fail((u'unexpected    argument    %r' % path))
    try:
        os.remove = fake_remove
        self.storage.save(u'normal.file', ContentFile(u'delete    normally'))
        self.storage.delete(u'normal.file')
        self.assertFalse(self.storage.exists(u'normal.file'))
        self.storage.save(u'raced.file', ContentFile(u'delete    with    race'))
        self.storage.delete(u'raced.file')
        self.assertFalse(self.storage.exists(u'normal.file'))
        self.storage.save(u'error.file', ContentFile(u'delete    with    error'))
        self.assertRaises(OSError, self.storage.delete, u'error.file')
    finally:
        os.remove = real_remove
