~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_commit.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
505
505
 
506
506
class TestCommitProgress(TestCaseWithWorkingTree):
507
507
 
508
 
    def restoreDefaults(self):
509
 
        ui.ui_factory = self.old_ui_factory
 
508
    def setUp(self):
 
509
        super(TestCommitProgress, self).setUp()
 
510
        self.addAttrCleanup(ui, 'ui_factory')
 
511
        ui.ui_factory = CapturingUIFactory()
510
512
 
511
513
    def test_commit_progress_steps(self):
512
514
        # during commit we one progress update for every entry in the
525
527
        f.close()
526
528
        # set a progress bar that captures the calls so we can see what is
527
529
        # emitted
528
 
        self.old_ui_factory = ui.ui_factory
529
 
        self.addCleanup(self.restoreDefaults)
530
530
        factory = CapturingUIFactory()
531
531
        ui.ui_factory = factory
532
532
        # TODO RBC 20060421 it would be nice to merge the reporter output
548
548
        tree = self.make_branch_and_tree('.')
549
549
        # set a progress bar that captures the calls so we can see what is
550
550
        # emitted
551
 
        self.old_ui_factory = ui.ui_factory
552
 
        self.addCleanup(self.restoreDefaults)
553
551
        factory = CapturingUIFactory()
554
552
        ui.ui_factory = factory
555
553
        def a_hook(_, _2, _3, _4, _5, _6):
573
571
        tree = self.make_branch_and_tree('.')
574
572
        # set a progress bar that captures the calls so we can see what is
575
573
        # emitted
576
 
        self.old_ui_factory = ui.ui_factory
577
 
        self.addCleanup(self.restoreDefaults)
578
574
        factory = CapturingUIFactory()
579
575
        ui.ui_factory = factory
580
576
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
622
618
            open(tree.abspath("newfile"), 'w').write("data")
623
619
            params.mutable_tree.add(["newfile"])
624
620
        def restoreDefaults():
 
621
            # We can't use addAttrCleanup here since we want to restore only
 
622
            # part of the dict -- vila 100123
625
623
            mutabletree.MutableTree.hooks['post_commit'] = []
626
624
        self.addCleanup(restoreDefaults)
627
625
        tree = self.make_branch_and_tree('.')