~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-01 09:01:06 UTC
  • mto: This revision was merged to the branch mainline in revision 5951.
  • Revision ID: v.ladeuil+lp@free.fr-20110601090106-j6576yr7gv1xs1fs
Forget weakref for branch <-> config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        test.backing_branch = test.make_branch(relpath)
105
105
 
106
106
 
107
 
def keep_branch_alive(test, b):
108
 
    """Keep a branch alive for the duration of a test.
109
 
 
110
 
    :param tests: the test that should hold the branch alive.
111
 
 
112
 
    :param b: the branch that should be kept alive.
113
 
 
114
 
    Several tests need to keep a reference to a branch object as they are
115
 
    testing a Store which uses a weak reference. This is achieved by embedding
116
 
    a reference to the branch object in a lambda passed to a cleanup. When the
117
 
    test finish the cleanup method is deleted and so does the reference to the
118
 
    branch.
119
 
    """
120
 
    test.addCleanup(lambda : b)
121
 
 
122
 
 
123
107
def build_branch_store(test):
124
108
    build_backing_branch(test, 'branch')
125
109
    b = branch.Branch.open('branch')
126
 
    keep_branch_alive(test, b)
127
110
    return config.BranchStore(b)
128
111
config.test_store_builder_registry.register('branch', build_branch_store)
129
112
 
134
117
    (transport_class, server_class) = remote.get_test_permutations()[0]
135
118
    build_backing_branch(test, 'branch', transport_class, server_class)
136
119
    b = branch.Branch.open(test.get_url('branch'))
137
 
    keep_branch_alive(test, b)
138
120
    return config.BranchStore(b)
139
121
config.test_store_builder_registry.register('remote_branch',
140
122
                                            build_remote_branch_store)
149
131
def build_branch_stack(test):
150
132
    build_backing_branch(test, 'branch')
151
133
    b = branch.Branch.open('branch')
152
 
    keep_branch_alive(test, b)
153
134
    return config.BranchStack(b)
154
135
config.test_stack_builder_registry.register('branch', build_branch_stack)
155
136
 
160
141
    (transport_class, server_class) = remote.get_test_permutations()[0]
161
142
    build_backing_branch(test, 'branch', transport_class, server_class)
162
143
    b = branch.Branch.open(test.get_url('branch'))
163
 
    keep_branch_alive(test, b)
164
144
    return config.BranchStack(b)
165
145
config.test_stack_builder_registry.register('remote_branch',
166
146
                                            build_remote_branch_stack)
2240
2220
        self.assertPathExists('dir/subdir')
2241
2221
 
2242
2222
 
2243
 
class TestBranchStore(TestStore):
2244
 
 
2245
 
    def test_dead_branch(self):
2246
 
        build_backing_branch(self, 'branch')
2247
 
        b = branch.Branch.open('branch')
2248
 
        store = config.BranchStore(b)
2249
 
        del b
2250
 
        # The only reliable way to trigger the error is to explicitly call the
2251
 
        # garbage collector.
2252
 
        import gc
2253
 
        gc.collect()
2254
 
        store.get_mutable_section(None).set('foo', 'bar')
2255
 
        self.assertRaises(AssertionError, store.save)
2256
 
 
2257
 
 
2258
2223
class TestConcurrentStoreUpdates(TestStore):
2259
2224
    """Test that Stores properly handle conccurent updates.
2260
2225