/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.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:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
831
831
 
832
832
    def setUp(self):
833
833
        super(TestUpdateEntry, self).setUp()
834
 
        self.overrideAttr(dirstate, 'update_entry', self.update_entry)
 
834
        self.addAttrCleanup(dirstate, 'update_entry')
 
835
        dirstate.update_entry = self.update_entry
835
836
 
836
837
    def get_state_with_a(self):
837
838
        """Create a DirState tracking a single object named 'a'"""
1274
1275
 
1275
1276
    def setUp(self):
1276
1277
        super(TestProcessEntry, self).setUp()
1277
 
        self.overrideAttr(dirstate, '_process_entry', self._process_entry)
 
1278
        self.addAttrCleanup(dirstate, '_process_entry')
 
1279
        dirstate._process_entry = self._process_entry
1278
1280
 
1279
1281
    def assertChangedFileIds(self, expected, tree):
1280
1282
        tree.lock_read()
1289
1291
        # This is a direct test of bug #495023, it relies on osutils.is_inside
1290
1292
        # getting called in an inner function. Which makes it a bit brittle,
1291
1293
        # but at least it does reproduce the bug.
 
1294
        def is_inside_raises(*args, **kwargs):
 
1295
            raise RuntimeError('stop this')
1292
1296
        tree = self.make_branch_and_tree('tree')
1293
1297
        self.build_tree(['tree/file', 'tree/dir/', 'tree/dir/sub',
1294
1298
                         'tree/dir2/', 'tree/dir2/sub2'])
1297
1301
        tree.lock_read()
1298
1302
        self.addCleanup(tree.unlock)
1299
1303
        basis_tree = tree.basis_tree()
1300
 
        def is_inside_raises(*args, **kwargs):
1301
 
            raise RuntimeError('stop this')
1302
 
        self.overrideAttr(osutils, 'is_inside', is_inside_raises)
 
1304
        self.addAttrCleanup(osutils, 'is_inside')
 
1305
        osutils.is_inside = is_inside_raises
1303
1306
        self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
1304
1307
 
1305
1308
    def test_simple_changes(self):