def test_cleanup_ordering(self): """Cleanups are added in LIFO order. So cleanups added before run is called are run last, and the last cleanup added during the func is run first. """ call_log = [] def func(op, foo): call_log.append(('func called', foo)) op.add_cleanup(call_log.append, 'cleanup 2') op.add_cleanup(call_log.append, 'cleanup 1') return 'result' owc = OperationWithCleanups(func) owc.add_cleanup(call_log.append, 'cleanup 4') owc.add_cleanup(call_log.append, 'cleanup 3') result = owc.run('foo') self.assertEqual('result', result) self.assertEqual( [('func called', 'foo'), 'cleanup 1', 'cleanup 2', 'cleanup 3', 'cleanup 4'], call_log)
def test_cleanup_ordering(self): """Cleanups are added in LIFO order. So cleanups added before run is called are run last, and the last cleanup added during the func is run first. """ call_log = [] def func(op, foo): call_log.append(('func called', foo)) op.add_cleanup(call_log.append, 'cleanup 2') op.add_cleanup(call_log.append, 'cleanup 1') return 'result' owc = OperationWithCleanups(func) owc.add_cleanup(call_log.append, 'cleanup 4') owc.add_cleanup(call_log.append, 'cleanup 3') result = owc.run('foo') self.assertEqual('result', result) self.assertEqual([('func called', 'foo'), 'cleanup 1', 'cleanup 2', 'cleanup 3', 'cleanup 4'], call_log)
def commit(self, message=None, timestamp=None, timezone=None, committer=None, specific_files=None, rev_id=None, allow_pointless=True, strict=False, verbose=False, revprops=None, working_tree=None, local=False, reporter=None, config=None, message_callback=None, recursive='down', exclude=None, possible_master_transports=None, lossy=False): """Commit working copy as a new revision. :param message: the commit message (it or message_callback is required) :param message_callback: A callback: message = message_callback(cmt_obj) :param timestamp: if not None, seconds-since-epoch for a postdated/predated commit. :param specific_files: If not None, commit only those files. An empty list means 'commit no files'. :param rev_id: If set, use this as the new revision id. Useful for test or import commands that need to tightly control what revisions are assigned. If you duplicate a revision id that exists elsewhere it is your own fault. If null (default), a time/random revision id is generated. :param allow_pointless: If true (default), commit even if nothing has changed and no merges are recorded. :param strict: If true, don't allow a commit if the working tree contains unknown files. :param revprops: Properties for new revision :param local: Perform a local only commit. :param reporter: the reporter to use or None for the default :param verbose: if True and the reporter is not None, report everything :param recursive: If set to 'down', commit in any subtrees that have pending changes of any sort during this commit. :param exclude: None or a list of relative paths to exclude from the commit. Pending changes to excluded files will be ignored by the commit. :param lossy: When committing to a foreign VCS, ignore any data that can not be natively represented. """ operation = OperationWithCleanups(self._commit) self.revprops = revprops or {} # XXX: Can be set on __init__ or passed in - this is a bit ugly. self.config_stack = config or self.config_stack return operation.run( message=message, timestamp=timestamp, timezone=timezone, committer=committer, specific_files=specific_files, rev_id=rev_id, allow_pointless=allow_pointless, strict=strict, verbose=verbose, working_tree=working_tree, local=local, reporter=reporter, message_callback=message_callback, recursive=recursive, exclude=exclude, possible_master_transports=possible_master_transports, lossy=lossy)