def test_suppress_oserror(self): # # Verify the `suppress_oserror()` function. # # Empty list and empty statement is a no-op. with ctx.suppress_oserror(): pass # Single errno matches raised errno. with ctx.suppress_oserror(errno.EPERM): raise OSError(errno.EPERM, "Operation not permitted") # Many errnos match raised errno regardless of their order. with ctx.suppress_oserror(errno.EPERM, errno.ENOENT, errno.ESRCH): raise OSError(errno.EPERM, "Operation not permitted") with ctx.suppress_oserror(errno.ENOENT, errno.EPERM, errno.ESRCH): raise OSError(errno.EPERM, "Operation not permitted") with ctx.suppress_oserror(errno.ENOENT, errno.ESRCH, errno.EPERM): raise OSError(errno.EPERM, "Operation not permitted") # Empty list re-raises exceptions. with self.assertRaises(OSError): with ctx.suppress_oserror(): raise OSError(errno.EPERM, "Operation not permitted") # Non-matching lists re-raise exceptions. with self.assertRaises(OSError): with ctx.suppress_oserror(errno.ENOENT): raise OSError(errno.EPERM, "Operation not permitted") with ctx.suppress_oserror(errno.ENOENT, errno.ESRCH): raise OSError(errno.EPERM, "Operation not permitted")
def store_tree(self, destination: str): """Store the tree at destination and reset itself Moves the tree atomically by using rename(2). If the target already exist, does nothing. Afterwards it resets itself and can be used as if it was new. """ self._check_writable() self._check_readers() self._check_writer() self.init() with ctx.suppress_oserror(errno.ENOTEMPTY, errno.EEXIST): os.rename(self._tree, destination) self.reset()