def _test_simple(self, target_prefix, trans_file): targets = [] log = TransactionLog(trans_file) try: for source in self.files: target = op.join(target_prefix, op.basename(source)) targets.append(target) log.copy(source, target, None) finally: log.close() for target in targets: self.assertTrue(op.exists(target))
def test_simple_interrupted(self): """Test a simple, interrupted run.""" class _InterruptException(Exception): pass target_prefix = op.join(self.base_dir, "foo") trans_file = op.join(self.base_dir, "trans.log") targets = [] log = TransactionLog(trans_file) try: try: for i, source in enumerate(self.files): if i > len(self.files) / 3: raise _InterruptException() target = op.join(target_prefix, op.basename(source)) targets.append(target) log.copy(source, target, None) except _InterruptException: log.rollback() for target in targets: self.assertFalse(op.exists(target)) return self.fail("Expected failure at this point !") finally: log.close()