~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.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:
59
59
 
60
60
    def setUp(self):
61
61
        TestCaseWithTransport.setUp(self)
62
 
        self._original_header = btree_index._RESERVED_HEADER_BYTES
63
 
        def restore():
64
 
            btree_index._RESERVED_HEADER_BYTES = self._original_header
65
 
        self.addCleanup(restore)
 
62
        self.addAttrCleanup(btree_index, '_RESERVED_HEADER_BYTES')
66
63
        btree_index._RESERVED_HEADER_BYTES = 100
67
64
 
68
65
    def make_nodes(self, count, key_elements, reference_lists):
103
100
 
104
101
    def shrink_page_size(self):
105
102
        """Shrink the default page size so that less fits in a page."""
106
 
        old_page_size = btree_index._PAGE_SIZE
107
 
        def cleanup():
108
 
            btree_index._PAGE_SIZE = old_page_size
109
 
        self.addCleanup(cleanup)
 
103
        self.addAttrCleanup(btree_index, '_PAGE_SIZE')
110
104
        btree_index._PAGE_SIZE = 2048
111
105
 
112
106
 
1157
1151
 
1158
1152
class TestBTreeNodes(BTreeTestCase):
1159
1153
 
1160
 
    def restore_parser(self):
1161
 
        btree_index._btree_serializer = self.saved_parser
1162
 
 
1163
1154
    def setUp(self):
1164
1155
        BTreeTestCase.setUp(self)
1165
 
        self.saved_parser = btree_index._btree_serializer
1166
 
        self.addCleanup(self.restore_parser)
 
1156
        self.addAttrCleanup(btree_index, '_btree_serializer')
1167
1157
        btree_index._btree_serializer = self.parse_btree
1168
1158
 
1169
1159
    def test_LeafNode_1_0(self):